From d3e5b383e8fe7459d1451f92595da6780e248791 Mon Sep 17 00:00:00 2001 From: Damian Damico Date: Tue, 29 Sep 2020 15:52:33 -0300 Subject: [PATCH] fixes --- .gitignore | 1 + .travis.yml | 1 + bin/behat | 1 - bin/console | 39 ----------- bin/doctrine | 1 - bin/doctrine-dbal | 1 - bin/doctrine-migrations | 1 - bin/ecs | 1 - bin/php-cs-fixer | 1 - bin/phpcbf | 1 - bin/phpcs | 1 - bin/phpspec | 1 - bin/phpstan | 1 - bin/phpstan.phar | 1 - bin/phpunit | 1 - bin/security-checker | 1 - bin/update-psl-icann-section | 1 - bin/upload-screenshots | 1 - bin/upload-textfiles | 1 - bin/var-dump-server | 1 - bin/wait-for-port | 1 - composer.json | 5 -- doc/tests.md | 68 +++++++++++++++---- psalm.xml | 11 +++ src/DependencyInjection/Configuration.php | 8 +-- .../OdiseoSyliusVendorExtension.php | 15 +++- src/Form/Type/VendorType.php | 6 +- src/Mapping/VendorAwareListener.php | 2 +- src/Repository/VendorRepository.php | 2 +- src/SitemapProvider/VendorUrlProvider.php | 6 +- 30 files changed, 92 insertions(+), 90 deletions(-) delete mode 120000 bin/behat delete mode 100755 bin/console delete mode 120000 bin/doctrine delete mode 120000 bin/doctrine-dbal delete mode 120000 bin/doctrine-migrations delete mode 120000 bin/ecs delete mode 120000 bin/php-cs-fixer delete mode 120000 bin/phpcbf delete mode 120000 bin/phpcs delete mode 120000 bin/phpspec delete mode 120000 bin/phpstan delete mode 120000 bin/phpstan.phar delete mode 120000 bin/phpunit delete mode 120000 bin/security-checker delete mode 120000 bin/update-psl-icann-section delete mode 120000 bin/upload-screenshots delete mode 120000 bin/upload-textfiles delete mode 120000 bin/var-dump-server delete mode 120000 bin/wait-for-port diff --git a/.gitignore b/.gitignore index bf9fda4..0d105e4 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ /behat.yml /phpspec.yml +/phpunit.xml diff --git a/.travis.yml b/.travis.yml index 5b3c07d..79960cd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -68,6 +68,7 @@ script: - composer validate - vendor/bin/phpstan analyse -c phpstan.neon -l max src/ + - vendor/bin/psalm - vendor/bin/phpunit - vendor/bin/phpspec run diff --git a/bin/behat b/bin/behat deleted file mode 120000 index ec35dd9..0000000 --- a/bin/behat +++ /dev/null @@ -1 +0,0 @@ -../vendor/behat/behat/bin/behat \ No newline at end of file diff --git a/bin/console b/bin/console deleted file mode 100755 index 5187d02..0000000 --- a/bin/console +++ /dev/null @@ -1,39 +0,0 @@ -#!/usr/bin/env php -load(__DIR__.'/../.env'); -} - -$input = new ArgvInput(); -$env = $input->getParameterOption(['--env', '-e'], $_SERVER['APP_ENV'] ?? 'dev', true); -$debug = (bool) ($_SERVER['APP_DEBUG'] ?? ('prod' !== $env)) && !$input->hasParameterOption('--no-debug', true); - -if ($debug) { - umask(0000); - - if (class_exists(Debug::class)) { - Debug::enable(); - } -} - -$kernel = new Kernel($env, $debug); -$application = new Application($kernel); -$application->run($input); diff --git a/bin/doctrine b/bin/doctrine deleted file mode 120000 index 0f72e36..0000000 --- a/bin/doctrine +++ /dev/null @@ -1 +0,0 @@ -../vendor/doctrine/orm/bin/doctrine \ No newline at end of file diff --git a/bin/doctrine-dbal b/bin/doctrine-dbal deleted file mode 120000 index 110e93c..0000000 --- a/bin/doctrine-dbal +++ /dev/null @@ -1 +0,0 @@ -../vendor/doctrine/dbal/bin/doctrine-dbal \ No newline at end of file diff --git a/bin/doctrine-migrations b/bin/doctrine-migrations deleted file mode 120000 index 7184da7..0000000 --- a/bin/doctrine-migrations +++ /dev/null @@ -1 +0,0 @@ -../vendor/doctrine/migrations/bin/doctrine-migrations \ No newline at end of file diff --git a/bin/ecs b/bin/ecs deleted file mode 120000 index afb6582..0000000 --- a/bin/ecs +++ /dev/null @@ -1 +0,0 @@ -../vendor/symplify/easy-coding-standard/bin/ecs \ No newline at end of file diff --git a/bin/php-cs-fixer b/bin/php-cs-fixer deleted file mode 120000 index 4d77120..0000000 --- a/bin/php-cs-fixer +++ /dev/null @@ -1 +0,0 @@ -../vendor/friendsofphp/php-cs-fixer/php-cs-fixer \ No newline at end of file diff --git a/bin/phpcbf b/bin/phpcbf deleted file mode 120000 index 77c39e3..0000000 --- a/bin/phpcbf +++ /dev/null @@ -1 +0,0 @@ -../vendor/squizlabs/php_codesniffer/bin/phpcbf \ No newline at end of file diff --git a/bin/phpcs b/bin/phpcs deleted file mode 120000 index e6aa789..0000000 --- a/bin/phpcs +++ /dev/null @@ -1 +0,0 @@ -../vendor/squizlabs/php_codesniffer/bin/phpcs \ No newline at end of file diff --git a/bin/phpspec b/bin/phpspec deleted file mode 120000 index 22e0618..0000000 --- a/bin/phpspec +++ /dev/null @@ -1 +0,0 @@ -../vendor/phpspec/phpspec/bin/phpspec \ No newline at end of file diff --git a/bin/phpstan b/bin/phpstan deleted file mode 120000 index 3b74c80..0000000 --- a/bin/phpstan +++ /dev/null @@ -1 +0,0 @@ -../vendor/phpstan/phpstan-shim/phpstan \ No newline at end of file diff --git a/bin/phpstan.phar b/bin/phpstan.phar deleted file mode 120000 index eeb97c2..0000000 --- a/bin/phpstan.phar +++ /dev/null @@ -1 +0,0 @@ -../vendor/phpstan/phpstan-shim/phpstan.phar \ No newline at end of file diff --git a/bin/phpunit b/bin/phpunit deleted file mode 120000 index 4ba3256..0000000 --- a/bin/phpunit +++ /dev/null @@ -1 +0,0 @@ -../vendor/phpunit/phpunit/phpunit \ No newline at end of file diff --git a/bin/security-checker b/bin/security-checker deleted file mode 120000 index 85f6e8e..0000000 --- a/bin/security-checker +++ /dev/null @@ -1 +0,0 @@ -../vendor/sensiolabs/security-checker/security-checker \ No newline at end of file diff --git a/bin/update-psl-icann-section b/bin/update-psl-icann-section deleted file mode 120000 index cbae64c..0000000 --- a/bin/update-psl-icann-section +++ /dev/null @@ -1 +0,0 @@ -../vendor/league/uri-hostname-parser/bin/update-psl-icann-section \ No newline at end of file diff --git a/bin/upload-screenshots b/bin/upload-screenshots deleted file mode 120000 index 6f14941..0000000 --- a/bin/upload-screenshots +++ /dev/null @@ -1 +0,0 @@ -../vendor/lakion/mink-debug-extension/travis/tools/upload-screenshots \ No newline at end of file diff --git a/bin/upload-textfiles b/bin/upload-textfiles deleted file mode 120000 index af11830..0000000 --- a/bin/upload-textfiles +++ /dev/null @@ -1 +0,0 @@ -../vendor/lakion/mink-debug-extension/travis/tools/upload-textfiles \ No newline at end of file diff --git a/bin/var-dump-server b/bin/var-dump-server deleted file mode 120000 index 1ae6785..0000000 --- a/bin/var-dump-server +++ /dev/null @@ -1 +0,0 @@ -../vendor/symfony/var-dumper/Resources/bin/var-dump-server \ No newline at end of file diff --git a/bin/wait-for-port b/bin/wait-for-port deleted file mode 120000 index 5dd8a4c..0000000 --- a/bin/wait-for-port +++ /dev/null @@ -1 +0,0 @@ -../vendor/lakion/mink-debug-extension/travis/tools/wait-for-port \ No newline at end of file diff --git a/composer.json b/composer.json index 51cf62d..cb99a18 100644 --- a/composer.json +++ b/composer.json @@ -55,11 +55,6 @@ "autoload-dev": { "classmap": ["tests/Application/Kernel.php"] }, - "extra": { - "branch-alias": { - "dev-master": "1.8-dev" - } - }, "config": { "sort-packages": true }, diff --git a/doc/tests.md b/doc/tests.md index 03b1949..0136fd1 100644 --- a/doc/tests.md +++ b/doc/tests.md @@ -1,17 +1,19 @@ ## Test the plugin -We are using Behat, PHPSpec and PHPUnit to test this plugin. +We are using PHPStan, Psalm, Behat, PHPSpec and PHPUnit to test this plugin. ### How to run the tests From the plugin root directory, run the following commands: + ```bash $ (cd tests/Application && yarn install) $ (cd tests/Application && yarn build) - $ (cd tests/Application && bin/console assets:install public -e test) + $ (cd tests/Application && APP_ENV=test bin/console assets:install public) - $ (cd tests/Application && bin/console doctrine:database:create -e test) - $ (cd tests/Application && bin/console doctrine:schema:create -e test) + $ (cd tests/Application && APP_ENV=test bin/console doctrine:database:create) + $ (cd tests/Application && APP_ENV=test bin/console doctrine:schema:create) + ``` To be able to setup a plugin's database, remember to configure you database credentials in `tests/Application/.env` and `tests/Application/.env.test`. @@ -22,19 +24,61 @@ To be able to setup a plugin's database, remember to configure you database cred - PHPUnit ```bash - $ bin/phpunit + $ vendor/bin/phpunit ``` - PHPSpec ```bash - $ bin/phpspec run + $ vendor/bin/phpspec run + ``` + + - Behat (non-JS scenarios) + + ```bash + $ vendor/bin/behat --strict --tags="~@javascript" ``` - - Behat + - Behat (JS scenarios) + + 1. [Install Symfony CLI command](https://symfony.com/download). + + 2. Start Headless Chrome: + + ```bash + $ google-chrome-stable --enable-automation --disable-background-networking --no-default-browser-check --no-first-run --disable-popup-blocking --disable-default-apps --allow-insecure-localhost --disable-translate --disable-extensions --no-sandbox --enable-features=Metal --headless --remote-debugging-port=9222 --window-size=2880,1800 --proxy-server='direct://' --proxy-bypass-list='*' http://127.0.0.1 + ``` + + 3. Install SSL certificates (only once needed) and run test application's webserver on `127.0.0.1:8080`: + + ```bash + $ symfony server:ca:install APP_ENV=test symfony server:start --port=8080 --dir=tests/Application/public --daemon + ``` + + 4. Run Behat: + + ```bash + $ vendor/bin/behat --strict --tags="@javascript" + ``` + + - Static Analysis + + - Psalm + + ```bash + $ vendor/bin/psalm + ``` + + - PHPStan + + ```bash + $ vendor/bin/phpstan analyse -c phpstan.neon -l max src/ + ``` + + - Coding Standard ```bash - $ bin/behat + $ vendor/bin/ecs check src ``` ### Opening Sylius with this plugin @@ -42,13 +86,13 @@ To be able to setup a plugin's database, remember to configure you database cred - Using `test` environment: ```bash - $ (cd tests/Application && bin/console sylius:fixtures:load -e test) - $ (cd tests/Application && bin/console server:run -d public -e test) + $ (cd tests/Application && APP_ENV=test bin/console sylius:fixtures:load) + $ (cd tests/Application && APP_ENV=test bin/console server:run -d public) ``` - Using `dev` environment: ```bash - $ (cd tests/Application && bin/console sylius:fixtures:load -e dev) - $ (cd tests/Application && bin/console server:run -d public -e dev) + $ (cd tests/Application && APP_ENV=dev bin/console sylius:fixtures:load) + $ (cd tests/Application && APP_ENV=dev bin/console server:run -d public) ``` diff --git a/psalm.xml b/psalm.xml index 3240886..b9cad4c 100644 --- a/psalm.xml +++ b/psalm.xml @@ -12,4 +12,15 @@ + + + + + + + + + + + diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 3d27bce..e2c8d38 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -15,12 +15,8 @@ final class Configuration implements ConfigurationInterface public function getConfigTreeBuilder(): TreeBuilder { $treeBuilder = new TreeBuilder('odiseo_sylius_vendor_plugin'); - if (\method_exists($treeBuilder, 'getRootNode')) { - $rootNode = $treeBuilder->getRootNode(); - } else { - // BC layer for symfony/config 4.1 and older - $rootNode = $treeBuilder->root('odiseo_sylius_vendor_plugin'); - } + + $treeBuilder->getRootNode(); return $treeBuilder; } diff --git a/src/DependencyInjection/OdiseoSyliusVendorExtension.php b/src/DependencyInjection/OdiseoSyliusVendorExtension.php index fbf4b06..1f84020 100644 --- a/src/DependencyInjection/OdiseoSyliusVendorExtension.php +++ b/src/DependencyInjection/OdiseoSyliusVendorExtension.php @@ -4,22 +4,31 @@ namespace Odiseo\SyliusVendorPlugin\DependencyInjection; -use Sylius\Bundle\ResourceBundle\DependencyInjection\Extension\AbstractResourceExtension; +use Symfony\Component\Config\Definition\ConfigurationInterface; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Extension\Extension; use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; -final class OdiseoSyliusVendorExtension extends AbstractResourceExtension +final class OdiseoSyliusVendorExtension extends Extension { /** * {@inheritdoc} */ public function load(array $config, ContainerBuilder $container): void { - $config = $this->processConfiguration($this->getConfiguration([], $container), $config); + $this->processConfiguration($this->getConfiguration([], $container), $config); $loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); $loader->load('services.yaml'); } + + /** + * {@inheritdoc} + */ + public function getConfiguration(array $config, ContainerBuilder $container): ConfigurationInterface + { + return new Configuration(); + } } diff --git a/src/Form/Type/VendorType.php b/src/Form/Type/VendorType.php index ebd8741..6a67dd0 100644 --- a/src/Form/Type/VendorType.php +++ b/src/Form/Type/VendorType.php @@ -4,6 +4,7 @@ namespace Odiseo\SyliusVendorPlugin\Form\Type; +use Odiseo\SyliusVendorPlugin\Entity\VendorInterface; use Sylius\Bundle\ChannelBundle\Form\Type\ChannelChoiceType; use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType; use Sylius\Bundle\ResourceBundle\Form\Type\ResourceTranslationsType; @@ -70,10 +71,11 @@ public function configureOptions(OptionsResolver $resolver): void parent::configureOptions($resolver); $resolver->setDefaults([ - 'validation_groups' => function (FormInterface $form) { + 'validation_groups' => function (FormInterface $form): array { + /** @var VendorInterface|null $vendor */ $vendor = $form->getData(); - if (!$vendor || null === $vendor->getId()) { + if (!$vendor instanceof VendorInterface || null === $vendor->getId()) { return array_merge($this->validationGroups, ['odiseo_logo_create']); } diff --git a/src/Mapping/VendorAwareListener.php b/src/Mapping/VendorAwareListener.php index dfb2f5c..946623e 100644 --- a/src/Mapping/VendorAwareListener.php +++ b/src/Mapping/VendorAwareListener.php @@ -61,7 +61,7 @@ public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs): void $classMetadata = $eventArgs->getClassMetadata(); $reflection = $classMetadata->reflClass; - if (!$reflection instanceof \ReflectionClass || $reflection->isAbstract()) { + if ($reflection->isAbstract()) { return; } diff --git a/src/Repository/VendorRepository.php b/src/Repository/VendorRepository.php index bfd2a1f..693dd1d 100644 --- a/src/Repository/VendorRepository.php +++ b/src/Repository/VendorRepository.php @@ -21,7 +21,7 @@ public function findByEnabledQueryBuilder(?ChannelInterface $channel): QueryBuil ->setParameter('enabled', true) ; - if ($channel) { + if ($channel instanceof ChannelInterface) { $queryBuilder->innerJoin('v.channels', 'channel') ->andWhere('channel = :channel') ->setParameter('channel', $channel) diff --git a/src/SitemapProvider/VendorUrlProvider.php b/src/SitemapProvider/VendorUrlProvider.php index 6b2212b..9e2004c 100644 --- a/src/SitemapProvider/VendorUrlProvider.php +++ b/src/SitemapProvider/VendorUrlProvider.php @@ -80,7 +80,7 @@ public function generate(): iterable */ private function getTranslations(VendorInterface $vendor): Collection { - return $vendor->getTranslations()->filter(function (TranslationInterface $translation) { + return $vendor->getTranslations()->filter(function (TranslationInterface $translation): bool { return $this->localeInLocaleCodes($translation); }); } @@ -91,7 +91,7 @@ private function getTranslations(VendorInterface $vendor): Collection */ private function localeInLocaleCodes(TranslationInterface $translation): bool { - return in_array($translation->getLocale(), $this->getLocaleCodes()); + return in_array($translation->getLocale(), $this->getLocaleCodes(), true); } /** @@ -113,7 +113,7 @@ private function getLocaleCodes(): array /** @var ChannelInterface $channel */ $channel = $this->channelContext->getChannel(); - return $channel->getLocales()->map(function (LocaleInterface $locale) { + return $channel->getLocales()->map(function (LocaleInterface $locale): ?string { return $locale->getCode(); })->toArray(); }