From 408b60f21865e188743e0097f100ad50ae4b4522 Mon Sep 17 00:00:00 2001 From: David ALLIX Date: Sat, 29 Jun 2019 01:22:07 +0200 Subject: [PATCH] Fix SF4.2 & Twig deprecations (#334) * Fix SF4.2 deprecation * Fix Twig deprecation * Improve travis * Fix tests about DI * Fix CS * Update AutoFormBundle version --- .travis.yml | 27 ++++++++++--------- composer.json | 4 +-- .../Compiler/TemplatingPass.php | 2 +- src/DependencyInjection/Configuration.php | 4 +-- .../TranslationsFormsListener.php | 2 +- .../EventListener/TranslationsListener.php | 2 +- src/Locale/SimpleProvider.php | 4 +-- src/Resources/views/macros.html.twig | 2 +- tests/Form/TypeTestCase.php | 2 +- 9 files changed, 25 insertions(+), 24 deletions(-) diff --git a/.travis.yml b/.travis.yml index 33b4be0..5e8cd18 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,6 @@ language: php sudo: false -dist: trusty cache: directories: @@ -19,22 +18,26 @@ matrix: fast_finish: true include: # Minimum supported dependencies with the latest and oldest PHP version - - php: 7.1 - env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" SYMFONY_DEPRECATIONS_HELPER="weak_vendors" - php: 7.2 - env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" SYMFONY_DEPRECATIONS_HELPER="weak_vendors" + env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" SYMFONY_DEPRECATIONS_HELPER="max[self]=0" + - php: 7.3 + env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" SYMFONY_DEPRECATIONS_HELPER="max[self]=0" # Test the latest stable release - - php: 7.1 - php: 7.2 + - php: 7.3 env: CHECK_PHP_SYNTAX="true" - # Latest commit to master + # # Test LTS versions. This makes sure we do not use Symfony packages with version greater + # # than 2 or 3 respectively. Read more at https://github.com/symfony/lts + # - php: 7.2 + # env: DEPENDENCIES="symfony/lts:^2" + # - php: 7.2 + # env: DEPENDENCIES="symfony/lts:^3" + + # Latest commit to master - php: 7.2 env: STABILITY="dev" - - - php: 7.3 - env: STABILITY="dev" allow_failures: # dev-master is allowed to fail. @@ -46,14 +49,12 @@ before_install: - if ! [ -v "$DEPENDENCIES" ]; then composer require --no-update ${DEPENDENCIES}; fi; install: - # To be removed when this issue will be resolved: https://github.com/composer/composer/issues/5355 - - if [[ "$COMPOSER_FLAGS" == *"--prefer-lowest"* ]]; then composer update --prefer-dist --no-interaction --prefer-stable --quiet; fi - composer update ${COMPOSER_FLAGS} --prefer-dist --no-interaction # Force most recent version of PHPUnit - - SYMFONY_PHPUNIT_VERSION=6.5 ./vendor/bin/simple-phpunit install + - ./vendor/bin/simple-phpunit install script: - composer validate --strict --no-check-lock # Force most recent version of PHPUnit - - SYMFONY_PHPUNIT_VERSION=6.5 ./vendor/bin/simple-phpunit $PHPUNIT_FLAGS + - ./vendor/bin/simple-phpunit $PHPUNIT_FLAGS - if [[ "$CHECK_PHP_SYNTAX" == "true" ]]; then php ./vendor/bin/php-cs-fixer fix --no-interaction --dry-run --diff -v; fi; diff --git a/composer.json b/composer.json index 3058284..e490a31 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,7 @@ ], "require": { "php": "^7.1.3", - "a2lix/auto-form-bundle": "^0.1", + "a2lix/auto-form-bundle": "^0.2", "symfony/config": "^3.4|^4.0", "symfony/dependency-injection": "^3.4|^4.0", "symfony/doctrine-bridge": "^3.4|^4.0", @@ -41,7 +41,7 @@ "doctrine/orm": "^2.4", "friendsofphp/php-cs-fixer": "^2.10", "knplabs/doctrine-behaviors": "^1.4", - "matthiasnoback/symfony-dependency-injection-test": "^2.0", + "matthiasnoback/symfony-dependency-injection-test": "^3.0", "symfony/phpunit-bridge": "^4.0", "symfony/validator": "^3.4|^4.0", "vimeo/psalm": "^1.0" diff --git a/src/DependencyInjection/Compiler/TemplatingPass.php b/src/DependencyInjection/Compiler/TemplatingPass.php index 19b509e..bb9887d 100644 --- a/src/DependencyInjection/Compiler/TemplatingPass.php +++ b/src/DependencyInjection/Compiler/TemplatingPass.php @@ -23,7 +23,7 @@ public function process(ContainerBuilder $container): void if (false !== ($template = $container->getParameter('a2lix_translation_form.templating'))) { $resources = $container->getParameter('twig.form.resources'); - if (in_array($template, $resources, true)) { + if (\in_array($template, $resources, true)) { return; } diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index e5646ec..d3102b8 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -21,8 +21,8 @@ class Configuration implements ConfigurationInterface { public function getConfigTreeBuilder(): TreeBuilder { - $treeBuilder = new TreeBuilder(); - $rootNode = $treeBuilder->root('a2lix_translation_form'); + $treeBuilder = new TreeBuilder('a2lix_translation_form'); + $rootNode = method_exists(TreeBuilder::class, 'getRootNode') ? $treeBuilder->getRootNode() : $treeBuilder->root('a2lix_translation_form'); $rootNode ->children() diff --git a/src/Form/EventListener/TranslationsFormsListener.php b/src/Form/EventListener/TranslationsFormsListener.php index 51e2ad4..aa4e1fd 100644 --- a/src/Form/EventListener/TranslationsFormsListener.php +++ b/src/Form/EventListener/TranslationsFormsListener.php @@ -35,7 +35,7 @@ public function preSetData(FormEvent $event): void foreach ($formOptions['locales'] as $locale) { $form->add($locale, $formOptions['form_type'], $formOptions['form_options'] + [ - 'required' => in_array($locale, $formOptions['required_locales'], true), + 'required' => \in_array($locale, $formOptions['required_locales'], true), ] ); } diff --git a/src/Form/EventListener/TranslationsListener.php b/src/Form/EventListener/TranslationsListener.php index 23e9cdb..60034be 100644 --- a/src/Form/EventListener/TranslationsListener.php +++ b/src/Form/EventListener/TranslationsListener.php @@ -57,7 +57,7 @@ public function preSetData(FormEvent $event): void $form->add($locale, AutoFormType::class, [ 'data_class' => $translationClass, - 'required' => in_array($locale, $formOptions['required_locales'], true), + 'required' => \in_array($locale, $formOptions['required_locales'], true), 'block_name' => ('field' === $formOptions['theming_granularity']) ? 'locale' : null, 'fields' => $fieldsOptions[$locale], 'excluded_fields' => $formOptions['excluded_fields'], diff --git a/src/Locale/SimpleProvider.php b/src/Locale/SimpleProvider.php index a982e32..b4e97df 100644 --- a/src/Locale/SimpleProvider.php +++ b/src/Locale/SimpleProvider.php @@ -24,8 +24,8 @@ class SimpleProvider implements LocaleProviderInterface public function __construct(array $locales, string $defaultLocale, array $requiredLocales = []) { - if (!in_array($defaultLocale, $locales, true)) { - if (count($locales)) { + if (!\in_array($defaultLocale, $locales, true)) { + if (\count($locales)) { throw new \InvalidArgumentException(sprintf('Default locale `%s` not found within the configured locales `[%s]`. Perhaps you need to add it to your `a2lix_translation_form.locales` bundle configuration?', $defaultLocale, implode(',', $locales))); } diff --git a/src/Resources/views/macros.html.twig b/src/Resources/views/macros.html.twig index 4e4e512..be0da66 100644 --- a/src/Resources/views/macros.html.twig +++ b/src/Resources/views/macros.html.twig @@ -30,7 +30,7 @@ Example: {% set locale = translationsFields.vars.name %}
- {% for translationsField in translationsFields if translationsField.vars.name in fieldsNames %} + {% for translationsField in translationsFields|filter(translationsField => translationsField.vars.name in fieldsNames) %} {{ form_row(translationsField) }} {% endfor %}
diff --git a/tests/Form/TypeTestCase.php b/tests/Form/TypeTestCase.php index 0afe385..e332dd9 100644 --- a/tests/Form/TypeTestCase.php +++ b/tests/Form/TypeTestCase.php @@ -44,7 +44,7 @@ protected function setUp(): void $validator = $this->getMockBuilder(ValidatorInterface::class) ->disableOriginalConstructor() ->getMock(); - $validator->method('validate')->will($this->returnValue(new ConstraintViolationList())); + $validator->method('validate')->willReturn(new ConstraintViolationList()); $this->factory = Forms::createFormFactoryBuilder() ->addExtensions($this->getExtensions())