Skip to content
This repository has been archived by the owner on Apr 19, 2022. It is now read-only.

Commit

Permalink
Fixed 5.1 compatibility (#6)
Browse files Browse the repository at this point in the history
* Fixed 5.1 compatibility

* Fixed Travis Config

* Fixed tests

* Remove deprecations
  • Loading branch information
yceruto authored Jul 30, 2020
1 parent b6351ab commit 5b38060
Show file tree
Hide file tree
Showing 14 changed files with 74 additions and 101 deletions.
11 changes: 5 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
language: php

addons:
chrome: stable

cache:
directories:
- .composer/cache/files
Expand All @@ -12,18 +9,18 @@ env:
global:
# needed to avoid some hard to fix deprecations
- SYMFONY_DEPRECATIONS_HELPER="8"
- CHROME_VERSION="80.0.3987.163-1"

matrix:
fast_finish: true
include:
# Minimum supported dependencies with the latest and oldest PHP version
- php: 7.3
- php: 7.4
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" SYMFONY_DEPRECATIONS_HELPER="2"
- php: 7.1
- php: 7.2
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" SYMFONY_DEPRECATIONS_HELPER="2"

# Test the latest stable release
- php: 7.1
- php: 7.2
- php: 7.3
- php: 7.4
Expand All @@ -37,6 +34,8 @@ matrix:
- env: STABILITY="dev"

before_install:
- wget --no-verbose -O /tmp/chrome.deb http://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/google-chrome-stable_${CHROME_VERSION}_amd64.deb
- sudo apt install -y /tmp/chrome.deb --allow-downgrades
- phpenv config-rm xdebug.ini
- if ! [ -z "$STABILITY" ]; then composer config minimum-stability ${STABILITY}; fi;

Expand Down
30 changes: 15 additions & 15 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,25 @@
}
],
"require": {
"php": "^7.1.3",
"php": ">=7.2.5",
"ext-json": "*",
"symfony/doctrine-bridge": "^3.4|^4.2|^5.0",
"symfony/form": "^3.4|^4.2|^5.0",
"symfony/framework-bundle": "^3.4|^4.2|^5.0",
"symfony/options-resolver": "^4.2|^5.0"
"symfony/doctrine-bridge": "^5.1",
"symfony/form": "^5.1.3",
"symfony/framework-bundle": "^5.1",
"symfony/options-resolver": "^5.1"
},
"require-dev": {
"doctrine/doctrine-bundle": "^1.10",
"doctrine/doctrine-fixtures-bundle": "^3.2",
"doctrine/orm": "^2.6.3",
"symfony/asset": "^3.4|^4.2|^5.0",
"symfony/dom-crawler": "^4.4",
"symfony/panther": "^0.4",
"symfony/phpunit-bridge": "^3.4|^4.2|^5.0",
"doctrine/doctrine-bundle": "^2.1",
"doctrine/doctrine-fixtures-bundle": "^3.3",
"doctrine/data-fixtures": "^1.4.1",
"doctrine/orm": "^2.7.3",
"symfony/asset": "^5.1",
"symfony/panther": "^0.7",
"symfony/phpunit-bridge": "^5.1",
"symfony/translation-contracts": "^1.1",
"symfony/twig-bundle": "^3.4|^4.2|^5.0",
"symfony/var-dumper": "^3.4|^4.2|^5.0",
"symfony/yaml": "^3.4|^4.2|^5.0"
"symfony/twig-bundle": "^5.1",
"symfony/var-dumper": "^5.1",
"symfony/yaml": "^5.1"
},
"config": {
"sort-packages": true
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/AbstractSearchAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

namespace Yceruto\Bundle\RichFormBundle\Controller;

use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\QueryBuilder;
use Doctrine\ORM\Tools\Pagination\Paginator;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Yceruto\Bundle\RichFormBundle\Exception\MissingOptionsException;
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Entity2SearchAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Yceruto\Bundle\RichFormBundle\Controller;

use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\ORM\Tools\Pagination\Paginator;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Bridge\Doctrine\Form\ChoiceList\IdReader;
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
use Yceruto\Bundle\RichFormBundle\Request\SearchOptions;
Expand Down
10 changes: 6 additions & 4 deletions src/Form/ChoiceList/Loader/Entity2LoaderDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function __construct(ChoiceLoaderInterface $decoratedLoader)
$this->decoratedLoader = $decoratedLoader;
}

