FileChunksTest.php 839 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. declare(strict_types=1);
  3. namespace JsonMachineTest;
  4. use JsonMachine\FileChunks;
  5. /**
  6. * @covers \JsonMachine\FileChunks
  7. */
  8. class FileChunksTest extends \PHPUnit_Framework_TestCase
  9. {
  10. /**
  11. * @dataProvider data_testGeneratorYieldsFileChunks
  12. */
  13. public function testGeneratorYieldsStringChunks($chunkSize, array $expectedResult)
  14. {
  15. $fileChunks = new FileChunks(__DIR__.'/ItemsTest.json', $chunkSize);
  16. $result = iterator_to_array($fileChunks);
  17. $this->assertSame($expectedResult, $result);
  18. }
  19. public function data_testGeneratorYieldsFileChunks()
  20. {
  21. return [
  22. [5, ['{"pat', 'h": {', '"key"', ':"val', 'ue"}}', "\n"]],
  23. [6, ['{"path', '": {"k', 'ey":"v', 'alue"}', '}'."\n"]],
  24. [1024, ['{"path": {"key":"value"}}'."\n"]],
  25. ];
  26. }
  27. }