Skip to content

Commit

Permalink
Fix SF4.2 & Twig deprecations (#334)
Browse files Browse the repository at this point in the history
* Fix SF4.2 deprecation
* Fix Twig deprecation
* Improve travis
* Fix tests about DI
* Fix CS
* Update AutoFormBundle version
  • Loading branch information
webda2l authored Jun 28, 2019
1 parent 12ac14e commit 408b60f
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 24 deletions.
27 changes: 14 additions & 13 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
language: php

sudo: false
dist: trusty

cache:
directories:
Expand All @@ -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.
Expand All @@ -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;
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/DependencyInjection/Compiler/TemplatingPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/Form/EventListener/TranslationsFormsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
]
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Form/EventListener/TranslationsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
4 changes: 2 additions & 2 deletions src/Locale/SimpleProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}

Expand Down
2 changes: 1 addition & 1 deletion src/Resources/views/macros.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Example:
{% set locale = translationsFields.vars.name %}

<div id="{{ translationsFields.vars.id }}_a2lix_translations-fields" class="tab-pane {% if app.request.locale == locale %}show active{% endif %} {% if not form.vars.valid %}sonata-ba-field-error{% endif %}" role="tabpanel">
{% 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 %}
</div>
Expand Down
2 changes: 1 addition & 1 deletion tests/Form/TypeTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit 408b60f

Please sign in to comment.