Skip to content

Commit

Permalink
manage exception for tests and infection, change xml version for vali…
Browse files Browse the repository at this point in the history
…date phpunit config, rename coverage by source
  • Loading branch information
JoMessina committed Nov 20, 2023
1 parent 53fa3b1 commit 67dacf9
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 7 deletions.
6 changes: 3 additions & 3 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.1/phpunit.xsd"
backupGlobals="true"
colors="false"
processIsolation="false"
Expand All @@ -21,11 +21,11 @@
<directory>tests/functional/</directory>
</testsuite>
</testsuites>
<coverage>
<source>
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
</source>
<php>
<ini name="allow_url_include" value="1" />
</php>
Expand Down
3 changes: 3 additions & 0 deletions src/Capacity/All.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/Capacity/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions src/Capacity/ListPerPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/Capacity/Upsert.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 14 additions & 2 deletions tests/functional/Factory/ExtractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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));
Expand Down
4 changes: 2 additions & 2 deletions tests/functional/Factory/LoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit 67dacf9

Please sign in to comment.