Skip to content

Commit 408b60f

Browse files
authored
Fix SF4.2 & Twig deprecations (#334)
* Fix SF4.2 deprecation * Fix Twig deprecation * Improve travis * Fix tests about DI * Fix CS * Update AutoFormBundle version
1 parent 12ac14e commit 408b60f

File tree

9 files changed

+25
-24
lines changed

9 files changed

+25
-24
lines changed

.travis.yml

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
language: php
22

33
sudo: false
4-
dist: trusty
54

65
cache:
76
directories:
@@ -19,22 +18,26 @@ matrix:
1918
fast_finish: true
2019
include:
2120
# Minimum supported dependencies with the latest and oldest PHP version
22-
- php: 7.1
23-
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" SYMFONY_DEPRECATIONS_HELPER="weak_vendors"
2421
- php: 7.2
25-
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" SYMFONY_DEPRECATIONS_HELPER="weak_vendors"
22+
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" SYMFONY_DEPRECATIONS_HELPER="max[self]=0"
23+
- php: 7.3
24+
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" SYMFONY_DEPRECATIONS_HELPER="max[self]=0"
2625

2726
# Test the latest stable release
28-
- php: 7.1
2927
- php: 7.2
28+
- php: 7.3
3029
env: CHECK_PHP_SYNTAX="true"
3130

32-
# Latest commit to master
31+
# # Test LTS versions. This makes sure we do not use Symfony packages with version greater
32+
# # than 2 or 3 respectively. Read more at https://github.com/symfony/lts
33+
# - php: 7.2
34+
# env: DEPENDENCIES="symfony/lts:^2"
35+
# - php: 7.2
36+
# env: DEPENDENCIES="symfony/lts:^3"
37+
38+
# Latest commit to master
3339
- php: 7.2
3440
env: STABILITY="dev"
35-
36-
- php: 7.3
37-
env: STABILITY="dev"
3841

3942
allow_failures:
4043
# dev-master is allowed to fail.
@@ -46,14 +49,12 @@ before_install:
4649
- if ! [ -v "$DEPENDENCIES" ]; then composer require --no-update ${DEPENDENCIES}; fi;
4750

4851
install:
49-
# To be removed when this issue will be resolved: https://github.com/composer/composer/issues/5355
50-
- if [[ "$COMPOSER_FLAGS" == *"--prefer-lowest"* ]]; then composer update --prefer-dist --no-interaction --prefer-stable --quiet; fi
5152
- composer update ${COMPOSER_FLAGS} --prefer-dist --no-interaction
5253
# Force most recent version of PHPUnit
53-
- SYMFONY_PHPUNIT_VERSION=6.5 ./vendor/bin/simple-phpunit install
54+
- ./vendor/bin/simple-phpunit install
5455

5556
script:
5657
- composer validate --strict --no-check-lock
5758
# Force most recent version of PHPUnit
58-
- SYMFONY_PHPUNIT_VERSION=6.5 ./vendor/bin/simple-phpunit $PHPUNIT_FLAGS
59+
- ./vendor/bin/simple-phpunit $PHPUNIT_FLAGS
5960
- if [[ "$CHECK_PHP_SYNTAX" == "true" ]]; then php ./vendor/bin/php-cs-fixer fix --no-interaction --dry-run --diff -v; fi;

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
],
2828
"require": {
2929
"php": "^7.1.3",
30-
"a2lix/auto-form-bundle": "^0.1",
30+
"a2lix/auto-form-bundle": "^0.2",
3131
"symfony/config": "^3.4|^4.0",
3232
"symfony/dependency-injection": "^3.4|^4.0",
3333
"symfony/doctrine-bridge": "^3.4|^4.0",
@@ -41,7 +41,7 @@
4141
"doctrine/orm": "^2.4",
4242
"friendsofphp/php-cs-fixer": "^2.10",
4343
"knplabs/doctrine-behaviors": "^1.4",
44-
"matthiasnoback/symfony-dependency-injection-test": "^2.0",
44+
"matthiasnoback/symfony-dependency-injection-test": "^3.0",
4545
"symfony/phpunit-bridge": "^4.0",
4646
"symfony/validator": "^3.4|^4.0",
4747
"vimeo/psalm": "^1.0"

src/DependencyInjection/Compiler/TemplatingPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function process(ContainerBuilder $container): void
2323
if (false !== ($template = $container->getParameter('a2lix_translation_form.templating'))) {
2424
$resources = $container->getParameter('twig.form.resources');
2525

26-
if (in_array($template, $resources, true)) {
26+
if (\in_array($template, $resources, true)) {
2727
return;
2828
}
2929

src/DependencyInjection/Configuration.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ class Configuration implements ConfigurationInterface
2121
{
2222
public function getConfigTreeBuilder(): TreeBuilder
2323
{
24-
$treeBuilder = new TreeBuilder();
25-
$rootNode = $treeBuilder->root('a2lix_translation_form');
24+
$treeBuilder = new TreeBuilder('a2lix_translation_form');
25+
$rootNode = method_exists(TreeBuilder::class, 'getRootNode') ? $treeBuilder->getRootNode() : $treeBuilder->root('a2lix_translation_form');
2626

2727
$rootNode
2828
->children()

src/Form/EventListener/TranslationsFormsListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function preSetData(FormEvent $event): void
3535
foreach ($formOptions['locales'] as $locale) {
3636
$form->add($locale, $formOptions['form_type'],
3737
$formOptions['form_options'] + [
38-
'required' => in_array($locale, $formOptions['required_locales'], true),
38+
'required' => \in_array($locale, $formOptions['required_locales'], true),
3939
]
4040
);
4141
}

src/Form/EventListener/TranslationsListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function preSetData(FormEvent $event): void
5757

5858
$form->add($locale, AutoFormType::class, [
5959
'data_class' => $translationClass,
60-
'required' => in_array($locale, $formOptions['required_locales'], true),
60+
'required' => \in_array($locale, $formOptions['required_locales'], true),
6161
'block_name' => ('field' === $formOptions['theming_granularity']) ? 'locale' : null,
6262
'fields' => $fieldsOptions[$locale],
6363
'excluded_fields' => $formOptions['excluded_fields'],

src/Locale/SimpleProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ class SimpleProvider implements LocaleProviderInterface
2424

2525
public function __construct(array $locales, string $defaultLocale, array $requiredLocales = [])
2626
{
27-
if (!in_array($defaultLocale, $locales, true)) {
28-
if (count($locales)) {
27+
if (!\in_array($defaultLocale, $locales, true)) {
28+
if (\count($locales)) {
2929
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)));
3030
}
3131

src/Resources/views/macros.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Example:
3030
{% set locale = translationsFields.vars.name %}
3131

3232
<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">
33-
{% for translationsField in translationsFields if translationsField.vars.name in fieldsNames %}
33+
{% for translationsField in translationsFields|filter(translationsField => translationsField.vars.name in fieldsNames) %}
3434
{{ form_row(translationsField) }}
3535
{% endfor %}
3636
</div>

tests/Form/TypeTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ protected function setUp(): void
4444
$validator = $this->getMockBuilder(ValidatorInterface::class)
4545
->disableOriginalConstructor()
4646
->getMock();
47-
$validator->method('validate')->will($this->returnValue(new ConstraintViolationList()));
47+
$validator->method('validate')->willReturn(new ConstraintViolationList());
4848

4949
$this->factory = Forms::createFormFactoryBuilder()
5050
->addExtensions($this->getExtensions())

0 commit comments

Comments
 (0)