Skip to content

Commit

Permalink
Reach 100% code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Art4 committed Oct 13, 2023
1 parent 4134936 commit 08bed29
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
6 changes: 0 additions & 6 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@
<directory suffix="Test.php">tests/Functional/</directory>
<directory suffix="Test.php">tests/BC/</directory>
</testsuite>
<testsuite name="unit">
<directory suffix="Test.php">tests/Unit/</directory>
</testsuite>
<testsuite name="functional">
<directory suffix="Test.php">tests/Functional/</directory>
</testsuite>
</testsuites>
<source>
<include>
Expand Down
6 changes: 5 additions & 1 deletion src/V1/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 15 additions & 0 deletions tests/Unit/V1/FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Art4\JsonApiClient\V1\Factory;
use Art4\JsonApiClient\V1\ResourceNull;
use PHPUnit\Framework\TestCase;
use stdClass;

class FactoryTest extends TestCase
{
Expand Down Expand Up @@ -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');
}
}

0 comments on commit 08bed29

Please sign in to comment.