Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bigboss86 committed Sep 29, 2020
1 parent 25d1e83 commit d3e5b38
Show file tree
Hide file tree
Showing 30 changed files with 92 additions and 90 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@

/behat.yml
/phpspec.yml
/phpunit.xml
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion bin/behat

This file was deleted.

39 changes: 0 additions & 39 deletions bin/console

This file was deleted.

1 change: 0 additions & 1 deletion bin/doctrine

This file was deleted.

1 change: 0 additions & 1 deletion bin/doctrine-dbal

This file was deleted.

1 change: 0 additions & 1 deletion bin/doctrine-migrations

This file was deleted.

1 change: 0 additions & 1 deletion bin/ecs

This file was deleted.

1 change: 0 additions & 1 deletion bin/php-cs-fixer

This file was deleted.

1 change: 0 additions & 1 deletion bin/phpcbf

This file was deleted.

1 change: 0 additions & 1 deletion bin/phpcs

This file was deleted.

1 change: 0 additions & 1 deletion bin/phpspec

This file was deleted.

1 change: 0 additions & 1 deletion bin/phpstan

This file was deleted.

1 change: 0 additions & 1 deletion bin/phpstan.phar

This file was deleted.

1 change: 0 additions & 1 deletion bin/phpunit

This file was deleted.

1 change: 0 additions & 1 deletion bin/security-checker

This file was deleted.

1 change: 0 additions & 1 deletion bin/update-psl-icann-section

This file was deleted.

1 change: 0 additions & 1 deletion bin/upload-screenshots

This file was deleted.

1 change: 0 additions & 1 deletion bin/upload-textfiles

This file was deleted.

1 change: 0 additions & 1 deletion bin/var-dump-server

This file was deleted.

1 change: 0 additions & 1 deletion bin/wait-for-port

This file was deleted.

5 changes: 0 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,6 @@
"autoload-dev": {
"classmap": ["tests/Application/Kernel.php"]
},
"extra": {
"branch-alias": {
"dev-master": "1.8-dev"
}
},
"config": {
"sort-packages": true
},
Expand Down
68 changes: 56 additions & 12 deletions doc/tests.md
Original file line number Diff line number Diff line change
@@ -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`.

Expand All @@ -22,33 +24,75 @@ 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
- 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)
```
11 changes: 11 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,15 @@
<directory name="vendor" />
</ignoreFiles>
</projectFiles>

<issueHandlers>
<PropertyNotSetInConstructor errorLevel="info" />
<PossiblyNullArrayOffset errorLevel="info" />
<MixedAssignment errorLevel="info" />
<MixedArgument errorLevel="info" />
<DocblockTypeContradiction errorLevel="info" />
<MixedInferredReturnType errorLevel="info" />
<MixedReturnStatement errorLevel="info" />
<PossiblyNullArgument errorLevel="info" />
</issueHandlers>
</psalm>
8 changes: 2 additions & 6 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
15 changes: 12 additions & 3 deletions src/DependencyInjection/OdiseoSyliusVendorExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
6 changes: 4 additions & 2 deletions src/Form/Type/VendorType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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']);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Mapping/VendorAwareListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Repository/VendorRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions src/SitemapProvider/VendorUrlProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
Expand All @@ -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);
}

/**
Expand All @@ -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();
}
Expand Down

0 comments on commit d3e5b38

Please sign in to comment.