66use ScriptFUSION \Porter \Cache \CacheUnavailableException ;
77use ScriptFUSION \Porter \Connector \CachingConnector ;
88use ScriptFUSION \Porter \Connector \Connector ;
9+ use ScriptFUSION \Porter \Options \EncapsulatedOptions ;
910use ScriptFUSION \Porter \Provider \AbstractProvider ;
1011use ScriptFUSION \Porter \Provider \ForeignResourceException ;
1112use ScriptFUSION \Porter \Provider \Resource \ProviderResource ;
13+ use ScriptFUSIONTest \MockFactory ;
1214
1315final class AbstractProviderTest extends \PHPUnit_Framework_TestCase
1416{
1517 use MockeryPHPUnitIntegration;
1618
17- /** @var AbstractProvider */
19+ /**
20+ * @var AbstractProvider
21+ */
1822 private $ provider ;
1923
20- /** @var MockInterface */
24+ /**
25+ * @var MockInterface|Connector
26+ */
2127 private $ connector ;
2228
2329 protected function setUp ()
@@ -40,23 +46,41 @@ private function setupCachingConnector()
4046 return $ connector ;
4147 }
4248
43- public function testFetch ()
49+ public function testFetchWithoutOptions ()
4450 {
4551 self ::assertSame (
4652 'foo ' ,
4753 $ this ->provider ->fetch (
48- \Mockery:: mock (ProviderResource::class )
54+ MockFactory:: mockResource ( $ this -> provider )
4955 ->shouldReceive ('fetch ' )
50- ->with ($ this ->connector )
56+ ->with ($ this ->connector , null )
5157 ->andReturn ('foo ' )
5258 ->getMock ()
53- ->shouldReceive ('getProviderClassName ' )
54- ->andReturn (get_class ($ this ->provider ))
55- ->getMock ()
5659 )
5760 );
5861 }
5962
63+ /**
64+ * Tests that a clone of the provider's options are passed to ProviderResource::fetch().
65+ */
66+ public function testFetchWithOptions ()
67+ {
68+ $ this ->setOptions ($ options = \Mockery::mock (EncapsulatedOptions::class));
69+
70+ $ this ->provider ->fetch (
71+ MockFactory::mockResource ($ this ->provider )
72+ ->shouldReceive ('fetch ' )
73+ ->with ($ this ->connector , \Mockery::on (
74+ function (EncapsulatedOptions $ argument ) use ($ options ) {
75+ self ::assertNotSame ($ options , $ argument );
76+
77+ return get_class ($ options ) === get_class ($ argument );
78+ }
79+ ))
80+ ->getMock ()
81+ );
82+ }
83+
6084 public function testFetchForeignProvider ()
6185 {
6286 $ this ->setExpectedException (ForeignResourceException::class);
@@ -114,4 +138,35 @@ public function testCacheEnabledMirrorsCachingConnector()
114138 self ::assertTrue ($ this ->provider ->isCacheEnabled ());
115139 self ::assertFalse ($ this ->provider ->isCacheEnabled ());
116140 }
141+
142+ public function testOptions ()
143+ {
144+ $ this ->setOptions ($ options = \Mockery::mock (EncapsulatedOptions::class));
145+
146+ self ::assertSame ($ options , $ this ->getOptions ());
147+ }
148+
149+ private function getOptions ()
150+ {
151+ return call_user_func (
152+ \Closure::bind (
153+ function () {
154+ return $ this ->getOptions ();
155+ },
156+ $ this ->provider
157+ )
158+ );
159+ }
160+
161+ private function setOptions (EncapsulatedOptions $ options )
162+ {
163+ call_user_func (
164+ \Closure::bind (
165+ function () use ($ options ) {
166+ $ this ->setOptions ($ options );
167+ },
168+ $ this ->provider
169+ )
170+ );
171+ }
117172}
0 commit comments