Skip to content

Commit af94411

Browse files
authored
Merge pull request #81 from Art4/72-code-coverage
Show code coverage with Codecov.io
2 parents a51a371 + 08bed29 commit af94411

File tree

5 files changed

+32
-8
lines changed

5 files changed

+32
-8
lines changed

.github/workflows/unit-tests.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,14 @@ jobs:
4040
composer-options: --ignore-platform-reqs
4141

4242
- name: Run tests
43-
run: composer run phpunit -- --coverage-text
43+
run: composer run phpunit -- --coverage-clover .phpunit.cache/clover.xml
44+
45+
- name: Upload coverage reports to Codecov
46+
if: ${{ success() && matrix.php == '8.2' }}
47+
uses: codecov/codecov-action@v3
48+
env:
49+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
50+
with:
51+
files: ./.phpunit.cache/clover.xml
52+
fail_ci_if_error: true
53+
verbose: true

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
[![Latest Version](https://img.shields.io/github/release/Art4/json-api-client.svg)](https://github.com/Art4/json-api-client/releases)
44
[![Software License](https://img.shields.io/badge/license-GPL3-brightgreen.svg)](LICENSE)
55
[![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)
6+
[![codecov](https://codecov.io/gh/Art4/json-api-client/graph/badge.svg?token=5oNNDEUWgZ)](https://codecov.io/gh/Art4/json-api-client)
67
[![Total Downloads](https://img.shields.io/packagist/dt/art4/json-api-client.svg)](https://packagist.org/packages/art4/json-api-client)
78

89
JsonApiClient :construction_worker_woman: is a PHP Library to validate and handle the response body from a [JSON API](http://jsonapi.org) Server.

phpunit.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,6 @@
1919
<directory suffix="Test.php">tests/Functional/</directory>
2020
<directory suffix="Test.php">tests/BC/</directory>
2121
</testsuite>
22-
<testsuite name="unit">
23-
<directory suffix="Test.php">tests/Unit/</directory>
24-
</testsuite>
25-
<testsuite name="functional">
26-
<directory suffix="Test.php">tests/Functional/</directory>
27-
</testsuite>
2822
</testsuites>
2923
<source>
3024
<include>

src/V1/Factory.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@ public function make($name, array $args = []): Accessable
6767
$object = $class->newInstanceArgs($args);
6868

6969
if (! $object instanceof Accessable) {
70-
throw new FactoryException($this->classes[$name] . ' must be instance of `Art4\JsonApiClient\Accessable`');
70+
throw new FactoryException(sprintf(
71+
'%s must be instance of `%s`',
72+
$this->classes[$name],
73+
Accessable::class
74+
));
7175
}
7276

7377
return $object;

tests/Unit/V1/FactoryTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Art4\JsonApiClient\V1\Factory;
1414
use Art4\JsonApiClient\V1\ResourceNull;
1515
use PHPUnit\Framework\TestCase;
16+
use stdClass;
1617

1718
class FactoryTest extends TestCase
1819
{
@@ -49,4 +50,18 @@ public function testMakeAnUndefindedClassThrowsException()
4950

5051
$class = $factory->make('NotExistent');
5152
}
53+
54+
public function testMakeWithClassNotImplementingAccessableThrowsException()
55+
{
56+
$factory = new Factory([
57+
'Default' => stdClass::class,
58+
]);
59+
60+
$this->expectException(FactoryException::class);
61+
$this->expectExceptionMessage(
62+
'stdClass must be instance of `Art4\JsonApiClient\Accessable`'
63+
);
64+
65+
$class = $factory->make('Default');
66+
}
5267
}

0 commit comments

Comments
 (0)