Skip to content

Commit

Permalink
Added missing ImportSpecification tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bilge committed Jan 31, 2017
1 parent 6d16020 commit 7c16a70
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 6 deletions.
2 changes: 1 addition & 1 deletion test/Integration/Porter/Connector/CachingConnectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
10 changes: 10 additions & 0 deletions test/Stubs/Invokable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
namespace ScriptFUSIONTest\Stubs;

final class Invokable
{
public function __invoke()
{
// Inteiontionally empty.
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
namespace ScriptFUSIONTest\Porter\Options;
namespace ScriptFUSIONTest\Stubs;

use ScriptFUSION\Porter\Options\EncapsulatedOptions;

Expand Down
44 changes: 41 additions & 3 deletions test/Unit/Porter/ImportSpecificationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use ScriptFUSION\Porter\Specification\DuplicateTransformerException;
use ScriptFUSION\Porter\Specification\ImportSpecification;
use ScriptFUSION\Porter\Transform\Transformer;
use ScriptFUSIONTest\Stubs\Invokable;

final class ImportSpecificationTest extends \PHPUnit_Framework_TestCase
{
Expand All @@ -26,7 +27,10 @@ public function testClone()
{
$this->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());
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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()
);
}
}
2 changes: 1 addition & 1 deletion test/Unit/Porter/Options/EncapsulatedOptionsTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace ScriptFUSIONTest\Unit\Porter\Options;

use ScriptFUSIONTest\Porter\Options\TestOptions;
use ScriptFUSIONTest\Stubs\TestOptions;

final class EncapsulatedOptionsTest extends \PHPUnit_Framework_TestCase
{
Expand Down

0 comments on commit 7c16a70

Please sign in to comment.