1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace JsonMapper \LaravelPackage \Tests \Integration ;
6+
7+ use JsonMapper \LaravelPackage \JsonMapperInterface ;
8+ use JsonMapper \LaravelPackage \ServiceProvider ;
9+ use JsonMapper \LaravelPackage \Tests \Implementation \ChuckNorris \Joke ;
10+ use \Orchestra \Testbench \TestCase ;
11+
12+ class JsonMapperTests extends TestCase
13+ {
14+ protected function getPackageProviders ($ app )
15+ {
16+ return [
17+ ServiceProvider::class,
18+ ];
19+ }
20+
21+ /** @covers \JsonMapper\LaravelPackage\JsonMapper */
22+ public function testJsonMapperCanMapToCollection (): void
23+ {
24+ /** @var JsonMapperInterface $mapper */
25+ $ mapper = $ this ->app ->make (JsonMapperInterface::class);
26+ $ url = "https://api.chucknorris.io/jokes/search?query=save " ;
27+ $ data = (string ) file_get_contents ($ url );
28+ $ json = json_decode ($ data , false );
29+ $ jokes = $ mapper ->mapToCollection ($ json ->result , new Joke ());
30+
31+ self ::assertContainsOnlyInstancesOf (Joke::class, $ jokes ->all ());
32+ }
33+
34+ /** @covers \JsonMapper\LaravelPackage\JsonMapper */
35+ public function testJsonMapperCanMapToCollectionWithLargeJson (): void
36+ {
37+ /** @var JsonMapperInterface $mapper */
38+ $ mapper = $ this ->app ->make (JsonMapperInterface::class);
39+ $ url = "https://api.chucknorris.io/jokes/search?query=kick " ;
40+ $ data = (string ) file_get_contents ($ url );
41+ $ json = json_decode ($ data , false );
42+ $ jokes = $ mapper ->mapToCollection ($ json ->result , new Joke ());
43+
44+ self ::assertContainsOnlyInstancesOf (Joke::class, $ jokes ->all ());
45+ }
46+
47+ }
0 commit comments