Skip to content

Commit 2d216f4

Browse files
committed
Skip tests broken by ORM bug and add one working testcase for each
1 parent 7dc8e39 commit 2d216f4

8 files changed

+91
-2
lines changed

tests/EntityPreloadBlogManyHasOneDeepTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ public function testManyHasOneDeepWithFetchJoin(DbalType $primaryKey): void
9898
public function testManyHasOneDeepWithEagerFetchMode(DbalType $primaryKey): void
9999
{
100100
$this->skipIfDoctrineOrmHasBrokenUnhandledMatchCase();
101+
$this->skipIfDoctrineOrmHasBrokenEagerFetch($primaryKey);
101102
$this->createDummyBlogData($primaryKey, categoryCount: 5, categoryParentsCount: 5, articleInEachCategoryCount: 5);
102103

103104
$articles = $this->getEntityManager()->createQueryBuilder()

tests/EntityPreloadBlogManyHasOneTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ public function testManyHasOneWithFetchJoin(DbalType $primaryKey): void
8484
public function testManyHasOneWithEagerFetchMode(DbalType $primaryKey): void
8585
{
8686
$this->skipIfDoctrineOrmHasBrokenUnhandledMatchCase();
87+
$this->skipIfDoctrineOrmHasBrokenEagerFetch($primaryKey);
8788
$this->createDummyBlogData($primaryKey, categoryCount: 5, articleInEachCategoryCount: 5);
8889

8990
$articles = $this->getEntityManager()->createQueryBuilder()

tests/EntityPreloadBlogOneHasManyAbstractTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public function testOneHasManyAbstractWithFetchJoin(DbalType $primaryKey): void
5252
public function testOneHasManyAbstractWithEagerFetchMode(DbalType $primaryKey): void
5353
{
5454
$this->skipIfDoctrineOrmHasBrokenUnhandledMatchCase();
55+
$this->skipIfDoctrineOrmHasBrokenEagerFetch($primaryKey);
5556
$this->createDummyBlogData($primaryKey, categoryCount: 1, articleInEachCategoryCount: 5, commentForEachArticleCount: 5);
5657

5758
$articles = $this->getEntityManager()->createQueryBuilder()

tests/EntityPreloadBlogOneHasManyDeepTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ public function testOneHasManyDeepWithFetchJoin(DbalType $primaryKey): void
104104
public function testOneHasManyDeepWithEagerFetchMode(DbalType $primaryKey): void
105105
{
106106
$this->skipIfDoctrineOrmHasBrokenUnhandledMatchCase();
107+
$this->skipIfDoctrineOrmHasBrokenEagerFetch($primaryKey);
107108
$this->createCategoryTree($primaryKey, depth: 5, branchingFactor: 5);
108109

109110
$rootCategories = $this->getEntityManager()->createQueryBuilder()

tests/EntityPreloadBlogOneHasManyTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ public function testOneHasManyWithFetchJoin(DbalType $primaryKey): void
105105
public function testOneHasManyWithEagerFetchMode(DbalType $primaryKey): void
106106
{
107107
$this->skipIfDoctrineOrmHasBrokenUnhandledMatchCase();
108+
$this->skipIfDoctrineOrmHasBrokenEagerFetch($primaryKey); // here the test it green, but emits PHP warning
108109
$this->createDummyBlogData($primaryKey, categoryCount: 5, articleInEachCategoryCount: 5);
109110

110111
$categories = $this->getEntityManager()->createQueryBuilder()

tests/Fixtures/Blog/PrimaryKey.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace ShipMonkTests\DoctrineEntityPreloader\Fixtures\Blog;
44

5-
use function md5;
5+
use function base64_encode;
66
use function random_int;
77

88
class PrimaryKey
@@ -33,7 +33,7 @@ public function getData(): int
3333

3434
public function __toString(): string
3535
{
36-
return md5((string) $this->data); // intentionally not matching any internal PK representation
36+
return base64_encode((string) $this->data); // intentionally not matching any internal PK representation
3737
}
3838

3939
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace ShipMonkTests\DoctrineEntityPreloader\Fixtures\Blog\Type;
4+
5+
use Doctrine\DBAL\ParameterType;
6+
use Doctrine\DBAL\Platforms\AbstractPlatform;
7+
use Doctrine\DBAL\Types\Type;
8+
use LogicException;
9+
use ShipMonkTests\DoctrineEntityPreloader\Fixtures\Blog\PrimaryKey;
10+
use ShipMonkTests\DoctrineEntityPreloader\Fixtures\Compat\CompatibilityType;
11+
use function base64_decode;
12+
use function base64_encode;
13+
use function get_debug_type;
14+
use function is_string;
15+
16+
/**
17+
* This type exists only to have SOME working version of tests that are failing due to ORM bug https://github.com/doctrine/orm/pull/12130
18+
* - the key feature here is that convertToDatabaseValue return value equals to PrimaryKey::__toString()
19+
*/
20+
final class PrimaryKeyBase64StringType extends Type
21+
{
22+
23+
use CompatibilityType;
24+
25+
public function convertToPHPValue(
26+
mixed $value,
27+
AbstractPlatform $platform,
28+
): ?PrimaryKey
29+
{
30+
if ($value === null) {
31+
return null;
32+
}
33+
34+
if (is_string($value)) {
35+
return new PrimaryKey((int) base64_decode($value, true));
36+
}
37+
38+
throw new LogicException('Unexpected value: ' . get_debug_type($value));
39+
}
40+
41+
public function convertToDatabaseValue(
42+
mixed $value,
43+
AbstractPlatform $platform,
44+
): ?string
45+
{
46+
if ($value === null) {
47+
return null;
48+
49+
} elseif ($value instanceof PrimaryKey) {
50+
return base64_encode((string) $value->getData());
51+
52+
} else {
53+
throw new LogicException('Unexpected value: ' . $value);
54+
}
55+
}
56+
57+
public function getSQLDeclaration(
58+
array $column,
59+
AbstractPlatform $platform,
60+
): string
61+
{
62+
return $platform->getStringTypeDeclarationSQL([]);
63+
}
64+
65+
public function getName(): string
66+
{
67+
return PrimaryKey::DOCTRINE_TYPE_NAME;
68+
}
69+
70+
public function doGetBindingType(): ParameterType|int // @phpstan-ignore return.unusedType (old dbal compat)
71+
{
72+
return ParameterType::STRING;
73+
}
74+
75+
}

tests/Lib/TestCase.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use ShipMonkTests\DoctrineEntityPreloader\Fixtures\Blog\Comment;
2828
use ShipMonkTests\DoctrineEntityPreloader\Fixtures\Blog\PrimaryKey;
2929
use ShipMonkTests\DoctrineEntityPreloader\Fixtures\Blog\Tag;
30+
use ShipMonkTests\DoctrineEntityPreloader\Fixtures\Blog\Type\PrimaryKeyBase64StringType;
3031
use ShipMonkTests\DoctrineEntityPreloader\Fixtures\Blog\Type\PrimaryKeyBinaryType;
3132
use ShipMonkTests\DoctrineEntityPreloader\Fixtures\Blog\Type\PrimaryKeyIntegerType;
3233
use ShipMonkTests\DoctrineEntityPreloader\Fixtures\Blog\Type\PrimaryKeyStringType;
@@ -55,6 +56,7 @@ public static function providePrimaryKeyTypes(): iterable
5556
yield 'binary' => [new PrimaryKeyBinaryType()];
5657
yield 'string' => [new PrimaryKeyStringType()];
5758
yield 'integer' => [new PrimaryKeyIntegerType()];
59+
yield 'base64string' => [new PrimaryKeyBase64StringType()];
5860
}
5961

6062
protected function setUp(): void
@@ -293,6 +295,13 @@ protected function skipIfDoctrineOrmHasBrokenUnhandledMatchCase(): void
293295
}
294296
}
295297

298+
protected function skipIfDoctrineOrmHasBrokenEagerFetch(DbalType $primaryKey): void
299+
{
300+
if (!$primaryKey instanceof PrimaryKeyBase64StringType) {
301+
self::markTestSkipped('Unable to run test due to https://github.com/doctrine/orm/pull/12130');
302+
}
303+
}
304+
296305
protected function initializeEntityManager(
297306
DbalType $primaryKey,
298307
QueryLogger $queryLogger,

0 commit comments

Comments
 (0)