Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5e068c4

Browse files
authored
fix: ignore PHPUnit warnings when dataprovider returns more data than test method accepts (#958)
1 parent 0a65872 commit 5e068c4

6 files changed

Lines changed: 68 additions & 8 deletions

File tree

phpunit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ case ${PHPUNIT_VERSION} in
7474
fi
7575

7676
if [ "${PHPUNIT_VERSION}" = "12" ]; then
77-
PHPUNIT_EXEC="${PHPUNIT_EXEC} --do-not-fail-on-phpunit-warning --do-not-fail-on-deprecation"
77+
PHPUNIT_EXEC="${PHPUNIT_EXEC} --do-not-fail-on-deprecation"
7878
fi
7979
;;
8080
esac

tests/Fixture/DoctrineCascadeRelationship/DoctrineCascadeRelationshipMetadata.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ private function __construct(
2828

2929
public function __toString(): string
3030
{
31-
$name = \sprintf('%s::$%s - %s', $this->class, $this->field, $this->cascade ? 'cascade' : 'no cascade');
31+
// @phpstan-ignore argument.type
32+
$name = \sprintf('%s::$%s - %s', substr(strrchr($this->class, '\\'), 1), $this->field, $this->cascade ? 'cascade' : 'no cascade');
3233

3334
if ($this->orphanRemoval) {
3435
$name = "{$name} - (orphan removal)";
@@ -67,19 +68,19 @@ public static function allCombinations(array $relationshipFields): iterable
6768
for ($i = 0; $i < $total; ++$i) {
6869
$temp = [];
6970

70-
$permutationName = "\n";
71+
$permutationName = [];
7172
for ($j = 0; $j < \count($relationshipFields); ++$j) {
7273
$metadata = self::fromArray($relationshipFields[$j], cascade: (bool) (($i >> $j) & 1));
7374

7475
$temp[] = $metadata;
75-
$permutationName = "{$permutationName}$metadata\n";
76+
$permutationName[] = (string) $metadata;
7677

7778
if ($relationshipFields[$j]['isOneToMany']) {
7879
$hasOneToMany = true;
7980
}
8081
}
8182

82-
yield $permutationName => $temp;
83+
yield implode(' / ', $permutationName) => $temp;
8384
}
8485

8586
if (!$hasOneToMany) {
@@ -89,12 +90,12 @@ public static function allCombinations(array $relationshipFields): iterable
8990
// if we have at least one OneToMany relationship, we need to test with orphan removal
9091
// let's add only one permutation with orphan removal (and all cascade to true)
9192
$temp = [];
92-
$permutationName = "\n";
93+
$permutationName = [];
9394
foreach ($relationshipFields as $relationshipField) {
9495
$metadata = self::fromArray($relationshipField, cascade: true, orphanRemoval: $relationshipField['isOneToMany']);
9596
$temp[] = $metadata;
96-
$permutationName = "{$permutationName}$metadata\n";
97+
$permutationName[] = (string) $metadata;
9798
}
98-
yield $permutationName => $temp;
99+
yield implode(' / ', $permutationName) => $temp;
99100
}
100101
}

tests/Integration/ORM/EdgeCasesRelationshipTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
use Doctrine\Common\Collections\Collection;
1717
use PHPUnit\Framework\Attributes\DataProvider;
18+
use PHPUnit\Framework\Attributes\IgnorePhpunitWarnings;
1819
use PHPUnit\Framework\Attributes\RequiresPhpunit;
1920
use PHPUnit\Framework\Attributes\Test;
2021
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
@@ -44,11 +45,16 @@ final class EdgeCasesRelationshipTest extends KernelTestCase
4445
{
4546
use ChangesEntityRelationshipCascadePersist, Factories, RequiresORM, ResetDatabase;
4647

48+
// Because we're handling the provided data manually in a #[Before] method,
49+
// PHPUnit triggers a warning, which we ignore with #[IgnorePhpunitWarnings]
50+
public const DATA_PROVIDER_WARNING_REGEX = 'Data set "(.)*" provided by Zenstruck(.)*::provideCascadeRelationshipsCombinations has more arguments \(\d\) than the test method accepts \(0\)';
51+
4752
/** @test */
4853
#[Test]
4954
#[DataProvider('provideCascadeRelationshipsCombinations')]
5055
#[UsingRelationships(RichDomainMandatoryRelationship\OwningSide::class, ['main'])]
5156
#[RequiresPhpunit('>=11.4')]
57+
#[IgnorePhpunitWarnings(self::DATA_PROVIDER_WARNING_REGEX)]
5258
public function inversed_relationship_mandatory(): void
5359
{
5460
$owningSideEntityFactory = persistent_factory(RichDomainMandatoryRelationship\OwningSide::class);
@@ -68,6 +74,7 @@ public function inversed_relationship_mandatory(): void
6874
#[DataProvider('provideCascadeRelationshipsCombinations')]
6975
#[UsingRelationships(InversedOneToOneWithNonNullableOwning\OwningSide::class, ['inverseSide'])]
7076
#[RequiresPhpunit('>=11.4')]
77+
#[IgnorePhpunitWarnings(self::DATA_PROVIDER_WARNING_REGEX)]
7178
public function inverse_one_to_one_with_non_nullable_inverse_side(): void
7279
{
7380
$owningSideFactory = persistent_factory(InversedOneToOneWithNonNullableOwning\OwningSide::class);
@@ -86,6 +93,7 @@ public function inverse_one_to_one_with_non_nullable_inverse_side(): void
8693
#[DataProvider('provideCascadeRelationshipsCombinations')]
8794
#[UsingRelationships(InversedOneToOneWithSetter\OwningSide::class, ['inverseSide'])]
8895
#[RequiresPhpunit('>=11.4')]
96+
#[IgnorePhpunitWarnings(self::DATA_PROVIDER_WARNING_REGEX)]
8997
public function inverse_one_to_one_with_both_nullable(): void
9098
{
9199
$owningSideFactory = persistent_factory(InversedOneToOneWithSetter\OwningSide::class);
@@ -105,6 +113,7 @@ public function inverse_one_to_one_with_both_nullable(): void
105113
#[UsingRelationships(InversedOneToOneWithOneToMany\OwningSide::class, ['inverseSide'])]
106114
#[UsingRelationships(InversedOneToOneWithOneToMany\Item::class, ['owningSide'])]
107115
#[RequiresPhpunit('>=11.4')]
116+
#[IgnorePhpunitWarnings(self::DATA_PROVIDER_WARNING_REGEX)]
108117
public function inverse_one_to_one_with_one_to_many(): void
109118
{
110119
$inverseSideFactory = persistent_factory(InversedOneToOneWithOneToMany\InverseSide::class);
@@ -145,6 +154,7 @@ public function many_to_many_to_self_referencing_inverse_side(): void
145154
#[DataProvider('provideCascadeRelationshipsCombinations')]
146155
#[UsingRelationships(IndexedOneToMany\ParentEntity::class, ['items'])]
147156
#[RequiresPhpunit('>=11.4')]
157+
#[IgnorePhpunitWarnings(self::DATA_PROVIDER_WARNING_REGEX)]
148158
public function indexed_one_to_many(): void
149159
{
150160
$parentFactory = persistent_factory(IndexedOneToMany\ParentEntity::class);
@@ -167,6 +177,7 @@ public function indexed_one_to_many(): void
167177
#[DataProvider('provideCascadeRelationshipsCombinations')]
168178
#[UsingRelationships(InversedOneToOneWithManyToOne\InverseSide::class, ['owningSide', 'item'])]
169179
#[RequiresPhpunit('>=11.4')]
180+
#[IgnorePhpunitWarnings(self::DATA_PROVIDER_WARNING_REGEX)]
170181
public function inversed_one_to_one_can_be_used_after_other_relationship(): void
171182
{
172183
$inverseSideFactory = persistent_factory(InversedOneToOneWithManyToOne\InverseSide::class);
@@ -195,6 +206,7 @@ public function inversed_one_to_one_can_be_used_after_other_relationship(): void
195206
#[DataProvider('provideCascadeRelationshipsCombinations')]
196207
#[UsingRelationships(InversedOneToOneWithoutAutoGeneratedId\OwningSide::class, ['inverseSide'])]
197208
#[RequiresPhpunit('>=11.4')]
209+
#[IgnorePhpunitWarnings(self::DATA_PROVIDER_WARNING_REGEX)]
198210
public function inverse_one_to_one_with_custom_id(): void
199211
{
200212
$owningSideFactory = persistent_factory(InversedOneToOneWithoutAutoGeneratedId\OwningSide::class);
@@ -213,6 +225,7 @@ public function inverse_one_to_one_with_custom_id(): void
213225
#[DataProvider('provideCascadeRelationshipsCombinations')]
214226
#[UsingRelationships(OneToManyWithUnionType\OwningSideEntity::class, ['item'])]
215227
#[RequiresPhpunit('>=11.4')]
228+
#[IgnorePhpunitWarnings(self::DATA_PROVIDER_WARNING_REGEX)]
216229
public function after_instantiate_flushing_using_current_object_in_relationship_one_to_one(): void
217230
{
218231
$owningSideFactory = persistent_factory(OneToManyWithUnionType\OwningSideEntity::class);
@@ -270,6 +283,7 @@ public function inverse_one_to_one_without_types_throws(): void
270283
#[DataProvider('provideCascadeRelationshipsCombinations')]
271284
#[UsingRelationships(InversedOneToOneWithNonNullableOwning\OwningSide::class, ['inverseSide'])]
272285
#[RequiresPhpunit('>=11.4')]
286+
#[IgnorePhpunitWarnings(self::DATA_PROVIDER_WARNING_REGEX)]
273287
public function after_instantiate_flushing_using_current_object_in_relationship_inverse_one_to_one(): void
274288
{
275289
$owningSideFactory = persistent_factory(InversedOneToOneWithNonNullableOwning\OwningSide::class);

0 commit comments

Comments
 (0)