2
2
3
3
use Clue \React \Packagist \Api \Client ;
4
4
use React \Promise \Deferred ;
5
- use Clue \React \Buzz \Message \Response ;
6
- use Clue \React \Buzz \Message \Headers ;
7
- use Clue \React \Buzz \Message \Body ;
5
+ use RingCentral \Psr7 \Response ;
6
+ use React \Promise ;
8
7
9
8
class ClientTest extends TestCase
10
9
{
@@ -14,38 +13,46 @@ class ClientTest extends TestCase
14
13
public function setUp ()
15
14
{
16
15
$ this ->browser = $ this ->getMockBuilder ('Clue\React\Buzz\Browser ' )->disableOriginalConstructor ()->getMock ();
16
+ $ this ->browser ->expects ($ this ->any ())->method ('withBase ' )->willReturn ($ this ->browser );
17
17
18
18
$ this ->client = new Client ($ this ->browser );
19
19
}
20
20
21
21
public function testGet ()
22
22
{
23
- $ this ->setupBrowser ('packages/clue/zenity -react.json ' , $ this ->createResponsePromise ('{"package":{"name":"clue\/zenity-react", "versions": {}}} ' ));
23
+ $ this ->setupBrowser ('/ packages/clue%2Fzenity -react.json ' , $ this ->createResponsePromise ('{"package":{"name":"clue\/zenity-react", "versions": {}}} ' ));
24
24
25
25
$ this ->expectPromiseResolve ($ this ->client ->get ('clue/zenity-react ' ));
26
26
}
27
27
28
28
public function testAll ()
29
29
{
30
- $ this ->setupBrowser ('packages/list.json ' , $ this ->createResponsePromise ('{"packageNames":["a/a", "b/b"]} ' ));
30
+ $ this ->setupBrowser ('/ packages/list.json ' , $ this ->createResponsePromise ('{"packageNames":["a/a", "b/b"]} ' ));
31
31
32
32
$ this ->expectPromiseResolve ($ this ->client ->all ());
33
33
}
34
34
35
35
public function testAllVendor ()
36
36
{
37
- $ this ->setupBrowser ('packages/list.json?vendor=a ' , $ this ->createResponsePromise ('{"packageNames":["a/a"]} ' ));
37
+ $ this ->setupBrowser ('/ packages/list.json?vendor=a ' , $ this ->createResponsePromise ('{"packageNames":["a/a"]} ' ));
38
38
39
39
$ this ->expectPromiseResolve ($ this ->client ->all (array ('vendor ' => 'a ' )));
40
40
}
41
41
42
42
public function testSearch ()
43
43
{
44
- $ this ->setupBrowser ('search.json?q=zenity ' , $ this ->createResponsePromise ('{"results":[{"name":"clue\/zenity-react","description":"Build graphical desktop (GUI) applications in PHP","url":"https:\/\/packagist.org\/packages\/clue\/zenity-react","downloads":57,"favers":0,"repository":"https:\/\/github.com\/clue\/reactphp-zenity"}],"total":1} ' ));
44
+ $ this ->setupBrowser ('/ search.json?q=zenity ' , $ this ->createResponsePromise ('{"results":[{"name":"clue\/zenity-react","description":"Build graphical desktop (GUI) applications in PHP","url":"https:\/\/packagist.org\/packages\/clue\/zenity-react","downloads":57,"favers":0,"repository":"https:\/\/github.com\/clue\/reactphp-zenity"}],"total":1} ' ));
45
45
46
46
$ this ->expectPromiseResolve ($ this ->client ->search ('zenity ' ));
47
47
}
48
48
49
+ public function testSearchSpecialWithNoResults ()
50
+ {
51
+ $ this ->setupBrowser ('/search.json?q=%3C%C3%A4%3E ' , $ this ->createResponsePromise ('{"results":[],"total":0} ' ));
52
+
53
+ $ this ->expectPromiseResolve ($ this ->client ->search ('<ä> ' ));
54
+ }
55
+
49
56
public function testSearchPagination ()
50
57
{
51
58
$ this ->browser ->expects ($ this ->exactly (2 ))
@@ -60,7 +67,7 @@ public function testSearchPagination()
60
67
61
68
public function testHttpError ()
62
69
{
63
- $ this ->setupBrowser ('packages/clue/invalid .json ' , $ this ->createRejectedPromise (new RuntimeException ('error ' )));
70
+ $ this ->setupBrowser ('/ packages/clue%2Finvalid .json ' , $ this ->createRejectedPromise (new RuntimeException ('error ' )));
64
71
65
72
$ this ->expectPromiseReject ($ this ->client ->get ('clue/invalid ' ));
66
73
}
@@ -69,15 +76,16 @@ private function setupBrowser($expectedUrl, $promise)
69
76
{
70
77
$ this ->browser ->expects ($ this ->once ())
71
78
->method ('get ' )
72
- ->with ($ this ->equalTo (' https://packagist.org/ ' . $ expectedUrl ), array ())
79
+ ->with ($ this ->equalTo ($ expectedUrl ), array ())
73
80
->will ($ this ->returnValue ($ promise ));
74
81
}
75
82
76
83
private function createResponsePromise ($ fakeResponseBody )
77
84
{
78
- $ d = new Deferred ();
79
- $ d ->resolve (new Response ('HTTP/1.0 ' , 200 , 'OK ' , new Headers (), new Body ($ fakeResponseBody )));
80
- return $ d ->promise ();
85
+ $ response = $ this ->getMock ('Psr\Http\Message\ResponseInterface ' );
86
+ $ response ->expects ($ this ->once ())->method ('getBody ' )->willReturn ($ fakeResponseBody );
87
+
88
+ return Promise \resolve ($ response );
81
89
}
82
90
83
91
private function createRejectedPromise ($ reason )
0 commit comments