66use ScriptFUSION \Porter \Specification \DuplicateTransformerException ;
77use ScriptFUSION \Porter \Specification \ImportSpecification ;
88use ScriptFUSION \Porter \Transform \Transformer ;
9+ use ScriptFUSIONTest \Stubs \Invokable ;
910
1011final class ImportSpecificationTest extends \PHPUnit_Framework_TestCase
1112{
@@ -26,7 +27,10 @@ public function testClone()
2627 {
2728 $ this ->specification
2829 ->addTransformer (\Mockery::mock (Transformer::class))
29- ->setContext ($ context = (object )[]);
30+ ->setContext ($ context = (object )[])
31+ ->setFetchExceptionHandler ($ handler = new Invokable )
32+ ;
33+
3034 $ specification = clone $ this ->specification ;
3135
3236 self ::assertNotSame ($ this ->resource , $ specification ->getResource ());
@@ -42,6 +46,7 @@ public function testClone()
4246 self ::assertCount (count ($ this ->specification ->getTransformers ()), $ specification ->getTransformers ());
4347
4448 self ::assertNotSame ($ context , $ specification ->getContext ());
49+ self ::assertNotSame ($ handler , $ specification ->getFetchExceptionHandler ());
4550 }
4651
4752 public function testProviderData ()
@@ -79,10 +84,10 @@ public function testAddTransformers()
7984
8085 public function testAddSameTransformer ()
8186 {
82- $ this ->specification ->addTransformer ($ transformer1 = \Mockery::mock (Transformer::class));
87+ $ this ->specification ->addTransformer ($ transformer = \Mockery::mock (Transformer::class));
8388
8489 $ this ->setExpectedException (DuplicateTransformerException::class);
85- $ this ->specification ->addTransformer ($ transformer1 );
90+ $ this ->specification ->addTransformer ($ transformer );
8691 }
8792
8893 public function testContext ()
@@ -97,4 +102,37 @@ public function testCacheAdvice()
97102 $ this ->specification ->setCacheAdvice ($ advice )->getCacheAdvice ()
98103 );
99104 }
105+
106+ /**
107+ * @param mixed $input
108+ * @param int $output
109+ *
110+ * @dataProvider provideFetchAttempts
111+ */
112+ public function testMaxFetchAttempts ($ input , $ output )
113+ {
114+ self ::assertSame ($ output , $ this ->specification ->setMaxFetchAttempts ($ input )->getMaxFetchAttempts ());
115+ }
116+
117+ public function provideFetchAttempts ()
118+ {
119+ return [
120+ // Valid.
121+ [1 , 1 ],
122+ [2 , 2 ],
123+
124+ // Invalid.
125+ 'Too low, positive ' => [0 , 1 ],
126+ 'Too low, negative ' => [-1 , 1 ],
127+ 'Float in range ' => [1.9 , 1 ],
128+ ];
129+ }
130+
131+ public function testExceptionHandler ()
132+ {
133+ self ::assertSame (
134+ $ handler = new Invokable ,
135+ $ this ->specification ->setFetchExceptionHandler ($ handler )->getFetchExceptionHandler ()
136+ );
137+ }
100138}
0 commit comments