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); } } 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..7721b9212 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 ? $query->getDQLPart('where')->count() : 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" + ); } 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()); } /**