Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
BatchProviderTest.php
Go to the documentation of this file.
1 <?php
7 
8 use \Magento\Framework\DB\Adapter\AdapterInterface;
9 use \Magento\Framework\DB\Select;
10 use \Magento\Framework\Indexer\BatchProvider;
11 
12 class BatchProviderTest extends \PHPUnit\Framework\TestCase
13 {
17  private $model;
18 
19  protected function setUp()
20  {
21  $this->model = new BatchProvider();
22  }
23 
31  public function testGetBatches($batchSize, $maxLinkFieldValue, $expectedResult)
32  {
33  $tableName = 'test_table';
34  $linkField = 'id';
35 
36  $selectMock = $this->createMock(Select::class);
37  $adapterMock = $this->createMock(AdapterInterface::class);
38 
39  $selectMock->expects($this->once())->method('from')->willReturnSelf();
40  $adapterMock->expects($this->once())->method('select')->willReturn($selectMock);
41  $adapterMock->expects($this->once())->method('fetchOne')->with($selectMock, [])->willReturn($maxLinkFieldValue);
42  $batches = $this->model->getBatches($adapterMock, $tableName, $linkField, $batchSize);
43  foreach ($batches as $index => $batch) {
44  $this->assertEquals($expectedResult[$index], $batch);
45  }
46  }
47 
51  public function getBatchesDataProvider()
52  {
53  return [
54  [200, 600, [['from' => 1, 'to' => 200], ['from' => 201, 'to' => 400], ['from' => 401, 'to' => 600]]],
55  [200, 555, [['from' => 1, 'to' => 200], ['from' => 201, 'to' => 400], ['from' => 401, 'to' => 555]]],
56  [200, 10, [['from' => 1, 'to' => 10]]],
57  [200, 0, []],
58  ];
59  }
60 
61  public function testGetBatchIds()
62  {
63  $selectMock = $this->createMock(Select::class);
64  $adapterMock = $this->createMock(AdapterInterface::class);
65 
66  $selectMock->expects($this->once())->method('where')->with('(entity_id BETWEEN 10 AND 100)')->willReturnSelf();
67  $adapterMock->expects($this->atLeastOnce())->method('quote')->willReturnArgument(0);
68  $adapterMock->expects($this->once())->method('fetchCol')->with($selectMock, [])->willReturn([1, 2, 3]);
69  $this->assertEquals(
70  [1, 2, 3],
71  $this->model->getBatchIds($adapterMock, $selectMock, ['from' => 10, 'to' => 100])
72  );
73  }
74 }
$tableName
Definition: trigger.php:13
testGetBatches($batchSize, $maxLinkFieldValue, $expectedResult)
$index
Definition: list.phtml:44