Skip to content

Commit

Permalink
Fixing review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
loevgaard committed Mar 18, 2022
1 parent ac8712f commit ee84d16
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 34 deletions.
2 changes: 0 additions & 2 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?xml version="1.0"?>
<psalm
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
totallyTyped="true"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
errorBaseline="psalm-baseline.xml"
Expand All @@ -13,7 +12,6 @@
<directory name="src/Fixture"/>
<directory name="tests/Application"/>
<directory name="vendor"/>
<file name="src/DependencyInjection/Configuration.php"/>
</ignoreFiles>
</projectFiles>
<plugins>
Expand Down
13 changes: 7 additions & 6 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public function getConfigTreeBuilder(): TreeBuilder

$rootNode = $treeBuilder->getRootNode();

/**
* @psalm-suppress MixedMethodCall,PossiblyNullReference,PossiblyUndefinedMethod
*/
$rootNode
->addDefaultsIfNotSet()
->children()
Expand Down Expand Up @@ -84,16 +87,11 @@ private function addResourcesSection(ArrayNodeDefinition $node): void
$this->addGiftCardConfigurationSection($resourcesNode);
$this->addGiftCardConfigurationImageSection($resourcesNode);
$this->addChannelConfigurationSection($resourcesNode);

$resourcesNode
->end()
->end()
->end()
;
}

