1515};
1616use Innmind \Filesystem \File \Content ;
1717use Innmind \Url \Url ;
18- use Innmind \Http \Message \ {
18+ use Innmind \Http \{
1919 Request ,
20- StatusCode ,
2120 Response ,
21+ Response \StatusCode ,
22+ ProtocolVersion ,
2223};
2324use Innmind \Immutable \Either ;
2425use PHPUnit \Framework \TestCase ;
@@ -32,31 +33,25 @@ public function testExecution()
3233 'InnmindCrawler ' ,
3334 );
3435 $ url = Url::of ('http://example.com ' );
35- $ response = $ this ->createMock (Response::class);
36- $ response
37- ->expects ($ this ->once ())
38- ->method ('statusCode ' )
39- ->willReturn (StatusCode::ok);
40- $ response
41- ->expects ($ this ->once ())
42- ->method ('body ' )
43- ->willReturn (
44- Content \Lines::ofContent (<<<TXT
45- Sitemap : foo.xml
46- Host : example.com
47- Crawl-delay: 10
48- User-agent : Foo
49- User-agent : Bar
50- Allow : /foo
51- Disallow : /bar
36+ $ response = Response::of (
37+ StatusCode::ok,
38+ ProtocolVersion::v11,
39+ null ,
40+ Content::ofString (<<<TXT
41+ Sitemap : foo.xml
42+ Host : example.com
43+ Crawl-delay: 10
44+ User-agent : Foo
45+ User-agent : Bar
46+ Allow : /foo
47+ Disallow : /bar
5248
53- User-agent : *
54- Disallow :
55- Crawl-delay : 10
56- Crawl-delay : 20
57- TXT
58- ),
59- );
49+ User-agent : *
50+ Disallow :
51+ Crawl-delay : 10
52+ Crawl-delay : 20
53+ TXT ),
54+ );
6055 $ transport
6156 ->expects ($ this ->once ())
6257 ->method ('__invoke ' )
@@ -71,8 +66,8 @@ public function testExecution()
7166 ) &&
7267 $ request ->body ()->toString () === '' ;
7368 }))
74- ->willReturn ( Either::right (new Success (
75- $ this -> createMock (Request::class) ,
69+ ->willReturnCallback ( static fn ( $ request ) => Either::right (new Success (
70+ $ request ,
7671 $ response ,
7772 )));
7873 $ expected = 'User-agent: Foo ' ."\n" ;
@@ -101,19 +96,15 @@ public function testThrowWhenRequestNotFulfilled()
10196 'InnmindCrawler ' ,
10297 );
10398 $ url = Url::of ('http://example.com ' );
104- $ response = $ this ->createMock (Response::class);
105- $ response
106- ->expects ($ this ->once ())
107- ->method ('statusCode ' )
108- ->willReturn (StatusCode::notFound);
109- $ response
110- ->expects ($ this ->never ())
111- ->method ('body ' );
99+ $ response = Response::of (
100+ StatusCode::notFound,
101+ ProtocolVersion::v11,
102+ );
112103 $ transport
113104 ->expects ($ this ->once ())
114105 ->method ('__invoke ' )
115- ->willReturn ( Either::left (new ClientError (
116- $ this -> createMock (Request::class) ,
106+ ->willReturnCallback ( static fn ( $ request ) => Either::left (new ClientError (
107+ $ request ,
117108 $ response ,
118109 )));
119110
0 commit comments