diff --git a/phpunit.xml b/phpunit.xml index 03c0f13..002a138 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -19,12 +19,6 @@ tests/Functional/ tests/BC/ - - tests/Unit/ - - - tests/Functional/ - diff --git a/src/V1/Factory.php b/src/V1/Factory.php index 8d99636..f1bab75 100644 --- a/src/V1/Factory.php +++ b/src/V1/Factory.php @@ -67,7 +67,11 @@ public function make($name, array $args = []): Accessable $object = $class->newInstanceArgs($args); if (! $object instanceof Accessable) { - throw new FactoryException($this->classes[$name] . ' must be instance of `Art4\JsonApiClient\Accessable`'); + throw new FactoryException(sprintf( + '%s must be instance of `%s`', + $this->classes[$name], + Accessable::class + )); } return $object; diff --git a/tests/Unit/V1/FactoryTest.php b/tests/Unit/V1/FactoryTest.php index a96aaef..5d1b6b0 100644 --- a/tests/Unit/V1/FactoryTest.php +++ b/tests/Unit/V1/FactoryTest.php @@ -13,6 +13,7 @@ use Art4\JsonApiClient\V1\Factory; use Art4\JsonApiClient\V1\ResourceNull; use PHPUnit\Framework\TestCase; +use stdClass; class FactoryTest extends TestCase { @@ -49,4 +50,18 @@ public function testMakeAnUndefindedClassThrowsException() $class = $factory->make('NotExistent'); } + + public function testMakeWithClassNotImplementingAccessableThrowsException() + { + $factory = new Factory([ + 'Default' => stdClass::class, + ]); + + $this->expectException(FactoryException::class); + $this->expectExceptionMessage( + 'stdClass must be instance of `Art4\JsonApiClient\Accessable`' + ); + + $class = $factory->make('Default'); + } }