diff --git a/tests/Dataset.php b/tests/Dataset.php index 71d55b2..e1ceb52 100644 --- a/tests/Dataset.php +++ b/tests/Dataset.php @@ -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]; } } } diff --git a/tests/Feature/SourcesTest.php b/tests/Feature/SourcesTest.php index f54801b..29f45ca 100644 --- a/tests/Feature/SourcesTest.php +++ b/tests/Feature/SourcesTest.php @@ -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());