Skip to content

Commit 71efaff

Browse files
committed
Refactored EntityTestCase class
1 parent 3c36484 commit 71efaff

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

tests/Integration/TestCase/EntityTestCase.php

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Doctrine\Common\Collections\ArrayCollection;
2222
use Doctrine\ORM\EntityManagerInterface;
2323
use Doctrine\ORM\Mapping\ClassMetadataInfo;
24+
use Generator;
2425
use PHPUnit\Framework\Attributes\DataProvider;
2526
use PHPUnit\Framework\Attributes\TestDox;
2627
use RuntimeException;
@@ -135,7 +136,7 @@ public function testThatGetterAndSetterExists(string $property, string $type, ar
135136
*
136137
* @throws Throwable
137138
*/
138-
#[DataProvider('dataProviderTestThatSetterAndGettersWorks')]
139+
#[DataProvider('dataProviderTestThatSetterAndGettersWorksWithoutReadOnlyFlag')]
139140
#[TestDox('Test that `setter` method for `$property` property only accepts `$type` parameter')]
140141
public function testThatSetterOnlyAcceptSpecifiedType(
141142
string $property,
@@ -168,7 +169,7 @@ public function testThatSetterOnlyAcceptSpecifiedType(
168169
*
169170
* @throws Throwable
170171
*/
171-
#[DataProvider('dataProviderTestThatSetterAndGettersWorks')]
172+
#[DataProvider('dataProviderTestThatSetterAndGettersWorksWithoutReadOnlyFlag')]
172173
#[TestDox('Test that `setter` method for `$type $property` property is fluent')]
173174
public function testThatSetterReturnsInstanceOfEntity(
174175
string $property,
@@ -202,7 +203,7 @@ public function testThatSetterReturnsInstanceOfEntity(
202203
*
203204
* @throws Throwable
204205
*/
205-
#[DataProvider('dataProviderTestThatSetterAndGettersWorks')]
206+
#[DataProvider('dataProviderTestThatSetterAndGettersWorksWithoutReadOnlyFlag')]
206207
#[TestDox('Test that `getter` method for `$property` property returns value of expected type `$type`')]
207208
public function testThatGetterReturnsExpectedValue(string $property, string $type, array $meta): void
208209
{
@@ -471,7 +472,8 @@ public static function dataProviderTestThatSetterAndGettersWorks(): array
471472
* following data:
472473
* 1) Name
473474
* 2) Type
474-
* 4) meta
475+
* 3) Mapping data
476+
* 4) Read-only flag
475477
*
476478
* @return array
477479
*/
@@ -508,6 +510,19 @@ public static function dataProviderTestThatSetterAndGettersWorks(): array
508510
), ...$assocFields];
509511
}
510512

513+
public static function dataProviderTestThatSetterAndGettersWorksWithoutReadOnlyFlag(): Generator
514+
{
515+
foreach (self::dataProviderTestThatSetterAndGettersWorks() as $data) {
516+
self::assertIsArray($data);
517+
self::assertCount(4, $data);
518+
519+
// Remove 'Read-only flag' from data
520+
unset($data[3]);
521+
522+
yield $data;
523+
}
524+
}
525+
511526
/**
512527
* @return array<mixed>
513528
*/
@@ -596,7 +611,6 @@ public static function dataProviderTestThatManyToOneAssociationMethodsWorksAsExp
596611
'get' . ucfirst((string)$mapping['fieldName']),
597612
$targetEntity,
598613
$mapping['fieldName'],
599-
$mapping,
600614
],
601615
];
602616
};
@@ -612,7 +626,7 @@ public static function dataProviderTestThatManyToOneAssociationMethodsWorksAsExp
612626

613627
if (empty($items)) {
614628
$output = [
615-
[null, null, null, null, []],
629+
[null, null, null, null],
616630
];
617631
} else {
618632
$output = array_merge(...array_values(array_map($iterator, $items)));
@@ -749,7 +763,6 @@ public static function dataProviderTestThatOneToManyAssociationMethodsWorksAsExp
749763
[
750764
'get' . ucfirst((string)$mapping['fieldName']),
751765
$mapping['fieldName'],
752-
$mapping,
753766
],
754767
];
755768

@@ -764,7 +777,7 @@ public static function dataProviderTestThatOneToManyAssociationMethodsWorksAsExp
764777

765778
if (empty($items)) {
766779
$output = [
767-
[null, null, []],
780+
[null, null],
768781
];
769782
} else {
770783
$output = array_merge(...array_values(array_map($iterator, $items)));

0 commit comments

Comments
 (0)