File tree Expand file tree Collapse file tree 5 files changed +117
-0
lines changed Expand file tree Collapse file tree 5 files changed +117
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php declare (strict_types = 1 );
2+
3+ namespace PHPStan \Type \Doctrine ;
4+
5+ use PHPStan \Testing \TypeInferenceTestCase ;
6+
7+ class QueryBuilderReproductionsTest extends TypeInferenceTestCase
8+ {
9+
10+ /**
11+ * @return iterable<mixed>
12+ */
13+ public function dataFileAsserts (): iterable
14+ {
15+ yield from $ this ->gatherAssertTypes (__DIR__ . '/data/queryBuilderReproductions.php ' );
16+ }
17+
18+ /**
19+ * @dataProvider dataFileAsserts
20+ * @param mixed ...$args
21+ */
22+ public function testFileAsserts (
23+ string $ assertType ,
24+ string $ file ,
25+ ...$ args
26+ ): void
27+ {
28+ $ this ->assertFileAsserts ($ assertType , $ file , ...$ args );
29+ }
30+
31+ public static function getAdditionalConfigFiles (): array
32+ {
33+ return [
34+ __DIR__ . '/data/QueryResult/config.neon ' ,
35+ ];
36+ }
37+
38+ }
Original file line number Diff line number Diff line change 1+ <?php declare (strict_types=1 );
2+
3+ namespace QueryResult \Entities ;
4+
5+ use Doctrine \ORM \Mapping as ORM ;
6+
7+ #[ORM \Entity]
8+ #[ORM \Table(name: 'orders ' )]
9+ class OrderItem
10+ {
11+
12+ #[ORM \Id]
13+ #[ORM \GeneratedValue]
14+ #[ORM \Column]
15+ private ?int $ id = null ;
16+
17+ #[ORM \ManyToOne]
18+ private Product $ product ;
19+
20+ }
Original file line number Diff line number Diff line change 1+ <?php declare (strict_types=1 );
2+
3+ namespace QueryResult \Entities ;
4+
5+ use Doctrine \ORM \Mapping as ORM ;
6+
7+ #[ORM \Entity]
8+ #[ORM \Table(name: 'products ' )]
9+ class Product
10+ {
11+
12+ #[ORM \Id]
13+ #[ORM \GeneratedValue]
14+ #[ORM \Column(options: ['unsigned ' => true ])]
15+ private ?int $ id = null ;
16+
17+ }
Original file line number Diff line number Diff line change 2222 [__DIR__ . '/Entities ' ]
2323), 'QueryResult\Entities \\' );
2424
25+ if (PHP_VERSION_ID >= 80100 ) {
26+ $ metadataDriver ->addDriver (
27+ new AttributeDriver ([__DIR__ . '/Entities ' ]),
28+ 'QueryResult\Entities \\'
29+ );
30+ }
31+
2532if (property_exists (Column::class, 'enumType ' ) && PHP_VERSION_ID >= 80100 ) {
2633 $ metadataDriver ->addDriver (new AnnotationDriver (
2734 new AnnotationReader (),
2835 [__DIR__ . '/EntitiesEnum ' ]
2936 ), 'QueryResult\EntitiesEnum \\' );
37+ $ metadataDriver ->addDriver (
38+ new AttributeDriver ([__DIR__ . '/EntitiesEnum ' ]),
39+ 'QueryResult\EntitiesEnum \\'
40+ );
3041}
3142
3243$ config ->setMetadataDriverImpl ($ metadataDriver );
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace QueryBuilderReproductions ;
4+
5+ use Doctrine \ORM \EntityManager ;
6+ use QueryResult \Entities \OrderItem ;
7+ use function PHPStan \Testing \assertType ;
8+
9+ class Foo
10+ {
11+
12+ /** @var EntityManager */
13+ private $ entityManager ;
14+
15+ public function __construct (EntityManager $ entityManager )
16+ {
17+ $ this ->entityManager = $ entityManager ;
18+ }
19+
20+ public function doFoo (): void
21+ {
22+ $ result = $ this ->entityManager ->createQueryBuilder ()
23+ ->select ('DISTINCT IDENTITY(oi.product) AS id ' )
24+ ->from (OrderItem::class, 'oi ' )
25+ ->join ('oi.product ' , 'p ' )
26+ ->getQuery ()
27+ ->getArrayResult ();
28+ assertType ('list<array{id: int}> ' , $ result );
29+ }
30+
31+ }
You can’t perform that action at this time.
0 commit comments