From 67dacf96e34ff8f7600948784b3257dd61b2c386 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Mon, 20 Nov 2023 17:29:34 +0100 Subject: [PATCH] manage exception for tests and infection, change xml version for validate phpunit config, rename coverage by source --- phpunit.xml | 6 +++--- src/Capacity/All.php | 3 +++ src/Capacity/Create.php | 4 ++++ src/Capacity/ListPerPage.php | 3 +++ src/Capacity/Upsert.php | 3 +++ tests/functional/Factory/ExtractorTest.php | 16 ++++++++++++++-- tests/functional/Factory/LoaderTest.php | 4 ++-- 7 files changed, 32 insertions(+), 7 deletions(-) diff --git a/phpunit.xml b/phpunit.xml index eadaa79..7fb2e0e 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,7 +1,7 @@ tests/functional/ - + src - + diff --git a/src/Capacity/All.php b/src/Capacity/All.php index 3fe81cc..e0aac54 100644 --- a/src/Capacity/All.php +++ b/src/Capacity/All.php @@ -120,6 +120,9 @@ public function __construct(private readonly ExpressionLanguage $interpreter) {} public function applies(array $config): bool { + if (!isset($config['api_type'])) { + return false; + } switch ($config['api_type']) { case 'admin': $endpoints = self::$endpointsAdmin; diff --git a/src/Capacity/Create.php b/src/Capacity/Create.php index 75efd8f..36157a3 100644 --- a/src/Capacity/Create.php +++ b/src/Capacity/Create.php @@ -4,6 +4,7 @@ namespace Kiboko\Plugin\Sylius\Capacity; +use Kiboko\Contract\Configurator\InvalidConfigurationException; use Kiboko\Plugin\Sylius; use Kiboko\Plugin\Sylius\Validator\ApiType; use PhpParser\Builder; @@ -79,6 +80,9 @@ final class Create implements CapacityInterface public function applies(array $config): bool { + if(!isset($config['api_type'])) { + throw new InvalidConfigurationException('Your Sylius API configuration is using some unsupported capacity, check your "api_type" properties to a suitable set.'); + } $endpoints = match ($config['api_type']) { 'admin' => self::$endpointsAdmin, 'shop' => self::$endpointsShop, diff --git a/src/Capacity/ListPerPage.php b/src/Capacity/ListPerPage.php index 0003b2c..2b4d06a 100644 --- a/src/Capacity/ListPerPage.php +++ b/src/Capacity/ListPerPage.php @@ -119,6 +119,9 @@ public function __construct(private readonly ExpressionLanguage $interpreter) {} public function applies(array $config): bool { + if (!isset($config['api_type'])) { + return false; + } switch ($config['api_type']) { case 'admin': $endpoints = self::$endpointsAdmin; diff --git a/src/Capacity/Upsert.php b/src/Capacity/Upsert.php index 8130d38..ac699f1 100644 --- a/src/Capacity/Upsert.php +++ b/src/Capacity/Upsert.php @@ -71,6 +71,9 @@ final class Upsert implements CapacityInterface public function applies(array $config): bool { + if (!isset($config['api_type'])) { + return false; + } $endpoints = match ($config['api_type']) { 'admin' => self::$endpointsAdmin, 'shop' => self::$endpointsShop, diff --git a/tests/functional/Factory/ExtractorTest.php b/tests/functional/Factory/ExtractorTest.php index e39795b..8dd3f3a 100644 --- a/tests/functional/Factory/ExtractorTest.php +++ b/tests/functional/Factory/ExtractorTest.php @@ -40,6 +40,18 @@ public static function wrongApiType(): \Generator 'api_type' => 'wrong', ], ]; + yield [ + 'config' => [ + 'type' => 'products', + 'api_type' => 'wrong', + ], + ]; + yield [ + 'config' => [ + 'method' => 'get', + 'api_type' => 'wrong', + ], + ]; } public static function missingApiType(): \Generator @@ -131,9 +143,9 @@ public function testWrongApiType(array $config) #[\PHPUnit\Framework\Attributes\DataProvider('missingApiType')] public function testMissingApiType(array $config) { - $this->expectException(\InvalidArgumentException::class); + $this->expectException(InvalidConfigurationException::class); $this->expectExceptionCode(0); - $this->expectExceptionMessage('The value of api_type should be one of [admin, shop, legacy], got null.'); + $this->expectExceptionMessage('Your Sylius API configuration is using some unsupported capacity, check your "api_type" properties to a suitable set.'); $client = new Loader(); $this->assertFalse($client->validate($config)); diff --git a/tests/functional/Factory/LoaderTest.php b/tests/functional/Factory/LoaderTest.php index 2e2d108..686d6f0 100644 --- a/tests/functional/Factory/LoaderTest.php +++ b/tests/functional/Factory/LoaderTest.php @@ -128,9 +128,9 @@ public function testWrongApiType(array $config) #[\PHPUnit\Framework\Attributes\DataProvider('missingApiType')] public function testMissingApiType(array $config) { - $this->expectException(\InvalidArgumentException::class); + $this->expectException(InvalidConfigurationException::class); $this->expectExceptionCode(0); - $this->expectExceptionMessage('The value of api_type should be one of [admin, shop, legacy], got null.'); + $this->expectExceptionMessage('Your Sylius API configuration is using some unsupported capacity, check your "api_type" properties to a suitable set.'); $client = new Loader(); $this->assertFalse($client->validate($config));