Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,14 @@ jobs:
composer-options: --ignore-platform-reqs

- name: Run tests
run: composer run phpunit -- --coverage-text
run: composer run phpunit -- --coverage-clover .phpunit.cache/clover.xml

- name: Upload coverage reports to Codecov
if: ${{ success() && matrix.php == '8.2' }}
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
files: ./.phpunit.cache/clover.xml
fail_ci_if_error: true
verbose: true
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[![Latest Version](https://img.shields.io/github/release/Art4/json-api-client.svg)](https://github.com/Art4/json-api-client/releases)
[![Software License](https://img.shields.io/badge/license-GPL3-brightgreen.svg)](LICENSE)
[![Build Status](https://github.com/art4/json-api-client/actions/workflows/unit-tests.yml/badge.svg?branch=v1.x)](https://github.com/Art4/json-api-client/actions)
[![codecov](https://codecov.io/gh/Art4/json-api-client/graph/badge.svg?token=5oNNDEUWgZ)](https://codecov.io/gh/Art4/json-api-client)
[![Total Downloads](https://img.shields.io/packagist/dt/art4/json-api-client.svg)](https://packagist.org/packages/art4/json-api-client)

JsonApiClient :construction_worker_woman: is a PHP Library to validate and handle the response body from a [JSON API](http://jsonapi.org) Server.
Expand Down
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');
}
}