diff --git a/src/Bundle/ChillMainBundle/Test/Export/AbstractAggregatorTest.php b/src/Bundle/ChillMainBundle/Test/Export/AbstractAggregatorTest.php index 38f80200d..d3f2849b7 100644 --- a/src/Bundle/ChillMainBundle/Test/Export/AbstractAggregatorTest.php +++ b/src/Bundle/ChillMainBundle/Test/Export/AbstractAggregatorTest.php @@ -63,6 +63,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. * @@ -257,4 +269,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); + } + } + } diff --git a/src/Bundle/ChillMainBundle/Test/Export/AbstractFilterTest.php b/src/Bundle/ChillMainBundle/Test/Export/AbstractFilterTest.php index 88607e7d9..8e8220b89 100644 --- a/src/Bundle/ChillMainBundle/Test/Export/AbstractFilterTest.php +++ b/src/Bundle/ChillMainBundle/Test/Export/AbstractFilterTest.php @@ -56,6 +56,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. * @@ -199,4 +211,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); + } + } }