mirror of
https://github.com/cerbero90/json-parser.git
synced 2025-01-16 20:48:15 +01:00
Test that all sources are parsed correctly
This commit is contained in:
parent
840469a24f
commit
3eec5fc8fb
@ -10,11 +10,11 @@ use Generator;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Psr7\Request as Psr7Request;
|
||||
use GuzzleHttp\Psr7\Response as Psr7Response;
|
||||
use GuzzleHttp\Psr7\Stream;
|
||||
use Illuminate\Http\Client\Request;
|
||||
use Illuminate\Http\Client\Response;
|
||||
use Mockery;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
|
||||
/**
|
||||
* The dataset provider.
|
||||
@ -462,21 +462,15 @@ final class Dataset
|
||||
*/
|
||||
public static function forSources(): Generator
|
||||
{
|
||||
$parsed = require fixture('parsing/simple_array.php');
|
||||
$path = fixture('json/simple_array.json');
|
||||
$json = file_get_contents($path);
|
||||
$size = strlen($json);
|
||||
$request = new Psr7Request('GET', 'foo');
|
||||
|
||||
$stream = Mockery::mock(StreamInterface::class)
|
||||
->shouldReceive([
|
||||
'getSize' => $size,
|
||||
'isReadable' => true,
|
||||
])
|
||||
->getMock();
|
||||
|
||||
$response = Mockery::mock(ResponseInterface::class)
|
||||
->shouldReceive('getBody')
|
||||
->andReturn($stream)
|
||||
->andReturnUsing(fn () => new Stream(fopen($path, 'rb')))
|
||||
->getMock();
|
||||
|
||||
$client = Mockery::mock(Client::class)
|
||||
@ -500,7 +494,7 @@ final class Dataset
|
||||
|
||||
$psr7Response = Mockery::mock(Psr7Response::class)
|
||||
->shouldReceive('getBody')
|
||||
->andReturn($stream)
|
||||
->andReturn(new Stream(fopen($path, 'rb')))
|
||||
->getMock();
|
||||
|
||||
$psr7Request = Mockery::mock(Sources\Psr7Request::class, [$request])
|
||||
@ -522,11 +516,11 @@ final class Dataset
|
||||
new Sources\LaravelClientResponse(new Response($psr7Response)),
|
||||
new Sources\Psr7Message($response),
|
||||
$psr7Request,
|
||||
new Sources\Psr7Stream($stream),
|
||||
new Sources\Psr7Stream(new Stream(fopen($path, 'rb'))),
|
||||
];
|
||||
|
||||
foreach ($sources as $source) {
|
||||
yield [$source, $size];
|
||||
yield [$source, $size, $parsed];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,9 +17,11 @@ it('throws an exception when Guzzle is required but not installed', function (So
|
||||
->toThrow(GuzzleRequiredException::class, 'Guzzle is required to load JSON from endpoints');
|
||||
})->with(Dataset::forSourcesRequiringGuzzle());
|
||||
|
||||
it('supports multiple sources', function (Source $source, int $size) {
|
||||
it('supports multiple sources', function (Source $source, int $size, array $parsed) {
|
||||
expect($source)
|
||||
->getIterator()->toBeInstanceOf(Traversable::class)
|
||||
->matches()->toBeTrue()
|
||||
->size()->toBe($size);
|
||||
|
||||
expect(new JsonParser($source))->toParseTo($parsed);
|
||||
})->with(Dataset::forSources());
|
||||
|
Loading…
x
Reference in New Issue
Block a user