diff --git a/tests/Form/Filter/Type/ArrayFilterTypeTest.php b/tests/Form/Filter/Type/ArrayFilterTypeTest.php index f19b9971a5..f8010275fd 100644 --- a/tests/Form/Filter/Type/ArrayFilterTypeTest.php +++ b/tests/Form/Filter/Type/ArrayFilterTypeTest.php @@ -26,7 +26,7 @@ public function testSubmitAndFilter($submittedData, $data, array $options, strin $filter->filter($this->qb, $form, ['property' => 'foo', 'dataType' => 'array']); $this->assertSame(static::FILTER_TYPE, \get_class($filter)); $this->assertSame($dql, $this->qb->getDQL()); - $this->assertEquals($params, $this->qb->getParameters()->toArray()); + $this->assertSameDoctrineParams($params, $this->qb->getParameters()->toArray()); } public function getDataProvider(): iterable @@ -36,7 +36,7 @@ public function getDataProvider(): iterable ['comparison' => 'like', 'value' => ['bar']], [], 'SELECT o FROM Object o WHERE o.foo like :foo_1', - [new Parameter('foo_1', '%"bar"%', \PDO::PARAM_STR)], + [new Parameter('foo_1', '%"bar"%')], ]; yield [ @@ -45,8 +45,8 @@ public function getDataProvider(): iterable [], 'SELECT o FROM Object o WHERE o.foo not like :foo_1 OR o.foo not like :foo_2 OR o.foo IS NULL', [ - new Parameter('foo_1', '%"foo"%', \PDO::PARAM_STR), - new Parameter('foo_2', '%"bar"%', \PDO::PARAM_STR), + new Parameter('foo_1', '%"foo"%'), + new Parameter('foo_2', '%"bar"%'), ], ]; @@ -79,7 +79,7 @@ public function getDataProvider(): iterable ], ], 'SELECT o FROM Object o WHERE o.foo like :foo_1', - [new Parameter('foo_1', '%"b"%', \PDO::PARAM_STR)], + [new Parameter('foo_1', '%"b"%')], ]; yield [ @@ -93,8 +93,8 @@ public function getDataProvider(): iterable ], 'SELECT o FROM Object o WHERE o.foo not like :foo_1 OR o.foo not like :foo_2 OR o.foo IS NULL', [ - new Parameter('foo_1', '%"a"%', \PDO::PARAM_STR), - new Parameter('foo_2', '%"c"%', \PDO::PARAM_STR), + new Parameter('foo_1', '%"a"%'), + new Parameter('foo_2', '%"c"%'), ], ]; } diff --git a/tests/Form/Filter/Type/BooleanFilterTypeTest.php b/tests/Form/Filter/Type/BooleanFilterTypeTest.php index 3d2c9e0f3e..54023d262f 100644 --- a/tests/Form/Filter/Type/BooleanFilterTypeTest.php +++ b/tests/Form/Filter/Type/BooleanFilterTypeTest.php @@ -25,7 +25,7 @@ public function testSubmitAndFilter($submittedData, $data, string $dql, array $p $filter->filter($this->qb, $form, ['property' => 'foo']); $this->assertSame(static::FILTER_TYPE, \get_class($filter)); $this->assertSame($dql, $this->qb->getDQL()); - $this->assertEquals($params, $this->qb->getParameters()->toArray()); + $this->assertSameDoctrineParams($params, $this->qb->getParameters()->toArray()); } public function getDataProvider(): iterable diff --git a/tests/Form/Filter/Type/ChoiceFilterTypeTest.php b/tests/Form/Filter/Type/ChoiceFilterTypeTest.php index 8ecf23ac4a..935d6d0d66 100644 --- a/tests/Form/Filter/Type/ChoiceFilterTypeTest.php +++ b/tests/Form/Filter/Type/ChoiceFilterTypeTest.php @@ -27,7 +27,7 @@ public function testSubmitAndFilter($submittedData, $data, array $options, strin $filter->filter($this->qb, $form, ['property' => 'foo']); $this->assertSame(static::FILTER_TYPE, \get_class($filter)); $this->assertSame($dql, $this->qb->getDQL()); - $this->assertEquals($params, $this->qb->getParameters()->toArray()); + $this->assertSameDoctrineParams($params, $this->qb->getParameters()->toArray()); } public function getDataProvider(): iterable diff --git a/tests/Form/Filter/Type/ComparisonFilterTypeTest.php b/tests/Form/Filter/Type/ComparisonFilterTypeTest.php index bf08198aa8..e1435759af 100644 --- a/tests/Form/Filter/Type/ComparisonFilterTypeTest.php +++ b/tests/Form/Filter/Type/ComparisonFilterTypeTest.php @@ -31,7 +31,7 @@ public function testSubmitAndFilter($submittedData, $data, $options, string $dql $filter->filter($this->qb, $form, ['property' => 'foo']); $this->assertSame(static::FILTER_TYPE, \get_class($filter)); $this->assertSame($dql, $this->qb->getDQL()); - $this->assertEquals($params, $this->qb->getParameters()->toArray()); + $this->assertSameDoctrineParams($params, $this->qb->getParameters()->toArray()); } public function getDataProvider(): iterable diff --git a/tests/Form/Filter/Type/DateTimeFilterTypeTest.php b/tests/Form/Filter/Type/DateTimeFilterTypeTest.php index fda1d93085..a0a1090d73 100644 --- a/tests/Form/Filter/Type/DateTimeFilterTypeTest.php +++ b/tests/Form/Filter/Type/DateTimeFilterTypeTest.php @@ -29,7 +29,7 @@ public function testSubmitAndFilter($submittedData, $data, $options, string $dql $filter->filter($this->qb, $form, ['property' => 'foo']); $this->assertSame(static::FILTER_TYPE, \get_class($filter)); $this->assertSame($dql, $this->qb->getDQL()); - $this->assertEquals($params, $this->qb->getParameters()->toArray()); + $this->assertSameDoctrineParams($params, $this->qb->getParameters()->toArray()); } else { $this->assertSame($expectedError, $form->getTransformationFailure()->getMessage()); } diff --git a/tests/Form/Filter/Type/EntityFilterTypeTest.php b/tests/Form/Filter/Type/EntityFilterTypeTest.php index 654da1ed70..d15acc815a 100644 --- a/tests/Form/Filter/Type/EntityFilterTypeTest.php +++ b/tests/Form/Filter/Type/EntityFilterTypeTest.php @@ -73,7 +73,7 @@ public function testSubmitAndFilterToOneAssociationType($submittedData, $data, a $filter->filter($this->qb, $form, ['property' => 'foo', 'dataType' => 'association', 'associationType' => ClassMetadata::TO_ONE]); $this->assertSame(static::FILTER_TYPE, \get_class($filter)); $this->assertSame($dql, $this->qb->getDQL()); - $this->assertEquals($params, $this->qb->getParameters()->toArray()); + $this->assertSameDoctrineParams($params, $this->qb->getParameters()->toArray()); } /** @@ -95,7 +95,7 @@ public function testFilterToManyAssociationType($submittedData, $data, array $op $filter->filter($this->qb, $form, ['property' => 'foo', 'dataType' => 'association', 'associationType' => ClassMetadata::TO_MANY]); $this->assertSame(static::FILTER_TYPE, \get_class($filter)); $this->assertSame($dql, $this->qb->getDQL()); - $this->assertEquals($params, $this->qb->getParameters()->toArray()); + $this->assertSameDoctrineParams($params, $this->qb->getParameters()->toArray()); } public function getDataProviderToOneAssoc(): iterable diff --git a/tests/Form/Filter/Type/FilterTypeTest.php b/tests/Form/Filter/Type/FilterTypeTest.php index 969c5b1e40..36e567151c 100644 --- a/tests/Form/Filter/Type/FilterTypeTest.php +++ b/tests/Form/Filter/Type/FilterTypeTest.php @@ -5,6 +5,7 @@ use Doctrine\ORM\QueryBuilder; use EasyCorp\Bundle\EasyAdminBundle\Form\Filter\FilterRegistry; use EasyCorp\Bundle\EasyAdminBundle\Form\Filter\Type\ComparisonFilterType; +use PHPUnit\Framework\AssertionFailedError; use Symfony\Bridge\Doctrine\Test\DoctrineTestHelper; use Symfony\Component\Form\Test\TypeTestCase; @@ -38,4 +39,43 @@ protected function createQueryBuilder(): QueryBuilder return $qb; } + + // this is needed because some Doctrine versions changed some internals + // and we can't use this code: $this->assertEquals($params, $this->qb->getParameters()->toArray()); + // (see https://github.com/doctrine/orm/pull/7528) + protected function assertSameDoctrineParams(array $expectedParams, array $actualParams) + { + for ($i = 0; $i < \count($expectedParams); ++$i) { + $expectedParam = $expectedParams[$i]; + $actualParam = $actualParams[$i]; + + $namesAreDifferent = $expectedParam->getName() !== $actualParam->getName(); + $typesAreDifferent = $expectedParam->getType() !== $actualParam->getType(); + + $expectedValue = $expectedParam->getValue(); + $actualValue = $actualParam->getValue(); + if ($expectedValue instanceof \DateInterval) { + $valuesAreDifferent = !$this->dateIntervalsAreEqual($expectedValue, $actualValue); + } elseif (\is_object($expectedValue)) { + $valuesAreDifferent = $expectedParam->getValue() != $actualParam->getValue(); + } else { + $valuesAreDifferent = $expectedParam->getValue() !== $actualParam->getValue(); + } + + if ($namesAreDifferent || $valuesAreDifferent || $typesAreDifferent) { + throw new AssertionFailedError(sprintf('The "%s" and "%s" Doctrine parameters are not the same.', $expectedParam->getName(), $actualParam->getName())); + } + } + } + + private function dateIntervalsAreEqual(\DateInterval $a, \DateInterval $b): bool + { + $startDate1 = date_create(); + $startDate2 = clone $startDate1; + + $endDate1 = $startDate1->add($a); + $endDate2 = $startDate2->add($b); + + return $endDate1 == $endDate2; + } } diff --git a/tests/Form/Filter/Type/NumericFilterTypeTest.php b/tests/Form/Filter/Type/NumericFilterTypeTest.php index 73c922eada..b08221bbbb 100644 --- a/tests/Form/Filter/Type/NumericFilterTypeTest.php +++ b/tests/Form/Filter/Type/NumericFilterTypeTest.php @@ -28,7 +28,7 @@ public function testSubmitAndFilter($submittedData, $data, $options, string $dql $filter->filter($this->qb, $form, ['property' => 'foo']); $this->assertSame(static::FILTER_TYPE, \get_class($filter)); $this->assertSame($dql, $this->qb->getDQL()); - $this->assertEquals($params, $this->qb->getParameters()->toArray()); + $this->assertSameDoctrineParams($params, $this->qb->getParameters()->toArray()); } else { $this->assertSame($expectedError, $form->getTransformationFailure()->getMessage()); } diff --git a/tests/Form/Filter/Type/TextFilterTypeTest.php b/tests/Form/Filter/Type/TextFilterTypeTest.php index 7115bf015f..a1071fbcaf 100644 --- a/tests/Form/Filter/Type/TextFilterTypeTest.php +++ b/tests/Form/Filter/Type/TextFilterTypeTest.php @@ -25,7 +25,7 @@ public function testSubmitAndFilter($submittedData, $data, string $dql, array $p $filter->filter($this->qb, $form, ['property' => 'foo']); $this->assertSame(ComparisonFilterType::class, \get_class($filter)); $this->assertSame($dql, $this->qb->getDQL()); - $this->assertEquals($params, $this->qb->getParameters()->toArray()); + $this->assertSameDoctrineParams($params, $this->qb->getParameters()->toArray()); } public function getDataProvider(): iterable