BatchTest.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Indexer\Test\Unit;
  7. class BatchTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /**
  10. * @var \Magento\Framework\Indexer\SaveHandler\Batch
  11. */
  12. private $object;
  13. protected function setUp()
  14. {
  15. $this->object = new \Magento\Framework\Indexer\SaveHandler\Batch();
  16. }
  17. /**
  18. * @param array $itemsData
  19. * @param int $size
  20. * @param array $expected
  21. *
  22. * @dataProvider getItemsDataProvider
  23. */
  24. public function testGetItems(array $itemsData, $size, array $expected)
  25. {
  26. $items = new \ArrayObject($itemsData);
  27. $data = $this->object->getItems($items, $size);
  28. $this->assertSame($expected, iterator_to_array($data));
  29. }
  30. /**
  31. * @return array
  32. */
  33. public function getItemsDataProvider()
  34. {
  35. return [
  36. 'empty' => [
  37. [],
  38. 2,
  39. [],
  40. ],
  41. 'even, numeric keys' => [
  42. [1, 2, 3, 4],
  43. 2,
  44. [
  45. [0 => 1, 1 => 2],
  46. [2 => 3, 3 => 4],
  47. ],
  48. ],
  49. 'odd, numeric keys' => [
  50. [1, 2, 3, 4, 5],
  51. 2,
  52. [
  53. [0 => 1, 1 => 2],
  54. [2 => 3, 3 => 4],
  55. [4 => 5],
  56. ],
  57. ],
  58. 'even, string keys' => [
  59. ['a' => 1, 'b' => 2, 'c' => 3, 'd' => 4],
  60. 2,
  61. [
  62. ['a' => 1, 'b' => 2],
  63. ['c' => 3, 'd' => 4],
  64. ],
  65. ],
  66. 'odd, string keys' => [
  67. ['a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5],
  68. 2,
  69. [
  70. ['a' => 1, 'b' => 2],
  71. ['c' => 3, 'd' => 4],
  72. ['e' => 5],
  73. ],
  74. ],
  75. ];
  76. }
  77. }