Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
BatchRangeIteratorTest.php
Go to the documentation of this file.
1 <?php
8 
12 
13 class BatchRangeIteratorTest extends \PHPUnit\Framework\TestCase
14 {
18  private $model;
19 
23  private $selectMock;
24 
28  private $wrapperSelectMock;
29 
33  private $connectionMock;
34 
38  private $batchSize;
39 
43  private $correlationName;
44 
48  private $rangeField;
49 
53  private $rangeFieldAlias;
54 
58  private $currentBatch = 0;
59 
65  protected function setUp()
66  {
67  $this->batchSize = 10;
68  $this->currentBatch = 0;
69  $this->correlationName = 'correlationName';
70  $this->rangeField = 'rangeField';
71  $this->rangeFieldAlias = 'rangeFieldAlias';
72 
73  $this->selectMock = $this->createMock(Select::class);
74  $this->wrapperSelectMock = $this->createMock(Select::class);
75  $this->connectionMock = $this->createMock(AdapterInterface::class);
76  $this->connectionMock->expects($this->any())->method('select')->willReturn($this->wrapperSelectMock);
77  $this->selectMock->expects($this->once())->method('getConnection')->willReturn($this->connectionMock);
78  $this->connectionMock->expects($this->any())->method('quoteIdentifier')->willReturnArgument(0);
79 
80  $this->model = new BatchRangeIterator(
81  $this->selectMock,
82  $this->batchSize,
83  $this->correlationName,
84  $this->rangeField,
85  $this->rangeFieldAlias
86  );
87  }
88 
95  public function testCurrent()
96  {
97  $this->selectMock->expects($this->once())->method('limit')->with($this->batchSize, $this->currentBatch);
98  $this->selectMock->expects($this->once())->method('order')->with('correlationName.rangeField' . ' ASC');
99  $this->assertEquals($this->selectMock, $this->model->current());
100  $this->assertEquals(0, $this->model->key());
101  }
102 
106  public function testIterations()
107  {
108  $iterations = 0;
109 
110  $this->connectionMock->expects($this->once())
111  ->method('fetchRow')
112  ->willReturn(['cnt' => 105]);
113 
114  foreach ($this->model as $key) {
115  $this->assertEquals($this->selectMock, $key);
116  $iterations++;
117  }
118 
119  $this->assertEquals(11, $iterations);
120  }
121 }