mirror of
https://github.com/cerbero90/json-parser.git
synced 2025-01-17 04:58:15 +01:00
Add tests for the progress value object
This commit is contained in:
parent
18cde0f63d
commit
5a65884255
@ -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);
|
||||
});
|
||||
|
24
tests/Unit/ValueObjects/ProgressTest.php
Normal file
24
tests/Unit/ValueObjects/ProgressTest.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
use Cerbero\JsonParser\ValueObjects\Progress;
|
||||
|
||||
|
||||
it('tracks the progress', function () {
|
||||
$progress = new Progress();
|
||||
|
||||
expect($progress)
|
||||
->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);
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user