22
33namespace FeedIo ;
44
5- use FeedIo \Rule \DateTimeBuilder ;
6- use FeedIo \Standard \Atom ;
5+ use FeedIo \Adapter \ClientFactory ;
6+ use Nyholm \Psr7 \Response ;
7+ use Nyholm \Psr7 \Stream ;
8+ use PHPUnit \Framework \TestCase ;
9+ use Psr \Http \Client \ClientInterface ;
10+ use Psr \Http \Message \StreamInterface ;
711
812/**
913 * Generated by PHPUnit_SkeletonGenerator on 2015-02-23 at 20:31:12.
1014 */
11- use PHPUnit \Framework \TestCase ;
12-
1315class FeedIoTest extends TestCase
1416{
1517 /**
@@ -23,18 +25,31 @@ class FeedIoTest extends TestCase
2325 */
2426 protected function setUp (): void
2527 {
26- $ client = $ this ->getMockForAbstractClass ('\FeedIo\Adapter\ClientInterface ' );
27- $ response = $ this ->createMock ('FeedIo\Adapter\ResponseInterface ' );
28- $ response ->expects ($ this ->any ())->method ('isModified ' )->will ($ this ->returnValue (true ));
29- $ response ->expects ($ this ->any ())->method ('getBody ' )->will ($ this ->returnValue (
30- file_get_contents (dirname (__FILE__ )."/../samples/expected-atom.xml " )
31- ));
32- $ response ->expects ($ this ->any ())->method ('getLastModified ' )->will ($ this ->returnValue (new \DateTime ()));
33- $ client ->expects ($ this ->any ())->method ('getResponse ' )->will ($ this ->returnValue ($ response ));
28+ $ html = file_get_contents (__DIR__ ."/../samples/expected-atom.xml " );
29+
30+ $ adapterClient = $ this ->getMockForAbstractClass ('\FeedIo\Adapter\ClientInterface ' );
31+ $ clientFactory = $ this ->createMock (ClientFactory::class);
32+ $ clientFactory ->expects ($ this ->once ())->method ('create ' )->willReturn ($ adapterClient );
33+
34+ $ stream = $ this ->createMock (Stream::class);
35+ $ stream ->expects ($ this ->any ())->method ('getContents ' )->willReturn ($ html );
36+
37+ $ psrResponse = $ this ->createMock (Response::class);
38+ $ psrResponse ->expects ($ this ->any ())->method ('getBody ' )->willReturn ($ stream );
39+ $ psrResponse ->expects ($ this ->any ())->method ('getStatusCode ' )->willReturn (200 );
40+
41+ $ client = $ this ->createMock (ClientInterface::class);
42+ $ client ->method ('sendRequest ' )->willReturn ($ psrResponse );
43+
44+ $ adapterResponse = $ this ->createMock ('FeedIo\Adapter\ResponseInterface ' );
45+ $ adapterResponse ->expects ($ this ->any ())->method ('isModified ' )->willReturn (true );
46+ $ adapterResponse ->expects ($ this ->any ())->method ('getBody ' )->willReturn ($ html );
47+ $ adapterResponse ->expects ($ this ->any ())->method ('getLastModified ' )->willReturn (new \DateTime ());
48+ $ adapterClient ->expects ($ this ->any ())->method ('getResponse ' )->willReturn ($ adapterResponse );
3449
3550 $ logger = new \Psr \Log \NullLogger ();
3651
37- $ this ->object = new FeedIo ($ client , $ logger , new Specification ($ logger ));
52+ $ this ->object = new FeedIo ($ client , $ logger , new Specification ($ logger ), $ clientFactory );
3853 }
3954
4055 /**
@@ -43,20 +58,34 @@ protected function setUp(): void
4358 */
4459 public function testConstruct ()
4560 {
46- $ client = $ this ->getMockForAbstractClass (' \FeedIo\Adapter\ ClientInterface' );
61+ $ client = $ this ->getMockForAbstractClass (ClientInterface::class );
4762 $ feedIo = new FeedIo ($ client , new \Psr \Log \NullLogger ());
4863 $ this ->assertInstanceOf ('\FeedIo\Reader ' , $ feedIo ->getReader ());
4964 }
5065
5166 public function testDiscovery ()
5267 {
53- $ html = file_get_contents (dirname (__FILE__ )."/../samples/discovery.html " );
54- $ client = $ this ->createMock ('FeedIo\Adapter\ClientInterface ' );
55- $ response = $ this ->createMock ('FeedIo\Adapter\ResponseInterface ' );
56- $ response ->expects ($ this ->any ())->method ('getBody ' )->will ($ this ->returnValue ($ html ));
57- $ client ->expects ($ this ->any ())->method ('getResponse ' )->will ($ this ->returnValue ($ response ));
68+ $ html = file_get_contents (__DIR__ ."/../samples/discovery.html " );
5869
59- $ feedIo = new FeedIo ($ client , new \Psr \Log \NullLogger ());
70+ $ adapterClient = $ this ->getMockForAbstractClass ('\FeedIo\Adapter\ClientInterface ' );
71+ $ clientFactory = $ this ->createMock (ClientFactory::class);
72+ $ clientFactory ->expects ($ this ->once ())->method ('create ' )->willReturn ($ adapterClient );
73+
74+ $ stream = $ this ->createMock (Stream::class);
75+ $ stream ->expects ($ this ->any ())->method ('getContents ' )->willReturn ($ html );
76+
77+ $ psrResponse = $ this ->createMock (Response::class);
78+ $ psrResponse ->method ('getBody ' )->willReturn ($ stream );
79+ $ psrResponse ->method ('getStatusCode ' )->willReturn (200 );
80+
81+ $ client = $ this ->createMock (ClientInterface::class);
82+ $ client ->method ('sendRequest ' )->willReturn ($ psrResponse );
83+
84+ $ adapterResponse = $ this ->createMock ('FeedIo\Adapter\ResponseInterface ' );
85+ $ adapterResponse ->expects ($ this ->any ())->method ('getBody ' )->willReturn ($ html );
86+ $ adapterClient ->expects ($ this ->any ())->method ('getResponse ' )->willReturn ($ adapterResponse );
87+
88+ $ feedIo = new FeedIo ($ client , new \Psr \Log \NullLogger (), null , $ clientFactory );
6089 $ urls = $ feedIo ->discover ('https://example.org/feed ' );
6190
6291 $ this ->assertCount (2 , $ urls );
0 commit comments