From 7b4c7285233983277a04b747a1d79fcfa0c841a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Wed, 4 Apr 2018 17:00:57 +0200 Subject: [PATCH 1/4] fix countable in php 7.2 in PHP 7.2, count does not allow null value or not countable object. This commit adapt the use of count to the nature of the object --- Test/Export/AbstractAggregatorTest.php | 4 ++-- Test/Export/AbstractFilterTest.php | 30 ++++++++++++++++++-------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/Test/Export/AbstractAggregatorTest.php b/Test/Export/AbstractAggregatorTest.php index a1f0cf60a..d33a6f88d 100644 --- a/Test/Export/AbstractAggregatorTest.php +++ b/Test/Export/AbstractAggregatorTest.php @@ -213,7 +213,7 @@ abstract class AbstractAggregatorTest extends KernelTestCase $nbOfFrom = $query->getDQLPart('from') !== null ? count($query->getDQLPart('from')) : 0; $nbOfWhere = $query->getDQLPart('where') !== null ? - count($query->getDQLPart('where')) : 0; + $query->getDQLPart('where')->count() : 0; $nbOfSelect = $query->getDQLPart('select') !== null ? count($query->getDQLPart('select')) : 0; @@ -226,7 +226,7 @@ abstract class AbstractAggregatorTest extends KernelTestCase altered the query"); $this->assertGreaterThanOrEqual( $nbOfWhere, - $query->getDQLPart('where') !== null ? count($query->getDQLPart('where')) : 0, + $query->getDQLPart('where') !== null ? $query->getDQLPart('where')->count() : 0, "Test that there are equal or more 'where' clause after that the filter has" . "altered the query"); $this->assertGreaterThanOrEqual( diff --git a/Test/Export/AbstractFilterTest.php b/Test/Export/AbstractFilterTest.php index c16bfb8c0..dd8f5df04 100644 --- a/Test/Export/AbstractFilterTest.php +++ b/Test/Export/AbstractFilterTest.php @@ -104,20 +104,32 @@ abstract class AbstractFilterTest extends KernelTestCase public function testAlterQuery(QueryBuilder $query, $data) { // retains informations about query - $nbOfFrom = count($query->getDQLPart('from')); - $nbOfWhere = count($query->getDQLPart('where')); - $nbOfSelect = count($query->getDQLPart('select')); + $nbOfFrom = $query->getDQLPart('from') !== null ? + count($query->getDQLPart('from')) : 0; + $nbOfWhere = $query->getDQLPart('where') !== null ? + $query->getDQLPart('where')->count() : 0; + $nbOfSelect = $query->getDQLPart('select') !== null ? + count($query->getDQLPart('select')) : 0; $this->getFilter()->alterQuery($query, $data); - $this->assertGreaterThanOrEqual($nbOfFrom, count($query->getDQLPart('from')), + $this->assertGreaterThanOrEqual( + $nbOfFrom, + $query->getDQLPart('from') !== null ? count($query->getDQLPart('from')) : 0, "Test that there are equal or more 'from' clause after that the filter has - altered the query"); - $this->assertGreaterThanOrEqual($nbOfWhere, count($query->getDQLPart('where')), + altered the query" + ); + $this->assertGreaterThanOrEqual( + $nbOfWhere, + $query->getDQLPart('where') !== null ? count($query->getDQLPart('where')) : 0, "Test that there are equal or more 'where' clause after that the filter has" - . "altered the query"); - $this->assertEquals($nbOfSelect, count($query->getDQLPart('select')), - "Test that the filter has no altered the 'select' part of the query"); + . "altered the query" + ); + $this->assertEquals( + $nbOfSelect, + $query->getDQLPart('select') !== null ? count($query->getDQLPart('select')) : 0, + "Test that the filter has no altered the 'select' part of the query" + ); } From a3e6b625b592d37d502b294c1a49581a41b633de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Wed, 4 Apr 2018 17:23:25 +0200 Subject: [PATCH 2/4] fix missing count statement --- Test/Export/AbstractFilterTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Test/Export/AbstractFilterTest.php b/Test/Export/AbstractFilterTest.php index dd8f5df04..7721b9212 100644 --- a/Test/Export/AbstractFilterTest.php +++ b/Test/Export/AbstractFilterTest.php @@ -121,7 +121,7 @@ abstract class AbstractFilterTest extends KernelTestCase ); $this->assertGreaterThanOrEqual( $nbOfWhere, - $query->getDQLPart('where') !== null ? count($query->getDQLPart('where')) : 0, + $query->getDQLPart('where') !== null ? $query->getDQLPart('where')->count() : 0, "Test that there are equal or more 'where' clause after that the filter has" . "altered the query" ); From bce6916837332b6c93cc81739db686ad356a872b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Wed, 4 Apr 2018 21:43:51 +0200 Subject: [PATCH 3/4] use fqdn in CenterType --- Form/Type/CenterType.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Form/Type/CenterType.php b/Form/Type/CenterType.php index e226c77ca..41db8dc98 100644 --- a/Form/Type/CenterType.php +++ b/Form/Type/CenterType.php @@ -25,6 +25,8 @@ use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage; use Chill\MainBundle\Entity\Center; use Chill\MainBundle\Form\Type\DataTransformer\CenterTransformer; +use Symfony\Component\Form\Extension\Core\Type\HiddenType; +use Symfony\Bridge\Doctrine\Form\Type\EntityType; /** * @@ -78,9 +80,9 @@ class CenterType extends AbstractType throw new \RuntimeException("The user is not associated with " . "any center. Associate user with a center"); } elseif ($nbReachableCenters === 1) { - return 'hidden'; + return HiddenType::class; } else { - return 'entity'; + return EntityType::class; } } @@ -93,7 +95,8 @@ class CenterType extends AbstractType public function configureOptions(OptionsResolver $resolver) { if (count($this->reachableCenters) > 1) { - $resolver->setDefault('class', 'Chill\MainBundle\Entity\Center'); + $resolver->setDefault('class', Center::class); + $resolver->setDefault('choices', $this->reachableCenters); } } @@ -105,7 +108,7 @@ class CenterType extends AbstractType */ public function buildForm(FormBuilderInterface $builder, array $options) { - if ($this->getParent() === 'hidden') { + if ($this->getParent() === HiddenType::class) { $builder->addModelTransformer($this->transformer); } } From 7be5a95ab9ac5ac73a0ba04d7a40fda6661a49b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Wed, 4 Apr 2018 21:54:28 +0200 Subject: [PATCH 4/4] fix test for CenterType (use fqdn in tests) --- Tests/Form/Type/CenterTypeTest.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Tests/Form/Type/CenterTypeTest.php b/Tests/Form/Type/CenterTypeTest.php index 8c3d2f290..48b96375e 100644 --- a/Tests/Form/Type/CenterTypeTest.php +++ b/Tests/Form/Type/CenterTypeTest.php @@ -23,6 +23,8 @@ use Symfony\Component\Form\Test\TypeTestCase; use Chill\MainBundle\Form\Type\CenterType; use Chill\MainBundle\Entity\User; use Chill\MainBundle\Entity\GroupCenter; +use Symfony\Component\Form\Extension\Core\Type\HiddenType; +use Symfony\Bridge\Doctrine\Form\Type\EntityType; /** @@ -48,7 +50,7 @@ class CenterTypeTest extends TypeTestCase $type = $this->prepareType($user); - $this->assertEquals('hidden', $type->getParent()); + $this->assertEquals(HiddenType::class, $type->getParent()); } /** @@ -71,7 +73,7 @@ class CenterTypeTest extends TypeTestCase $type = $this->prepareType($user); - $this->assertEquals('hidden', $type->getParent()); + $this->assertEquals(HiddenType::class, $type->getParent()); } /** @@ -96,7 +98,7 @@ class CenterTypeTest extends TypeTestCase $type = $this->prepareType($user); - $this->assertEquals('entity', $type->getParent()); + $this->assertEquals(EntityType::class, $type->getParent()); } /**