public function loadChoiceList($value = null)
public function loadChoiceList(callable $value = null)
{
if (null !== $this->choiceList && $this->cached) {
return $this->choiceList;
Expand All @@ -31,7 +31,7 @@ public function loadChoiceList($value = null)
return $this->choiceList = new ArrayChoiceList($this->choices, $value);
}

public function loadChoicesForValues(array $values, $value = null): array
public function loadChoicesForValues(array $values, callable $value = null): array
{
if ($this->choices !== $choices = $this->decoratedLoader->loadChoicesForValues($values, $value)) {
$this->cached = false;
Expand All @@ -40,9 +40,11 @@ public function loadChoicesForValues(array $values, $value = null): array
return $this->choices = $choices;
}

public function loadValuesForChoices(array $choices, $value = null): array
public function loadValuesForChoices(array $choices, callable $value = null): array
{
if ([] === $values = $this->decoratedLoader->loadValuesForChoices($choices, $value)) {
$values = $this->decoratedLoader->loadValuesForChoices($choices, $value);

if ([] === $values || [''] === $values) {
$newChoices = [];
} else {
$newChoices = $choices;
Expand Down
12 changes: 1 addition & 11 deletions src/Form/Extension/Select2TypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,6 @@ public function configureOptions(OptionsResolver $resolver): void
]);
}

/**
* Symfony 3.4 Compatibility
*/
public function getExtendedType(): string
{
foreach (static::getExtendedTypes() as $extendedType) {
return $extendedType;
}
}

public static function getExtendedTypes(): iterable
{
return [Entity2Type::class];
Expand All @@ -125,7 +115,7 @@ protected function preselectData(array $choices, array $resultFields): void

/** @var ChoiceView $choiceView */
foreach ($resultFields as $fieldName => $fieldValuePath) {
$value = $this->propertyAccessor->getValue($choiceView->data, $fieldValuePath);
$value = $choiceView->data ? $this->propertyAccessor->getValue($choiceView->data, $fieldValuePath) : null;

if (\is_object($value)) {
$value = (string) $value;
Expand Down
21 changes: 0 additions & 21 deletions src/Form/Type/Entity2Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,10 @@
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\ChoiceList\Factory\CachingFactoryDecorator;
use Symfony\Component\Form\ChoiceList\LazyChoiceList;
use Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\OptionsResolver\Exception\InvalidArgumentException;
use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
use Symfony\Component\OptionsResolver\Options;
Expand All @@ -35,22 +30,6 @@ public function __construct(Session $session, array $globalOptions = [])
$this->globalOptions = $globalOptions;
}

public function buildForm(FormBuilderInterface $builder, array $options): void
{
if (Kernel::MAJOR_VERSION < 4) {
// Avoid caching in LazyChoiceList - Symfony 3.4
$builder->addEventListener(FormEvents::PRE_SUBMIT, static function (FormEvent $event) {
$choiceList = $event->getForm()->getConfig()->getAttribute('choice_list');
if ($choiceList instanceof LazyChoiceList) {
$loaded = (new \ReflectionObject($choiceList))->getProperty('loaded');
$loaded->setAccessible(true);
$loaded->setValue($choiceList, false);
$loaded->setAccessible(false);
}
});
}
}

public function buildView(FormView $view, FormInterface $form, array $options): void
{
$autocompleteOptions = [
Expand Down
8 changes: 4 additions & 4 deletions tests/Controller/Entity2SearchActionFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public function testNewProductWithSelect2SearchQuery(): void
// Check success
$client->waitFor('.product-list');
$this->assertCount(1, $crawler->filter('tbody > tr'));
$this->assertSame('Category 24', $crawler->filter('tbody > tr > td')->getElement(1)->getText());
$this->assertSame('Tag 11, Tag 20', $crawler->filter('tbody > tr > td')->getElement(2)->getText());
$this->assertSame('Category 24', $crawler->filter('tbody > tr > td')->getElement(2)->getText());
$this->assertSame('Tag 11, Tag 20', $crawler->filter('tbody > tr > td')->getElement(3)->getText());
}

public function testEditProductWithSelect2SearchQuery(): void
Expand Down Expand Up @@ -88,8 +88,8 @@ public function testEditProductWithSelect2SearchQuery(): void
// Check success
$client->waitFor('.product-list');
$this->assertCount(1, $crawler->filter('tbody > tr'));
$this->assertSame('Category 10', $crawler->filter('tbody > tr > td')->getElement(1)->getText());
$this->assertSame('Tag 20, Tag 32', $crawler->filter('tbody > tr > td')->getElement(2)->getText());
$this->assertSame('Category 10', $crawler->filter('tbody > tr > td')->getElement(2)->getText());
$this->assertSame('Tag 20, Tag 32', $crawler->filter('tbody > tr > td')->getElement(3)->getText());
}

public function testMaxResultsAndInfinityScroll(): void
Expand Down
Loading

0 comments on commit 5b38060

Please sign in to comment.