diff --git a/tests/DoctrineIntegration/ORM/EntityManagerIntegrationTest.php b/tests/DoctrineIntegration/ORM/EntityManagerIntegrationTest.php index 7ed4a32e..da9d731e 100644 --- a/tests/DoctrineIntegration/ORM/EntityManagerIntegrationTest.php +++ b/tests/DoctrineIntegration/ORM/EntityManagerIntegrationTest.php @@ -18,6 +18,7 @@ public function dataTopics(): array ['entityManagerMergeReturn'], ['customRepositoryUsage'], ['queryBuilder'], + ['queryBuilderExtraMethod'], ]; } diff --git a/tests/DoctrineIntegration/ORM/data/queryBuilderExtraMethod-4.json b/tests/DoctrineIntegration/ORM/data/queryBuilderExtraMethod-4.json new file mode 100644 index 00000000..0d4f101c --- /dev/null +++ b/tests/DoctrineIntegration/ORM/data/queryBuilderExtraMethod-4.json @@ -0,0 +1,2 @@ +[ +] diff --git a/tests/DoctrineIntegration/ORM/data/queryBuilderExtraMethod.php b/tests/DoctrineIntegration/ORM/data/queryBuilderExtraMethod.php new file mode 100644 index 00000000..94548336 --- /dev/null +++ b/tests/DoctrineIntegration/ORM/data/queryBuilderExtraMethod.php @@ -0,0 +1,49 @@ +entityManager = $entityManager; + } + + public function doFoo(): Query + { + $queryBuilder = $this->entityManager->createQueryBuilder() + ->select('e') + ->from(MyEntity::class, 'e'); + + // @todo it works when the extra where is here + //$queryBuilder->andWhere('e.id != :excludedId'); + + // but it does not work when the where is added in extra method + $this->addExtraCondition($queryBuilder); + + $query = $queryBuilder->getQuery(); + + $expectedDql = 'SELECT e FROM PHPStan\DoctrineIntegration\ORM\CustomRepositoryUsage\MyEntity e WHERE e.id != :excludedId'; + $query->getDQL() === $expectedDql; + $queryBuilder->getDQL() === $expectedDql; + + return $query; + } + + private function addExtraCondition(QueryBuilder $queryBuilder): void + { + $queryBuilder->andWhere('e.id != :excludedId'); + } + +}