private function addGiftCardSection(NodeBuilder $nodeBuilder): void
{
/** @psalm-suppress MixedMethodCall,PossiblyNullReference,PossiblyUndefinedMethod */
$nodeBuilder
->arrayNode('gift_card')
->addDefaultsIfNotSet()
Expand All @@ -113,6 +111,7 @@ private function addGiftCardSection(NodeBuilder $nodeBuilder): void

private function addGiftCardConfigurationSection(NodeBuilder $nodeBuilder): void
{
/** @psalm-suppress MixedMethodCall,PossiblyNullReference,PossiblyUndefinedMethod */
$nodeBuilder
->arrayNode('gift_card_configuration')
->addDefaultsIfNotSet()
Expand All @@ -132,6 +131,7 @@ private function addGiftCardConfigurationSection(NodeBuilder $nodeBuilder): void

private function addGiftCardConfigurationImageSection(NodeBuilder $nodeBuilder): void
{
/** @psalm-suppress MixedMethodCall,PossiblyNullReference,PossiblyUndefinedMethod */
$nodeBuilder
->arrayNode('gift_card_configuration_image')
->addDefaultsIfNotSet()
Expand All @@ -151,6 +151,7 @@ private function addGiftCardConfigurationImageSection(NodeBuilder $nodeBuilder):

private function addChannelConfigurationSection(NodeBuilder $nodeBuilder): void
{
/** @psalm-suppress MixedMethodCall,PossiblyNullReference,PossiblyUndefinedMethod */
$nodeBuilder
->arrayNode('gift_card_channel_configuration')
->addDefaultsIfNotSet()
Expand Down
10 changes: 7 additions & 3 deletions src/DependencyInjection/SetonoSyliusGiftCardExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public function load(array $configs, ContainerBuilder $container): void
* @var array{
* pdf_rendering: array{
* default_orientation: string,
* available_orientations: array<array-key, string>,
* available_orientations: list<string>,
* default_page_size: string,
* available_page_sizes: array<array-key, string>,
* available_page_sizes: list<string>,
* },
* code_length: int,
* driver: string,
Expand Down Expand Up @@ -54,7 +54,11 @@ public function load(array $configs, ContainerBuilder $container): void
$loader->load('services.xml');

if ($container->hasParameter('kernel.bundles')) {
/** @var array $bundles */
/**
* @var array $bundles
*
* @psalm-suppress UndefinedDocblockClass
*/
$bundles = $container->getParameter('kernel.bundles');
if (array_key_exists('SetonoSyliusCatalogPromotionPlugin', $bundles)) {
$loader->load('services/conditional/catalog_promotion_rule.xml');
Expand Down
6 changes: 5 additions & 1 deletion src/Form/Type/GiftCardConfigurationType.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@

final class GiftCardConfigurationType extends AbstractResourceType
{
/** @var list<string> */
private array $availableOrientations;

/** @var list<string> */
private array $availablePageSizes;

/**
* @psalm-param array<array-key, string> $validationGroups
* @param list<string> $availableOrientations
* @param list<string> $availablePageSizes
* @param list<string> $validationGroups
*/
public function __construct(
array $availableOrientations,
Expand Down
7 changes: 7 additions & 0 deletions src/Generator/GiftCardCodeGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,22 @@

use function preg_replace;
use Setono\SyliusGiftCardPlugin\Repository\GiftCardRepositoryInterface;
use Webmozart\Assert\Assert;

final class GiftCardCodeGenerator implements GiftCardCodeGeneratorInterface
{
private GiftCardRepositoryInterface $giftCardRepository;

/** @var positive-int */
private int $codeLength;

/**
* @param positive-int $codeLength
*/
public function __construct(GiftCardRepositoryInterface $giftCardRepository, int $codeLength)
{
Assert::greaterThan($codeLength, 0);

$this->giftCardRepository = $giftCardRepository;
$this->codeLength = $codeLength;
}
Expand Down
23 changes: 2 additions & 21 deletions tests/Unit/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Tests\Setono\SyliusGiftCardPlugin\Unit\DependencyInjection;

use Matthias\SymfonyConfigTest\PhpUnit\ConfigurationTestCaseTrait;
use PHPUnit\Framework\TestCase;
use Setono\SyliusGiftCardPlugin\DependencyInjection\Configuration;
use Setono\SyliusGiftCardPlugin\Doctrine\ORM\GiftCardRepository;
use Setono\SyliusGiftCardPlugin\Form\Type\GiftCardChannelConfigurationType;
Expand All @@ -23,9 +24,8 @@
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository;
use Sylius\Bundle\ResourceBundle\SyliusResourceBundle;
use Sylius\Component\Resource\Factory\Factory;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;

final class ConfigurationTest extends KernelTestCase
final class ConfigurationTest extends TestCase
{
use ConfigurationTestCaseTrait;

Expand Down Expand Up @@ -128,23 +128,4 @@ public function processed_configuration_for_array_node_1(): void
],
]);
}

/**
* @test
*/
public function it_overrides_default_configuration(): void
{
self::bootKernel();
$container = self::$container;

self::assertEquals(
$container->getParameter('setono_sylius_gift_card.pdf_rendering.available_page_sizes'),
['A5', 'B0']
);

self::assertEquals(
$container->getParameter('setono_sylius_gift_card.pdf_rendering.available_orientations'),
['Landscape']
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase;
use Setono\SyliusGiftCardPlugin\DependencyInjection\SetonoSyliusGiftCardExtension;
use Setono\SyliusGiftCardPlugin\Provider\PdfRenderingOptionsProviderInterface;
use Sylius\Bundle\ResourceBundle\SyliusResourceBundle;

final class SetonoSyliusGiftCardExtensionTest extends AbstractExtensionTestCase
Expand All @@ -22,7 +23,42 @@ public function after_loading_the_correct_parameter_has_been_set(): void
{
$this->load();

$this->assertContainerBuilderHasParameter('setono_sylius_gift_card.code_length', 20);
$this->assertContainerBuilderHasParameter('setono_sylius_gift_card.driver', SyliusResourceBundle::DRIVER_DOCTRINE_ORM);
$this->assertContainerBuilderHasParameter('setono_sylius_gift_card.code_length', 20);
$this->assertContainerBuilderHasParameter('setono_sylius_gift_card.pdf_rendering.default_orientation', 'Portrait');
$this->assertContainerBuilderHasParameter('setono_sylius_gift_card.pdf_rendering.available_orientations', ['Portrait', 'Landscape']);
$this->assertContainerBuilderHasParameter('setono_sylius_gift_card.pdf_rendering.default_page_size', 'A4');
$this->assertContainerBuilderHasParameter('setono_sylius_gift_card.pdf_rendering.available_page_sizes', [
PdfRenderingOptionsProviderInterface::PAGE_SIZE_A0,
PdfRenderingOptionsProviderInterface::PAGE_SIZE_A1,
PdfRenderingOptionsProviderInterface::PAGE_SIZE_A2,
PdfRenderingOptionsProviderInterface::PAGE_SIZE_A3,
PdfRenderingOptionsProviderInterface::PAGE_SIZE_A4,
PdfRenderingOptionsProviderInterface::PAGE_SIZE_A5,
PdfRenderingOptionsProviderInterface::PAGE_SIZE_A6,
PdfRenderingOptionsProviderInterface::PAGE_SIZE_A7,
PdfRenderingOptionsProviderInterface::PAGE_SIZE_A8,
PdfRenderingOptionsProviderInterface::PAGE_SIZE_A9,
PdfRenderingOptionsProviderInterface::PAGE_SIZE_B0,
PdfRenderingOptionsProviderInterface::PAGE_SIZE_B1,
PdfRenderingOptionsProviderInterface::PAGE_SIZE_B2,
PdfRenderingOptionsProviderInterface::PAGE_SIZE_B3,
PdfRenderingOptionsProviderInterface::PAGE_SIZE_B4,
PdfRenderingOptionsProviderInterface::PAGE_SIZE_B5,
PdfRenderingOptionsProviderInterface::PAGE_SIZE_B6,
PdfRenderingOptionsProviderInterface::PAGE_SIZE_B7,
PdfRenderingOptionsProviderInterface::PAGE_SIZE_B8,
PdfRenderingOptionsProviderInterface::PAGE_SIZE_B9,
PdfRenderingOptionsProviderInterface::PAGE_SIZE_B10,
PdfRenderingOptionsProviderInterface::PAGE_SIZE_C5E,
PdfRenderingOptionsProviderInterface::PAGE_SIZE_COMM_10_E,
PdfRenderingOptionsProviderInterface::PAGE_SIZE_DLE,
PdfRenderingOptionsProviderInterface::PAGE_SIZE_EXECUTIVE,
PdfRenderingOptionsProviderInterface::PAGE_SIZE_FOLIO,
PdfRenderingOptionsProviderInterface::PAGE_SIZE_LEDGER,
PdfRenderingOptionsProviderInterface::PAGE_SIZE_LEGAL,
PdfRenderingOptionsProviderInterface::PAGE_SIZE_LETTER,
PdfRenderingOptionsProviderInterface::PAGE_SIZE_TABLOID,
]);
}
}

0 comments on commit ee84d16

Please sign in to comment.