Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
StoreWebsiteRelationTest.php
Go to the documentation of this file.
1 <?php
8 
13 
14 class StoreWebsiteRelationTest extends \PHPUnit\Framework\TestCase
15 {
17  private $model;
18 
20  private $resourceConnection;
21 
23  private $connection;
24 
26  private $select;
27 
28  public function setUp()
29  {
30  $this->select = $this->getMockBuilder(Select::class)
31  ->disableOriginalConstructor()
32  ->getMock();
33  $this->resourceConnection = $this->getMockBuilder(ResourceConnection::class)
34  ->disableOriginalConstructor()
35  ->getMock();
36  $this->connection = $this->createMock(AdapterInterface::class);
37 
38  $this->model = new StoreWebsiteRelation($this->resourceConnection);
39  }
40 
41  public function testGetStoreByWebsiteId()
42  {
43  $data = ['ololo'];
44  $websiteId = 1;
45  $storeTable = 'store';
46  $this->resourceConnection->expects($this->once())
47  ->method('getConnection')
48  ->willReturn($this->connection);
49  $this->resourceConnection->expects($this->once())
50  ->method('getTableName')
51  ->willReturn($storeTable);
52  $this->connection->expects($this->once())
53  ->method('select')
54  ->willReturn($this->select);
55 
56  $this->select->expects($this->once())
57  ->method('from')
58  ->with($storeTable, ['store_id'])
59  ->willReturn($this->select);
60  $this->select->expects($this->once())
61  ->method('where')
62  ->with('website_id = ?', $websiteId)
63  ->willReturn($this->select);
64  $this->connection->expects($this->once())
65  ->method('fetchCol')
66  ->willReturn($data);
67 
68  $this->assertEquals($data, $this->model->getStoreByWebsiteId($websiteId));
69  }
70 }