Skip to content

Commit fab790b

Browse files
committed
Fixed EntityTestCase related tests
1 parent d56856f commit fab790b

File tree

6 files changed

+136
-65
lines changed

6 files changed

+136
-65
lines changed

tests/Integration/Entity/DateDimensionTest.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
use App\Tests\Integration\TestCase\EntityTestCase;
1313
use App\Tests\Utils\PhpUnitUtil;
1414
use DateTimeImmutable;
15+
use Doctrine\ORM\Mapping\AssociationMapping;
16+
use Doctrine\ORM\Mapping\FieldMapping;
1517
use Override;
1618
use PHPUnit\Framework\Attributes\DataProvider;
1719
use PHPUnit\Framework\Attributes\TestDox;
@@ -41,7 +43,7 @@ class DateDimensionTest extends EntityTestCase
4143
public function testThatSetterOnlyAcceptSpecifiedType(
4244
?string $property = null,
4345
?string $type = null,
44-
?array $meta = null,
46+
FieldMapping|AssociationMapping|null $meta,
4547
): void {
4648
self::markTestSkipped('There is not setter in read only entity...');
4749
}
@@ -55,7 +57,7 @@ public function testThatSetterOnlyAcceptSpecifiedType(
5557
public function testThatSetterReturnsInstanceOfEntity(
5658
?string $property = null,
5759
?string $type = null,
58-
?array $meta = null
60+
FieldMapping|AssociationMapping|null $meta = null
5961
): void {
6062
self::markTestSkipped('There is not setter in read only entity...');
6163
}
@@ -67,8 +69,11 @@ public function testThatSetterReturnsInstanceOfEntity(
6769
#[DataProvider('dataProviderTestThatSetterAndGettersWorks')]
6870
#[TestDox('Test that getter method for `$type $property` property returns expected')]
6971
#[Override]
70-
public function testThatGetterReturnsExpectedValue(string $property, string $type, array $meta): void
71-
{
72+
public function testThatGetterReturnsExpectedValue(
73+
string $property,
74+
string $type,
75+
FieldMapping|AssociationMapping|null $meta,
76+
): void {
7277
$getter = 'get' . ucfirst($property);
7378

7479
if (in_array($type, [PhpUnitUtil::TYPE_BOOL, PhpUnitUtil::TYPE_BOOLEAN], true)) {

tests/Integration/Entity/LogLoginFailureTest.php

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@
1212
use App\Entity\User;
1313
use App\Tests\Integration\TestCase\EntityTestCase;
1414
use Doctrine\Common\Collections\ArrayCollection;
15+
use Doctrine\ORM\Mapping\AssociationMapping;
16+
use Doctrine\ORM\Mapping\FieldMapping;
1517
use Override;
1618
use PHPUnit\Framework\Attributes\DataProvider;
1719
use PHPUnit\Framework\Attributes\TestDox;
1820
use Throwable;
19-
use function array_key_exists;
21+
use function method_exists;
2022
use function ucfirst;
2123

2224
/**
@@ -41,7 +43,7 @@ class LogLoginFailureTest extends EntityTestCase
4143
public function testThatSetterOnlyAcceptSpecifiedType(
4244
?string $property = null,
4345
?string $type = null,
44-
?array $meta = null
46+
FieldMapping|AssociationMapping|null $meta = null
4547
): void {
4648
self::markTestSkipped('There is not setter in read only entity...');
4749
}
@@ -55,7 +57,7 @@ public function testThatSetterOnlyAcceptSpecifiedType(
5557
public function testThatSetterReturnsInstanceOfEntity(
5658
?string $property = null,
5759
?string $type = null,
58-
?array $meta = null
60+
FieldMapping|AssociationMapping|null $meta = null
5961
): void {
6062
self::markTestSkipped('There is not setter in read only entity...');
6163
}
@@ -67,19 +69,25 @@ public function testThatSetterReturnsInstanceOfEntity(
6769
#[DataProvider('dataProviderTestThatSetterAndGettersWorks')]
6870
#[TestDox('Test that getter method for `$type $property` property returns expected')]
6971
#[Override]
70-
public function testThatGetterReturnsExpectedValue(string $property, string $type, array $meta): void
71-
{
72+
public function testThatGetterReturnsExpectedValue(
73+
string $property,
74+
string $type,
75+
FieldMapping|AssociationMapping|null $meta,
76+
): void {
7277
$getter = 'get' . ucfirst($property);
7378

7479
if ($type === 'boolean') {
7580
$getter = 'is' . ucfirst($property);
7681
}
7782

78-
$logRequest = new LogLoginFailure(
79-
new User()
80-
);
83+
$logRequest = new LogLoginFailure(new User());
8184

82-
if (!(array_key_exists('columnName', $meta) || array_key_exists('joinColumns', $meta))) {
85+
if (method_exists($meta, 'isManyToManyOwningSide')
86+
&& (
87+
$meta->isManyToManyOwningSide()
88+
|| $meta->isOneToMany()
89+
)
90+
) {
8391
$type = ArrayCollection::class;
8492

8593
self::assertInstanceOf($type, $logRequest->{$getter}());

tests/Integration/Entity/LogLoginTest.php

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@
1515
use App\Tests\Utils\PhpUnitUtil;
1616
use DeviceDetector\DeviceDetector;
1717
use Doctrine\Common\Collections\ArrayCollection;
18+
use Doctrine\ORM\Mapping\AssociationMapping;
19+
use Doctrine\ORM\Mapping\FieldMapping;
1820
use Override;
1921
use PHPUnit\Framework\Attributes\DataProvider;
2022
use PHPUnit\Framework\Attributes\TestDox;
2123
use Symfony\Component\HttpFoundation\Request;
2224
use Throwable;
23-
use function array_key_exists;
25+
use function method_exists;
2426
use function in_array;
2527
use function ucfirst;
2628

@@ -44,9 +46,9 @@ class LogLoginTest extends EntityTestCase
4446
#[TestDox('No setter for `$property` property in read only entity - so cannot test this')]
4547
#[Override]
4648
public function testThatSetterOnlyAcceptSpecifiedType(
47-
?string $property = null,
48-
?string $type = null,
49-
?array $meta = null
49+
string $property,
50+
string $type,
51+
FieldMapping|AssociationMapping $meta,
5052
): void {
5153
self::markTestSkipped('There is not setter in read only entity...');
5254
}
@@ -58,9 +60,9 @@ public function testThatSetterOnlyAcceptSpecifiedType(
5860
#[TestDox('No setter for `$property` property in read only entity - so cannot test this')]
5961
#[Override]
6062
public function testThatSetterReturnsInstanceOfEntity(
61-
?string $property = null,
62-
?string $type = null,
63-
?array $meta = null
63+
string $property,
64+
string $type,
65+
FieldMapping|AssociationMapping $meta,
6466
): void {
6567
self::markTestSkipped('There is not setter in read only entity...');
6668
}
@@ -72,8 +74,11 @@ public function testThatSetterReturnsInstanceOfEntity(
7274
#[DataProvider('dataProviderTestThatSetterAndGettersWorks')]
7375
#[TestDox('Test that getter method for `$type $property` property returns expected')]
7476
#[Override]
75-
public function testThatGetterReturnsExpectedValue(string $property, string $type, array $meta): void
76-
{
77+
public function testThatGetterReturnsExpectedValue(
78+
string $property,
79+
string $type,
80+
FieldMapping|AssociationMapping $meta,
81+
): void {
7782
$getter = 'get' . ucfirst($property);
7883

7984
if (in_array($type, [PhpUnitUtil::TYPE_BOOL, PhpUnitUtil::TYPE_BOOLEAN], true)) {
@@ -93,7 +98,12 @@ public function testThatGetterReturnsExpectedValue(string $property, string $typ
9398
new User(),
9499
);
95100

96-
if (!(array_key_exists('columnName', $meta) || array_key_exists('joinColumns', $meta))) {
101+
if (method_exists($meta, 'isManyToManyOwningSide')
102+
&& (
103+
$meta->isManyToManyOwningSide()
104+
|| $meta->isOneToMany()
105+
)
106+
) {
97107
$type = ArrayCollection::class;
98108

99109
self::assertInstanceOf($type, $logRequest->{$getter}());

tests/Integration/Entity/LogRequestTest.php

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@
1515
use App\Tests\Utils\PhpUnitUtil;
1616
use App\Tests\Utils\StringableArrayObject;
1717
use Doctrine\Common\Collections\ArrayCollection;
18+
use Doctrine\ORM\Mapping\AssociationMapping;
19+
use Doctrine\ORM\Mapping\FieldMapping;
1820
use Generator;
1921
use Override;
2022
use PHPUnit\Framework\Attributes\DataProvider;
2123
use PHPUnit\Framework\Attributes\TestDox;
2224
use Symfony\Component\HttpFoundation\Request;
2325
use Symfony\Component\HttpFoundation\Response;
2426
use Throwable;
25-
use function array_key_exists;
27+
use function method_exists;
2628
use function in_array;
2729
use function is_array;
2830
use function is_object;
@@ -49,9 +51,9 @@ class LogRequestTest extends EntityTestCase
4951
#[TestDox('No setter for `$property` property in read only entity - so cannot test this')]
5052
#[Override]
5153
public function testThatSetterOnlyAcceptSpecifiedType(
52-
?string $property = null,
53-
?string $type = null,
54-
?array $meta = null
54+
string $property,
55+
string $type,
56+
FieldMapping|AssociationMapping $meta,
5557
): void {
5658
self::markTestSkipped('There is not setter in read only entity...');
5759
}
@@ -63,9 +65,9 @@ public function testThatSetterOnlyAcceptSpecifiedType(
6365
#[TestDox('No setter for `$property` property in read only entity - so cannot test this')]
6466
#[Override]
6567
public function testThatSetterReturnsInstanceOfEntity(
66-
?string $property = null,
67-
?string $type = null,
68-
?array $meta = null
68+
string $property,
69+
string $type,
70+
FieldMapping|AssociationMapping $meta,
6971
): void {
7072
self::markTestSkipped('There is not setter in read only entity...');
7173
}
@@ -77,8 +79,11 @@ public function testThatSetterReturnsInstanceOfEntity(
7779
#[DataProvider('dataProviderTestThatSetterAndGettersWorks')]
7880
#[TestDox('Test that getter method for `$type $property` returns expected')]
7981
#[Override]
80-
public function testThatGetterReturnsExpectedValue(string $property, string $type, array $meta): void
81-
{
82+
public function testThatGetterReturnsExpectedValue(
83+
string $property,
84+
string $type,
85+
FieldMapping|AssociationMapping $meta,
86+
): void {
8287
$getter = 'get' . ucfirst($property);
8388

8489
if (in_array($type, [PhpUnitUtil::TYPE_BOOL, PhpUnitUtil::TYPE_BOOLEAN], true)) {
@@ -95,7 +100,12 @@ public function testThatGetterReturnsExpectedValue(string $property, string $typ
95100

96101
$value = $logRequest->{$getter}();
97102

98-
if (!(array_key_exists('columnName', $meta) || array_key_exists('joinColumns', $meta))) {
103+
if (method_exists($meta, 'isManyToManyOwningSide')
104+
&& (
105+
$meta->isManyToManyOwningSide()
106+
|| $meta->isOneToMany()
107+
)
108+
) {
99109
$type = ArrayCollection::class;
100110

101111
self::assertInstanceOf($type, $value);

0 commit comments

Comments
 (0)