diff --git a/tests/Feature/ParsingTest.php b/tests/Feature/ParsingTest.php index b93b1a7..5309962 100644 --- a/tests/Feature/ParsingTest.php +++ b/tests/Feature/ParsingTest.php @@ -21,3 +21,15 @@ it('parses JSON when calling the helper', function (string $json, array $parsed) it('eager loads JSON into an array', function (string $json, array $parsed) { expect(JsonParser::parse($json)->toArray())->toBe($parsed); })->with(Dataset::forParsing()); + +it('shows the progress while parsing', function () { + $parser = new JsonParser(fixture('json/simple_array.json')); + + expect($parser->progress()->percentage())->toBe($percentage = 0.0); + + foreach ($parser as $value) { + expect($percentage)->toBeLessThan($percentage = $parser->progress()->percentage()); + } + + expect($parser->progress()->percentage())->toBe(100.0); +}); diff --git a/tests/Unit/ValueObjects/ProgressTest.php b/tests/Unit/ValueObjects/ProgressTest.php new file mode 100644 index 0000000..0786d59 --- /dev/null +++ b/tests/Unit/ValueObjects/ProgressTest.php @@ -0,0 +1,24 @@ +current()->toBe(0) + ->total()->toBeNull() + ->format()->toBeNull() + ->percentage()->toBeNull() + ->fraction()->toBeNull(); + + $progress->setTotal(200)->setCurrent(33); + + expect($progress) + ->current()->toBe(33) + ->total()->toBe(200) + ->format()->toBe('16.5%') + ->percentage()->toBe(16.5) + ->fraction()->toBe(0.165); +});