From 7c16a703be03f4ceb086da52965d348cdc03e57f Mon Sep 17 00:00:00 2001 From: Bilge Date: Tue, 31 Jan 2017 20:34:47 +0000 Subject: [PATCH] Added missing ImportSpecification tests. --- .../Porter/Connector/CachingConnectorTest.php | 2 +- test/Stubs/Invokable.php | 10 +++++ .../{Porter/Options => Stubs}/TestOptions.php | 2 +- test/Unit/Porter/ImportSpecificationTest.php | 44 +++++++++++++++++-- .../Options/EncapsulatedOptionsTest.php | 2 +- 5 files changed, 54 insertions(+), 6 deletions(-) create mode 100644 test/Stubs/Invokable.php rename test/{Porter/Options => Stubs}/TestOptions.php (91%) diff --git a/test/Integration/Porter/Connector/CachingConnectorTest.php b/test/Integration/Porter/Connector/CachingConnectorTest.php index cfbb8d8..3115957 100644 --- a/test/Integration/Porter/Connector/CachingConnectorTest.php +++ b/test/Integration/Porter/Connector/CachingConnectorTest.php @@ -5,7 +5,7 @@ use Mockery\MockInterface; use ScriptFUSION\Porter\Connector\CachingConnector; use ScriptFUSION\Porter\Options\EncapsulatedOptions; -use ScriptFUSIONTest\Porter\Options\TestOptions; +use ScriptFUSIONTest\Stubs\TestOptions; final class CachingConnectorTest extends \PHPUnit_Framework_TestCase { diff --git a/test/Stubs/Invokable.php b/test/Stubs/Invokable.php new file mode 100644 index 0000000..e942af9 --- /dev/null +++ b/test/Stubs/Invokable.php @@ -0,0 +1,10 @@ +specification ->addTransformer(\Mockery::mock(Transformer::class)) - ->setContext($context = (object)[]); + ->setContext($context = (object)[]) + ->setFetchExceptionHandler($handler = new Invokable) + ; + $specification = clone $this->specification; self::assertNotSame($this->resource, $specification->getResource()); @@ -42,6 +46,7 @@ public function testClone() self::assertCount(count($this->specification->getTransformers()), $specification->getTransformers()); self::assertNotSame($context, $specification->getContext()); + self::assertNotSame($handler, $specification->getFetchExceptionHandler()); } public function testProviderData() @@ -79,10 +84,10 @@ public function testAddTransformers() public function testAddSameTransformer() { - $this->specification->addTransformer($transformer1 = \Mockery::mock(Transformer::class)); + $this->specification->addTransformer($transformer = \Mockery::mock(Transformer::class)); $this->setExpectedException(DuplicateTransformerException::class); - $this->specification->addTransformer($transformer1); + $this->specification->addTransformer($transformer); } public function testContext() @@ -97,4 +102,37 @@ public function testCacheAdvice() $this->specification->setCacheAdvice($advice)->getCacheAdvice() ); } + + /** + * @param mixed $input + * @param int $output + * + * @dataProvider provideFetchAttempts + */ + public function testMaxFetchAttempts($input, $output) + { + self::assertSame($output, $this->specification->setMaxFetchAttempts($input)->getMaxFetchAttempts()); + } + + public function provideFetchAttempts() + { + return [ + // Valid. + [1, 1], + [2, 2], + + // Invalid. + 'Too low, positive' => [0, 1], + 'Too low, negative' => [-1, 1], + 'Float in range' => [1.9, 1], + ]; + } + + public function testExceptionHandler() + { + self::assertSame( + $handler = new Invokable, + $this->specification->setFetchExceptionHandler($handler)->getFetchExceptionHandler() + ); + } } diff --git a/test/Unit/Porter/Options/EncapsulatedOptionsTest.php b/test/Unit/Porter/Options/EncapsulatedOptionsTest.php index d1145cb..783da57 100644 --- a/test/Unit/Porter/Options/EncapsulatedOptionsTest.php +++ b/test/Unit/Porter/Options/EncapsulatedOptionsTest.php @@ -1,7 +1,7 @@