@@ -48,35 +48,27 @@ public function testExecution()
4848 );
4949 $ url = Url::of ('http://example.com ' );
5050 $ parse = Parser::of (
51- new class ($ url , $ response , $ this ) implements Transport {
52- public function __construct (
53- private $ url ,
54- private $ response ,
55- private $ test ,
56- ) {
57- }
58-
59- public function __invoke (Request $ request ): Either
60- {
61- $ this ->test ->assertSame ($ this ->url , $ request ->url ());
62- $ this ->test ->assertSame ('GET ' , $ request ->method ()->toString ());
63- $ this ->test ->assertSame ('2.0 ' , $ request ->protocolVersion ()->toString ());
64- $ this ->test ->assertCount (1 , $ request ->headers ());
65- $ this ->test ->assertSame (
51+ Transport::via (
52+ function (Request $ request ) use ($ url , $ response ): Either {
53+ $ this ->assertSame ($ url , $ request ->url ());
54+ $ this ->assertSame ('GET ' , $ request ->method ()->toString ());
55+ $ this ->assertSame ('2.0 ' , $ request ->protocolVersion ()->toString ());
56+ $ this ->assertCount (1 , $ request ->headers ());
57+ $ this ->assertSame (
6658 'User-Agent: InnmindCrawler ' ,
6759 $ request ->headers ()->get ('user-agent ' )->match (
6860 static fn ($ header ) => $ header ->toString (),
6961 static fn () => null ,
7062 ),
7163 );
72- $ this ->test -> assertSame ('' , $ request ->body ()->toString ());
64+ $ this ->assertSame ('' , $ request ->body ()->toString ());
7365
7466 return Either::right (new Success (
7567 $ request ,
76- $ this -> response ,
68+ $ response ,
7769 ));
78- }
79- } ,
70+ },
71+ ) ,
8072 'InnmindCrawler ' ,
8173 );
8274 $ expected = 'User-agent: Foo ' ."\n" ;
@@ -106,21 +98,12 @@ public function testThrowWhenRequestNotFulfilled()
10698 ProtocolVersion::v11,
10799 );
108100 $ parse = Parser::of (
109- new class ($ url , $ response ) implements Transport {
110- public function __construct (
111- private $ url ,
112- private $ response ,
113- ) {
114- }
115-
116- public function __invoke (Request $ request ): Either
117- {
118- return Either::left (new ClientError (
119- $ request ,
120- $ this ->response ,
121- ));
122- }
123- },
101+ Transport::via (
102+ static fn (Request $ request ) => Either::left (new ClientError (
103+ $ request ,
104+ $ response ,
105+ )),
106+ ),
124107 'InnmindCrawler ' ,
125108 );
126109
0 commit comments