22
33namespace ShipMonkTests \DoctrineEntityPreloader ;
44
5- use Doctrine \DBAL \ArrayParameterType ;
5+ use Doctrine \DBAL \Types \ Type as DbalType ;
66use Doctrine \ORM \Mapping \ClassMetadata ;
7+ use PHPUnit \Framework \Attributes \DataProvider ;
78use ShipMonkTests \DoctrineEntityPreloader \Fixtures \Blog \Article ;
89use ShipMonkTests \DoctrineEntityPreloader \Fixtures \Blog \Category ;
910use ShipMonkTests \DoctrineEntityPreloader \Lib \TestCase ;
1617class EntityPreloadBlogManyHasOneDeepTest extends TestCase
1718{
1819
19- public function testManyHasOneDeepUnoptimized (): void
20+ #[DataProvider('providePrimaryKeyTypes ' )]
21+ public function testManyHasOneDeepUnoptimized (DbalType $ primaryKey ): void
2022 {
21- $ this ->createDummyBlogData (categoryCount: 5 , categoryParentsCount: 5 , articleInEachCategoryCount: 5 );
23+ $ this ->createDummyBlogData ($ primaryKey , categoryCount: 5 , categoryParentsCount: 5 , articleInEachCategoryCount: 5 );
2224
2325 $ articles = $ this ->getEntityManager ()->getRepository (Article::class)->findAll ();
2426
@@ -30,33 +32,35 @@ public function testManyHasOneDeepUnoptimized(): void
3032 ]);
3133 }
3234
33- public function testManyHasOneDeepWithManualPreload (): void
35+ #[DataProvider('providePrimaryKeyTypes ' )]
36+ public function testManyHasOneDeepWithManualPreload (DbalType $ primaryKey ): void
3437 {
35- $ this ->createDummyBlogData (categoryCount: 5 , categoryParentsCount: 5 , articleInEachCategoryCount: 5 );
38+ $ this ->createDummyBlogData ($ primaryKey , categoryCount: 5 , categoryParentsCount: 5 , articleInEachCategoryCount: 5 );
3639
3740 $ articles = $ this ->getEntityManager ()->getRepository (Article::class)->findAll ();
41+ $ platform = $ this ->getEntityManager ()->getConnection ()->getDatabasePlatform ();
3842
39- $ categoryIds = array_map (static fn (Article $ article ) => $ article ->getCategory ()?->getId()-> getBytes ( ), $ articles );
43+ $ categoryIds = array_map (static fn (Article $ article ) => $ primaryKey -> convertToDatabaseValue ( $ article ->getCategory ()?->getId(), $ platform ), $ articles );
4044 $ categoryIds = array_filter ($ categoryIds , static fn (?string $ id ) => $ id !== null );
4145
4246 if (count ($ categoryIds ) > 0 ) {
4347 $ categories = $ this ->getEntityManager ()->createQueryBuilder ()
4448 ->select ('category ' )
4549 ->from (Category::class, 'category ' )
4650 ->where ('category.id IN (:ids) ' )
47- ->setParameter ('ids ' , array_values (array_unique ($ categoryIds )), ArrayParameterType:: BINARY )
51+ ->setParameter ('ids ' , array_values (array_unique ($ categoryIds )), $ this -> deduceArrayParameterType ( $ primaryKey ) )
4852 ->getQuery ()
4953 ->getResult ();
5054
51- $ parentCategoryIds = array_map (static fn (Category $ category ) => $ category ->getParent ()?->getId()-> getBytes ( ), $ categories );
55+ $ parentCategoryIds = array_map (static fn (Category $ category ) => $ primaryKey -> convertToDatabaseValue ( $ category ->getParent ()?->getId(), $ platform ), $ categories );
5256 $ parentCategoryIds = array_filter ($ parentCategoryIds , static fn (?string $ id ) => $ id !== null );
5357
5458 if (count ($ parentCategoryIds ) > 0 ) {
5559 $ this ->getEntityManager ()->createQueryBuilder ()
5660 ->select ('category ' )
5761 ->from (Category::class, 'category ' )
5862 ->where ('category.id IN (:ids) ' )
59- ->setParameter ('ids ' , array_values (array_unique ($ parentCategoryIds )), ArrayParameterType:: BINARY )
63+ ->setParameter ('ids ' , array_values (array_unique ($ parentCategoryIds )), $ this -> deduceArrayParameterType ( $ primaryKey ) )
6064 ->getQuery ()
6165 ->getResult ();
6266 }
@@ -70,9 +74,10 @@ public function testManyHasOneDeepWithManualPreload(): void
7074 ]);
7175 }
7276
73- public function testManyHasOneDeepWithFetchJoin (): void
77+ #[DataProvider('providePrimaryKeyTypes ' )]
78+ public function testManyHasOneDeepWithFetchJoin (DbalType $ primaryKey ): void
7479 {
75- $ this ->createDummyBlogData (categoryCount: 5 , categoryParentsCount: 5 , articleInEachCategoryCount: 5 );
80+ $ this ->createDummyBlogData ($ primaryKey , categoryCount: 5 , categoryParentsCount: 5 , articleInEachCategoryCount: 5 );
7681
7782 $ articles = $ this ->getEntityManager ()->createQueryBuilder ()
7883 ->select ('article ' , 'category ' , 'parentCategory ' )
@@ -89,10 +94,11 @@ public function testManyHasOneDeepWithFetchJoin(): void
8994 ]);
9095 }
9196
92- public function testManyHasOneDeepWithEagerFetchMode (): void
97+ #[DataProvider('providePrimaryKeyTypes ' )]
98+ public function testManyHasOneDeepWithEagerFetchMode (DbalType $ primaryKey ): void
9399 {
94100 $ this ->skipIfDoctrineOrmHasBrokenUnhandledMatchCase ();
95- $ this ->createDummyBlogData (categoryCount: 5 , categoryParentsCount: 5 , articleInEachCategoryCount: 5 );
101+ $ this ->createDummyBlogData ($ primaryKey , categoryCount: 5 , categoryParentsCount: 5 , articleInEachCategoryCount: 5 );
96102
97103 $ articles = $ this ->getEntityManager ()->createQueryBuilder ()
98104 ->select ('article ' )
@@ -111,9 +117,10 @@ public function testManyHasOneDeepWithEagerFetchMode(): void
111117 ]);
112118 }
113119
114- public function testManyHasOneDeepWithPreload (): void
120+ #[DataProvider('providePrimaryKeyTypes ' )]
121+ public function testManyHasOneDeepWithPreload (DbalType $ primaryKey ): void
115122 {
116- $ this ->createDummyBlogData (categoryCount: 5 , categoryParentsCount: 5 , articleInEachCategoryCount: 5 );
123+ $ this ->createDummyBlogData ($ primaryKey , categoryCount: 5 , categoryParentsCount: 5 , articleInEachCategoryCount: 5 );
117124
118125 $ articles = $ this ->getEntityManager ()->getRepository (Article::class)->findAll ();
119126 $ categories = $ this ->getEntityPreloader ()->preload ($ articles , 'category ' );
0 commit comments