66
77use GuzzleHttp \Client as HttpClient ;
88use GuzzleHttp \Psr7 \Response ;
9+ use GuzzleHttp \Psr7 \Stream ;
910use Packagist \Api \Client ;
1011use Packagist \Api \Result \Factory ;
1112use PhpSpec \ObjectBehavior ;
@@ -17,15 +18,16 @@ public function let(HttpClient $client, Factory $factory)
1718 $ this ->beConstructedWith ($ client , $ factory );
1819 }
1920
20- public function it_is_initializable ()
21+ public function it_is_initializable (): void
2122 {
2223 $ this ->shouldHaveType (Client::class);
2324 }
2425
25- public function it_search_for_packages (HttpClient $ client , Factory $ factory , Response $ response)
26+ public function it_search_for_packages (HttpClient $ client , Factory $ factory , Response $ response, Stream $ body ): void
2627 {
2728 $ data = file_get_contents ('spec/Packagist/Api/Fixture/search.json ' );
28- $ response ->getBody ()->shouldBeCalled ()->willReturn ($ data );
29+ $ response ->getBody ()->shouldBeCalled ()->willReturn ($ body );
30+ $ body ->getContents ()->shouldBeCalled ()->willReturn ($ data );
2931
3032 $ client ->request ('GET ' , 'https://packagist.org/search.json?q=sylius ' )
3133 ->shouldBeCalled ()
@@ -35,21 +37,23 @@ public function it_search_for_packages(HttpClient $client, Factory $factory, Res
3537 $ this ->search ('sylius ' );
3638 }
3739
38- public function it_search_for_packages_with_limit (HttpClient $ client , Factory $ factory , Response $ response)
40+ public function it_search_for_packages_with_limit (HttpClient $ client , Factory $ factory , Response $ response, Stream $ body ): void
3941 {
4042 $ data = file_get_contents ('spec/Packagist/Api/Fixture/search.json ' );
41- $ response ->getBody ()->shouldBeCalled ()->willReturn ($ data );
43+ $ response ->getBody ()->shouldBeCalled ()->willReturn ($ body );
44+ $ body ->getContents ()->shouldBeCalled ()->willReturn ($ data );
4245
4346 $ client ->request ('GET ' , 'https://packagist.org/search.json?q=sylius ' )->shouldBeCalled ()->willReturn ($ response );
4447 $ factory ->create (json_decode ($ data , true ))->shouldBeCalled ()->willReturn (array ());
4548
4649 $ this ->search ('sylius ' , [], 2 );
4750 }
4851
49- public function it_searches_for_packages_with_filters (HttpClient $ client , Factory $ factory , Response $ response)
52+ public function it_searches_for_packages_with_filters (HttpClient $ client , Factory $ factory , Response $ response, Stream $ body ): void
5053 {
5154 $ data = file_get_contents ('spec/Packagist/Api/Fixture/search.json ' );
52- $ response ->getBody ()->shouldBeCalled ()->willReturn ($ data );
55+ $ response ->getBody ()->shouldBeCalled ()->willReturn ($ body );
56+ $ body ->getContents ()->shouldBeCalled ()->willReturn ($ data );
5357
5458 $ client ->request ('GET ' , 'https://packagist.org/search.json?tag=storage&q=sylius ' )
5559 ->shouldBeCalled ()
@@ -60,10 +64,11 @@ public function it_searches_for_packages_with_filters(HttpClient $client, Factor
6064 $ this ->search ('sylius ' , ['tag ' => 'storage ' ]);
6165 }
6266
63- public function it_gets_popular_packages (HttpClient $ client , Factory $ factory , Response $ response)
67+ public function it_gets_popular_packages (HttpClient $ client , Factory $ factory , Response $ response, Stream $ body ): void
6468 {
6569 $ data = file_get_contents ('spec/Packagist/Api/Fixture/popular.json ' );
66- $ response ->getBody ()->shouldBeCalled ()->willReturn ($ data );
70+ $ response ->getBody ()->shouldBeCalled ()->willReturn ($ body );
71+ $ body ->getContents ()->shouldBeCalled ()->willReturn ($ data );
6772
6873 $ client ->request ('GET ' , 'https://packagist.org/explore/popular.json?page=1 ' )
6974 ->shouldBeCalled ()
@@ -76,10 +81,11 @@ public function it_gets_popular_packages(HttpClient $client, Factory $factory, R
7681 $ this ->popular (2 )->shouldHaveCount (2 );
7782 }
7883
79- public function it_gets_package_details (HttpClient $ client , Factory $ factory , Response $ response)
84+ public function it_gets_package_details (HttpClient $ client , Factory $ factory , Response $ response, Stream $ body ): void
8085 {
8186 $ data = file_get_contents ('spec/Packagist/Api/Fixture/get.json ' );
82- $ response ->getBody ()->shouldBeCalled ()->willReturn ($ data );
87+ $ response ->getBody ()->shouldBeCalled ()->willReturn ($ body );
88+ $ body ->getContents ()->shouldBeCalled ()->willReturn ($ data );
8389
8490 $ client ->request ('GET ' , 'https://packagist.org/packages/sylius/sylius.json ' )
8591 ->shouldBeCalled ()
@@ -90,10 +96,11 @@ public function it_gets_package_details(HttpClient $client, Factory $factory, Re
9096 $ this ->get ('sylius/sylius ' );
9197 }
9298
93- public function it_gets_composer_package_details (HttpClient $ client , Factory $ factory , Response $ response)
99+ public function it_gets_composer_package_details (HttpClient $ client , Factory $ factory , Response $ response, Stream $ body ): void
94100 {
95101 $ data = file_get_contents ('spec/Packagist/Api/Fixture/get_composer.json ' );
96- $ response ->getBody ()->shouldBeCalled ()->willReturn ($ data );
102+ $ response ->getBody ()->shouldBeCalled ()->willReturn ($ body );
103+ $ body ->getContents ()->shouldBeCalled ()->willReturn ($ data );
97104
98105 $ client ->request ('GET ' , 'https://packagist.org/p/sylius/sylius.json ' )
99106 ->shouldBeCalled ()
@@ -104,10 +111,26 @@ public function it_gets_composer_package_details(HttpClient $client, Factory $fa
104111 $ this ->getComposer ('sylius/sylius ' );
105112 }
106113
107- public function it_lists_all_package_names (HttpClient $ client , Factory $ factory , Response $ response )
114+ public function it_gets_composer_lite_package_details (HttpClient $ client , Factory $ factory , Response $ response , Stream $ body ): void
115+ {
116+ $ data = file_get_contents ('spec/Packagist/Api/Fixture/get_composer_lite.json ' );
117+ $ response ->getBody ()->shouldBeCalled ()->willReturn ($ body );
118+ $ body ->getContents ()->shouldBeCalled ()->willReturn ($ data );
119+
120+ $ client ->request ('GET ' , 'https://packagist.org/p/sylius/sylius.json ' )
121+ ->shouldBeCalled ()
122+ ->willReturn ($ response );
123+
124+ $ factory ->create (json_decode ($ data , true ))->shouldBeCalled ();
125+
126+ $ this ->getComposerLite ('sylius/sylius ' );
127+ }
128+
129+ public function it_lists_all_package_names (HttpClient $ client , Factory $ factory , Response $ response , Stream $ body ): void
108130 {
109131 $ data = file_get_contents ('spec/Packagist/Api/Fixture/all.json ' );
110- $ response ->getBody ()->shouldBeCalled ()->willReturn ($ data );
132+ $ response ->getBody ()->shouldBeCalled ()->willReturn ($ body );
133+ $ body ->getContents ()->shouldBeCalled ()->willReturn ($ data );
111134
112135 $ client ->request ('GET ' , 'https://packagist.org/packages/list.json ' )
113136 ->shouldBeCalled ()
@@ -118,10 +141,11 @@ public function it_lists_all_package_names(HttpClient $client, Factory $factory,
118141 $ this ->all ();
119142 }
120143
121- public function it_filters_package_names_by_type (HttpClient $ client , Factory $ factory , Response $ response)
144+ public function it_filters_package_names_by_type (HttpClient $ client , Factory $ factory , Response $ response, Stream $ body ): void
122145 {
123146 $ data = file_get_contents ('spec/Packagist/Api/Fixture/all.json ' );
124- $ response ->getBody ()->shouldBeCalled ()->willReturn ($ data );
147+ $ response ->getBody ()->shouldBeCalled ()->willReturn ($ body );
148+ $ body ->getContents ()->shouldBeCalled ()->willReturn ($ data );
125149
126150 $ client ->request ('GET ' , 'https://packagist.org/packages/list.json?type=library ' )
127151 ->shouldBeCalled ()
@@ -132,10 +156,11 @@ public function it_filters_package_names_by_type(HttpClient $client, Factory $fa
132156 $ this ->all (['type ' => 'library ' ]);
133157 }
134158
135- public function it_filters_package_names_by_vendor (HttpClient $ client , Factory $ factory , Response $ response)
159+ public function it_filters_package_names_by_vendor (HttpClient $ client , Factory $ factory , Response $ response, Stream $ body ): void
136160 {
137161 $ data = file_get_contents ('spec/Packagist/Api/Fixture/all.json ' );
138- $ response ->getBody ()->shouldBeCalled ()->willReturn ($ data );
162+ $ response ->getBody ()->shouldBeCalled ()->willReturn ($ body );
163+ $ body ->getContents ()->shouldBeCalled ()->willReturn ($ data );
139164
140165 $ client ->request ('GET ' , 'https://packagist.org/packages/list.json?vendor=sylius ' )
141166 ->shouldBeCalled ()
@@ -145,4 +170,5 @@ public function it_filters_package_names_by_vendor(HttpClient $client, Factory $
145170
146171 $ this ->all (['vendor ' => 'sylius ' ]);
147172 }
173+
148174}
0 commit comments