Skip to content

Commit

Permalink
Fix magento#14958 - add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Bartlomiejsz committed Apr 12, 2019
1 parent 8529467 commit 4c4ae53
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,34 @@ public function testLoadBy()
$this->assertEquals($this->meta, $this->resource->loadByEntityTypeAndStore($entityType, $storeId));
}

public function testGetIdsByStore()
{
$metaTableName = 'sequence_meta';
$metaIdFieldName = 'meta_id';
$storeId = 1;
$metaIds = [1, 2];
$this->resourceMock->expects($this->any())
->method('getConnection')
->willReturn($this->connectionMock);
$this->resourceMock->expects($this->once())
->method('getTableName')
->willReturn($metaTableName);
$this->connectionMock->expects($this->any())->method('select')->willReturn($this->select);
$this->select->expects($this->at(0))
->method('from')
->with($metaTableName, [$metaIdFieldName])
->willReturn($this->select);
$this->select->expects($this->at(1))
->method('where')
->with('store_id = :store_id')
->willReturn($this->select);
$this->connectionMock->expects($this->once())
->method('fetchCol')
->with($this->select, ['store_id' => $storeId])
->willReturn($metaIds);
$this->assertEquals($metaIds, $this->resource->getIdsByStore($storeId));
}

/**
* @param $metaData
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,32 @@ public function testLoadActiveProfile()
$this->profile->expects($this->at(1))->method('setData')->with($profileData);
$this->assertEquals($this->profile, $this->resource->loadActiveProfile($metaId));
}

public function testGetProfileIdsByMetadataIds()
{
$profileTableName = 'sequence_profile';
$profileIdFieldName = 'profile_id';
$metadataIds = [1, 2];
$profileIds = [10, 11];
$this->resourceMock->expects($this->any())
->method('getConnection')
->willReturn($this->connectionMock);
$this->resourceMock->expects($this->once())
->method('getTableName')
->willReturn($profileTableName);
$this->connectionMock->expects($this->any())->method('select')->willReturn($this->select);
$this->select->expects($this->at(0))
->method('from')
->with($profileTableName, [$profileIdFieldName])
->willReturn($this->select);
$this->select->expects($this->at(1))
->method('where')
->with('meta_id IN (?)', $metadataIds)
->willReturn($this->select);
$this->connectionMock->expects($this->once())
->method('fetchCol')
->with($this->select)
->willReturn($profileIds);
$this->assertEquals($profileIds, $this->resource->getProfileIdsByMetadataIds($metadataIds));
}
}

0 comments on commit 4c4ae53

Please sign in to comment.