Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
PositionResolverTest.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
16 
17 class PositionResolverTest extends \PHPUnit\Framework\TestCase
18 {
22  private $context;
23 
27  private $resources;
28 
32  private $connection;
33 
37  private $select;
38 
42  private $model;
43 
47  private $positions = [
48  '3' => 100,
49  '2' => 101,
50  '1' => 102
51  ];
52 
56  private $flippedPositions = [
57  '100' => 3,
58  '101' => 2,
59  '102' => 1
60  ];
61 
65  private $categoryId = 1;
66 
67  protected function setUp()
68  {
69  $this->context = $this->getMockBuilder(Context::class)
70  ->disableOriginalConstructor()
71  ->getMock();
72 
73  $this->resources = $this->getMockBuilder(ResourceConnection::class)
74  ->disableOriginalConstructor()
75  ->getMock();
76 
77  $this->connection = $this->getMockBuilder(AdapterInterface::class)
78  ->disableOriginalConstructor()
79  ->getMockForAbstractClass();
80 
81  $this->select = $this->getMockBuilder(Select::class)
82  ->disableOriginalConstructor()
83  ->getMock();
84 
85  $this->model = (new ObjectManager($this))->getObject(
86  PositionResolver::class,
87  [
88  'context' => $this->context,
89  null,
90  '_resources' => $this->resources
91  ]
92  );
93  }
94 
95  public function testGetPositions()
96  {
97  $this->resources->expects($this->once())
98  ->method('getConnection')
99  ->willReturn($this->connection);
100 
101  $this->connection->expects($this->once())
102  ->method('select')
103  ->willReturn($this->select);
104  $this->select->expects($this->once())
105  ->method('from')
106  ->willReturnSelf();
107  $this->select->expects($this->once())
108  ->method('where')
109  ->willReturnSelf();
110  $this->select->expects($this->once())
111  ->method('order')
112  ->willReturnSelf();
113  $this->select->expects($this->once())
114  ->method('joinLeft')
115  ->willReturnSelf();
116  $this->connection->expects($this->once())
117  ->method('fetchCol')
118  ->willReturn($this->positions);
119 
120  $this->assertEquals($this->flippedPositions, $this->model->getPositions($this->categoryId));
121  }
122 }