From 2a841ab9eb497ac06862a0266052cd871343a040 Mon Sep 17 00:00:00 2001 From: Art4 Date: Fri, 13 Oct 2023 13:31:24 +0200 Subject: [PATCH 1/3] Upload code coverage report to codecov.io --- .github/workflows/unit-tests.yml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index ed8c22b..85d91ee 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -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 From 413493620045d078aad1a17cf7658355c6382d59 Mon Sep 17 00:00:00 2001 From: Art4 Date: Fri, 13 Oct 2023 13:34:15 +0200 Subject: [PATCH 2/3] Add codecov badge --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index e200ed8..1325e1a 100644 --- a/README.md +++ b/README.md @@ -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. From 08bed29e5b6af08cde80b08d9d2c3f01e0fadd48 Mon Sep 17 00:00:00 2001 From: Art4 Date: Fri, 13 Oct 2023 13:43:59 +0200 Subject: [PATCH 3/3] Reach 100% code coverage --- phpunit.xml | 6 ------ src/V1/Factory.php | 6 +++++- tests/Unit/V1/FactoryTest.php | 15 +++++++++++++++ 3 files changed, 20 insertions(+), 7 deletions(-) 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'); + } }