Skip to content

Commit 67dacf9

Browse files
committed
manage exception for tests and infection, change xml version for validate phpunit config, rename coverage by source
1 parent 53fa3b1 commit 67dacf9

File tree

7 files changed

+32
-7
lines changed

7 files changed

+32
-7
lines changed

phpunit.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0"?>
22
<phpunit
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd"
4+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.1/phpunit.xsd"
55
backupGlobals="true"
66
colors="false"
77
processIsolation="false"
@@ -21,11 +21,11 @@
2121
<directory>tests/functional/</directory>
2222
</testsuite>
2323
</testsuites>
24-
<coverage>
24+
<source>
2525
<include>
2626
<directory suffix=".php">src</directory>
2727
</include>
28-
</coverage>
28+
</source>
2929
<php>
3030
<ini name="allow_url_include" value="1" />
3131
</php>

src/Capacity/All.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ public function __construct(private readonly ExpressionLanguage $interpreter) {}
120120

121121
public function applies(array $config): bool
122122
{
123+
if (!isset($config['api_type'])) {
124+
return false;
125+
}
123126
switch ($config['api_type']) {
124127
case 'admin':
125128
$endpoints = self::$endpointsAdmin;

src/Capacity/Create.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Kiboko\Plugin\Sylius\Capacity;
66

7+
use Kiboko\Contract\Configurator\InvalidConfigurationException;
78
use Kiboko\Plugin\Sylius;
89
use Kiboko\Plugin\Sylius\Validator\ApiType;
910
use PhpParser\Builder;
@@ -79,6 +80,9 @@ final class Create implements CapacityInterface
7980

8081
public function applies(array $config): bool
8182
{
83+
if(!isset($config['api_type'])) {
84+
throw new InvalidConfigurationException('Your Sylius API configuration is using some unsupported capacity, check your "api_type" properties to a suitable set.');
85+
}
8286
$endpoints = match ($config['api_type']) {
8387
'admin' => self::$endpointsAdmin,
8488
'shop' => self::$endpointsShop,

src/Capacity/ListPerPage.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ public function __construct(private readonly ExpressionLanguage $interpreter) {}
119119

120120
public function applies(array $config): bool
121121
{
122+
if (!isset($config['api_type'])) {
123+
return false;
124+
}
122125
switch ($config['api_type']) {
123126
case 'admin':
124127
$endpoints = self::$endpointsAdmin;

src/Capacity/Upsert.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ final class Upsert implements CapacityInterface
7171

7272
public function applies(array $config): bool
7373
{
74+
if (!isset($config['api_type'])) {
75+
return false;
76+
}
7477
$endpoints = match ($config['api_type']) {
7578
'admin' => self::$endpointsAdmin,
7679
'shop' => self::$endpointsShop,

tests/functional/Factory/ExtractorTest.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@ public static function wrongApiType(): \Generator
4040
'api_type' => 'wrong',
4141
],
4242
];
43+
yield [
44+
'config' => [
45+
'type' => 'products',
46+
'api_type' => 'wrong',
47+
],
48+
];
49+
yield [
50+
'config' => [
51+
'method' => 'get',
52+
'api_type' => 'wrong',
53+
],
54+
];
4355
}
4456

4557
public static function missingApiType(): \Generator
@@ -131,9 +143,9 @@ public function testWrongApiType(array $config)
131143
#[\PHPUnit\Framework\Attributes\DataProvider('missingApiType')]
132144
public function testMissingApiType(array $config)
133145
{
134-
$this->expectException(\InvalidArgumentException::class);
146+
$this->expectException(InvalidConfigurationException::class);
135147
$this->expectExceptionCode(0);
136-
$this->expectExceptionMessage('The value of api_type should be one of [admin, shop, legacy], got null.');
148+
$this->expectExceptionMessage('Your Sylius API configuration is using some unsupported capacity, check your "api_type" properties to a suitable set.');
137149

138150
$client = new Loader();
139151
$this->assertFalse($client->validate($config));

tests/functional/Factory/LoaderTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,9 @@ public function testWrongApiType(array $config)
128128
#[\PHPUnit\Framework\Attributes\DataProvider('missingApiType')]
129129
public function testMissingApiType(array $config)
130130
{
131-
$this->expectException(\InvalidArgumentException::class);
131+
$this->expectException(InvalidConfigurationException::class);
132132
$this->expectExceptionCode(0);
133-
$this->expectExceptionMessage('The value of api_type should be one of [admin, shop, legacy], got null.');
133+
$this->expectExceptionMessage('Your Sylius API configuration is using some unsupported capacity, check your "api_type" properties to a suitable set.');
134134

135135
$client = new Loader();
136136
$this->assertFalse($client->validate($config));

0 commit comments

Comments
 (0)