Skip to content

Commit

Permalink
Conversion unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
leodido committed Dec 26, 2014
1 parent 6c35a49 commit f389ea1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
3 changes: 2 additions & 1 deletion library/Conversion.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,12 @@ public static function getOptionsFullQualifiedClassName($adapter)
}
if (!$adapter instanceof ConversionAlgorithmInterface) {
throw new Exception\InvalidArgumentException(sprintf(
'"%s" expects a string or an instance of ConversionAlgorithmInterface; received "%s"',
'"%s" expects an instance of ConversionAlgorithmInterface; received "%s"',
__METHOD__,
is_object($adapter) ? get_class($adapter) : gettype($adapter)
));
}

$adapterClass = get_class($adapter);
$namespace = substr($adapterClass, 0, strrpos($adapterClass, '\\'));
return $namespace . '\\Options\\' . $adapter->getName() . 'Options';
Expand Down
18 changes: 14 additions & 4 deletions tests/ConversionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ public function testConstructor()
$ctor->invoke($this->mock, $input);
}

public function testGetOptionsFQCNWithNotAConversionAlgorithmInterfaceShouldThrowInvalidArgumentException()
{
$this->setExpectedException('Conversio\Exception\InvalidArgumentException');
Conversion::getOptionsFullQualifiedClassName(new \stdClass());
}

public function testGetAdapterNotSetShouldThrowRuntimeException()
{
$filter = new Conversion();
Expand Down Expand Up @@ -269,6 +275,11 @@ public function testGetAdapterOptionsAndOptions()
$this->assertEmpty($filter->getOptions());
$this->assertEquals($fakeAdapterOpts, $filter->getAdapterOptions());
$this->assertEquals($fakeAdapterOpts->toArray(), $filter->getOptions());

$this->assertEquals($fakeAdapterOpts->getFake(), $filter->getOptions('fake'));

$this->setExpectedException('Conversio\Exception\RuntimeException');
$filter->getOptions('not_exists');
}

public function testSetAdapterOptionsWithInvalidTypeInputShouldThrowInvalidArgumentException()
Expand All @@ -286,15 +297,14 @@ public function testSetAdapterOptionsWithInvalidTypeInputShouldThrowInvalidArgum
$filter->setAdapterOptions('invalid');
}

public function testFilterNotString()
public function testFilter()
{
// Filtering a non string return the non strig input
$notAString = [];
$filter = new Conversion();
$this->assertEquals($notAString, $filter->filter($notAString));
}

public function testFilter()
{
// Filtering
$input = 'string';

$adapterMock = $this->getMock('Conversio\ConversionAlgorithmInterface');
Expand Down

0 comments on commit f389ea1

Please sign in to comment.