From eb6efcefd8757ca83a5a95f96cf2436e6cd494e1 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Thu, 29 Sep 2022 19:12:10 +0200 Subject: [PATCH 1/2] Add new Abstract Aggregator Test to check qb aliases (for join clauses) --- .../Test/Export/AbstractAggregatorTest.php | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/Bundle/ChillMainBundle/Test/Export/AbstractAggregatorTest.php b/src/Bundle/ChillMainBundle/Test/Export/AbstractAggregatorTest.php index 40792a1c6..99ece6002 100644 --- a/src/Bundle/ChillMainBundle/Test/Export/AbstractAggregatorTest.php +++ b/src/Bundle/ChillMainBundle/Test/Export/AbstractAggregatorTest.php @@ -62,6 +62,18 @@ abstract class AbstractAggregatorTest extends KernelTestCase } } + /** + * provide data for `testAliasDidNotDisappears`. + */ + public function dataProviderAliasDidNotDisappears() + { + foreach ($this->getQueryBuilders() as $qb) { + foreach ($this->getFormData() as $data) { + yield [clone $qb, $data]; + } + } + } + /** * Create an aggregator instance which will be used in tests. * @@ -256,4 +268,29 @@ abstract class AbstractAggregatorTest extends KernelTestCase 'test that the title is not empty' ); } + + /** + * Compare aliases array before and after that aggregator alter query + * + * @dataProvider dataProviderAliasDidNotDisappears + * + * @param QueryBuilder $qb + * @param array $data + * @return void + */ + public function testAliasDidNotDisappears(QueryBuilder $qb, array $data) + { + $aliases = $qb->getAllAliases(); + + $this->getAggregator()->alterQuery($qb, $data); + + $alteredQuery = $qb->getAllAliases(); + + $this->assertGreaterThanOrEqual(count($aliases), count($alteredQuery)); + + foreach ($aliases as $alias) { + $this->assertContains($alias, $alteredQuery); + } + } + } From ccedebda9093e743a708cf4c843b26f2924cffae Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Thu, 29 Sep 2022 20:17:53 +0200 Subject: [PATCH 2/2] Add new Abstract Filter Test to check qb aliases (for join clauses) --- .../Test/Export/AbstractFilterTest.php | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/Bundle/ChillMainBundle/Test/Export/AbstractFilterTest.php b/src/Bundle/ChillMainBundle/Test/Export/AbstractFilterTest.php index 8e9761c67..91e6edd69 100644 --- a/src/Bundle/ChillMainBundle/Test/Export/AbstractFilterTest.php +++ b/src/Bundle/ChillMainBundle/Test/Export/AbstractFilterTest.php @@ -55,6 +55,18 @@ abstract class AbstractFilterTest extends KernelTestCase } } + /** + * provide data for `testAliasDidNotDisappears`. + */ + public function dataProviderAliasDidNotDisappears() + { + foreach ($this->getQueryBuilders() as $qb) { + foreach ($this->getFormData() as $data) { + yield [clone $qb, $data]; + } + } + } + /** * Create a filter which will be used in tests. * @@ -198,4 +210,28 @@ abstract class AbstractFilterTest extends KernelTestCase 'test that the title is not empty' ); } + + /** + * Compare aliases array before and after that filter alter query + * + * @dataProvider dataProviderAliasDidNotDisappears + * + * @param QueryBuilder $qb + * @param array $data + * @return void + */ + public function testAliasDidNotDisappears(QueryBuilder $qb, array $data) + { + $aliases = $qb->getAllAliases(); + + $this->getFilter()->alterQuery($qb, $data); + + $alteredQuery = $qb->getAllAliases(); + + $this->assertGreaterThanOrEqual(count($aliases), count($alteredQuery)); + + foreach ($aliases as $alias) { + $this->assertContains($alias, $alteredQuery); + } + } }