Skip to content

Commit 5eca1e4

Browse files
committed
improve tests and mutation percent, update phpunit config
1 parent 67dacf9 commit 5eca1e4

File tree

8 files changed

+356
-18
lines changed

8 files changed

+356
-18
lines changed

phpunit.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@
2121
<directory>tests/functional/</directory>
2222
</testsuite>
2323
</testsuites>
24-
<source>
25-
<include>
26-
<directory suffix=".php">src</directory>
27-
</include>
28-
</source>
2924
<php>
3025
<ini name="allow_url_include" value="1" />
3126
</php>

src/Capacity/All.php

Lines changed: 2 additions & 1 deletion
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;
@@ -121,7 +122,7 @@ public function __construct(private readonly ExpressionLanguage $interpreter) {}
121122
public function applies(array $config): bool
122123
{
123124
if (!isset($config['api_type'])) {
124-
return false;
125+
throw new InvalidConfigurationException('Your Sylius API configuration is using some unsupported capacity, check your "api_type" properties to a suitable set.');
125126
}
126127
switch ($config['api_type']) {
127128
case 'admin':

src/Capacity/ListPerPage.php

Lines changed: 2 additions & 1 deletion
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;
@@ -120,7 +121,7 @@ public function __construct(private readonly ExpressionLanguage $interpreter) {}
120121
public function applies(array $config): bool
121122
{
122123
if (!isset($config['api_type'])) {
123-
return false;
124+
throw new InvalidConfigurationException('Your Sylius API configuration is using some unsupported capacity, check your "api_type" properties to a suitable set.');
124125
}
125126
switch ($config['api_type']) {
126127
case 'admin':

src/Capacity/Upsert.php

Lines changed: 2 additions & 1 deletion
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;
@@ -72,7 +73,7 @@ final class Upsert implements CapacityInterface
7273
public function applies(array $config): bool
7374
{
7475
if (!isset($config['api_type'])) {
75-
return false;
76+
throw new InvalidConfigurationException('Your Sylius API configuration is using some unsupported capacity, check your "api_type" properties to a suitable set.');
7677
}
7778
$endpoints = match ($config['api_type']) {
7879
'admin' => self::$endpointsAdmin,

tests/functional/Configuration/ExtractorTest.php

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,90 @@ public static function validDataProvider(): iterable
6161
'search' => [],
6262
],
6363
];
64+
yield [
65+
'config' => [
66+
'type' => 'product',
67+
'method' => 'get',
68+
'api_type' => 'admin',
69+
'search' => [],
70+
],
71+
'expected' => [
72+
'type' => 'product',
73+
'method' => 'get',
74+
'api_type' => 'admin',
75+
'search' => [],
76+
],
77+
];
78+
yield [
79+
'config' => [
80+
'type' => 'product',
81+
'method' => 'all',
82+
'api_type' => 'admin',
83+
'search' => [],
84+
],
85+
'expected' => [
86+
'type' => 'product',
87+
'method' => 'all',
88+
'api_type' => 'admin',
89+
'search' => [],
90+
],
91+
];
92+
yield [
93+
'config' => [
94+
'type' => 'product',
95+
'method' => 'listPerPage',
96+
'api_type' => 'admin',
97+
'search' => [],
98+
],
99+
'expected' => [
100+
'type' => 'product',
101+
'method' => 'listPerPage',
102+
'api_type' => 'admin',
103+
'search' => [],
104+
],
105+
];
106+
yield [
107+
'config' => [
108+
'type' => 'product',
109+
'method' => 'get',
110+
'api_type' => 'shop',
111+
'search' => [],
112+
],
113+
'expected' => [
114+
'type' => 'product',
115+
'method' => 'get',
116+
'api_type' => 'shop',
117+
'search' => [],
118+
],
119+
];
120+
yield [
121+
'config' => [
122+
'type' => 'product',
123+
'method' => 'all',
124+
'api_type' => 'shop',
125+
'search' => [],
126+
],
127+
'expected' => [
128+
'type' => 'product',
129+
'method' => 'all',
130+
'api_type' => 'shop',
131+
'search' => [],
132+
],
133+
];
134+
yield [
135+
'config' => [
136+
'type' => 'product',
137+
'method' => 'listPerPage',
138+
'api_type' => 'shop',
139+
'search' => [],
140+
],
141+
'expected' => [
142+
'type' => 'product',
143+
'method' => 'listPerPage',
144+
'api_type' => 'shop',
145+
'search' => [],
146+
],
147+
];
64148
}
65149

66150
#[\PHPUnit\Framework\Attributes\DataProvider('validDataProvider')]

tests/functional/Configuration/LoaderTest.php

Lines changed: 89 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,100 @@ protected function setUp(): void
1616
{
1717
$this->processor = new Config\Definition\Processor();
1818
}
19+
20+
public static function validDataProvider(): iterable
21+
{
22+
yield [
23+
'config' => [
24+
'type' => 'products',
25+
'method' => 'create',
26+
'api_type' => 'legacy',
27+
],
28+
'expected' => [
29+
'type' => 'products',
30+
'method' => 'create',
31+
'api_type' => 'legacy',
32+
],
33+
];
34+
yield [
35+
'config' => [
36+
'type' => 'products',
37+
'method' => 'upsert',
38+
'api_type' => 'legacy',
39+
],
40+
'expected' => [
41+
'type' => 'products',
42+
'method' => 'upsert',
43+
'api_type' => 'legacy',
44+
],
45+
];
46+
yield [
47+
'config' => [
48+
'type' => 'product',
49+
'method' => 'create',
50+
'api_type' => 'admin',
51+
],
52+
'expected' => [
53+
'type' => 'product',
54+
'method' => 'create',
55+
'api_type' => 'admin',
56+
],
57+
];
58+
yield [
59+
'config' => [
60+
'type' => 'product',
61+
'method' => 'upsert',
62+
'api_type' => 'admin',
63+
],
64+
'expected' => [
65+
'type' => 'product',
66+
'method' => 'upsert',
67+
'api_type' => 'admin',
68+
],
69+
];
70+
yield [
71+
'config' => [
72+
'type' => 'customer',
73+
'method' => 'create',
74+
'api_type' => 'shop',
75+
],
76+
'expected' => [
77+
'type' => 'customer',
78+
'method' => 'create',
79+
'api_type' => 'shop',
80+
],
81+
];
82+
yield [
83+
'config' => [
84+
'type' => 'customer',
85+
'method' => 'upsert',
86+
'api_type' => 'shop',
87+
],
88+
'expected' => [
89+
'type' => 'customer',
90+
'method' => 'upsert',
91+
'api_type' => 'shop',
92+
],
93+
];
94+
}
95+
96+
#[\PHPUnit\Framework\Attributes\DataProvider('validDataProvider')]
97+
public function testValidConfig(array $config, array $expected): void
98+
{
99+
$client = new Configuration\Loader();
100+
101+
$this->assertSame($expected, $this->processor->processConfiguration($client, [$config]));
102+
}
103+
19104
public function testWrongApiType(): void
20105
{
21-
$client = new Configuration\Extractor();
106+
$client = new Configuration\Loader();
22107

23108
$this->expectException(
24109
Config\Definition\Exception\InvalidConfigurationException::class,
25110
);
26111
$this->expectExceptionMessage(
27-
'Invalid configuration for path "extractor.api_type": the value should be one of [admin, shop, legacy], got "invalidValue".',
112+
'Invalid configuration for path "loader.api_type": the value should be one of [admin, shop, legacy], got "invalidValue".',
28113
);
29114

30115
$this->processor->processConfiguration($client, [
@@ -38,13 +123,13 @@ public function testWrongApiType(): void
38123

39124
public function testWrongType(): void
40125
{
41-
$client = new Configuration\Extractor();
126+
$client = new Configuration\Loader();
42127

43128
$this->expectException(
44129
Config\Definition\Exception\InvalidConfigurationException::class,
45130
);
46131
$this->expectExceptionMessage(
47-
'Invalid configuration for path "extractor.type": the value should be one of [channels, countries, carts, currencies, customers, exchangeRates, locales, orders, payments, paymentMethods, products, productAttributes, productAssociationTypes, productOptions, promotions, shipments, shippingCategories, taxCategories, taxRates, taxons, users, zones, productReviews, productVariants, promotionCoupons], got "wrong".',
132+
'Invalid configuration for path "loader.type": the value should be one of [channels, countries, carts, currencies, customers, exchangeRates, locales, orders, payments, paymentMethods, products, productAttributes, productAssociationTypes, productOptions, promotions, shipments, shippingCategories, taxCategories, taxRates, taxons, users, zones], got "wrong".',
48133
);
49134

50135
$this->processor->processConfiguration($client, [

0 commit comments

Comments
 (0)