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

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion phpunit
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ case ${PHPUNIT_VERSION} in
fi

if [ "${PHPUNIT_VERSION}" = "12" ]; then
PHPUNIT_EXEC="${PHPUNIT_EXEC} --do-not-fail-on-phpunit-warning --do-not-fail-on-deprecation"
PHPUNIT_EXEC="${PHPUNIT_EXEC} --do-not-fail-on-deprecation"
fi
;;
esac
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ private function __construct(

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

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

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

$temp[] = $metadata;
$permutationName = "{$permutationName}$metadata\n";
$permutationName[] = (string) $metadata;

if ($relationshipFields[$j]['isOneToMany']) {
$hasOneToMany = true;
}
}

yield $permutationName => $temp;
yield implode(' / ', $permutationName) => $temp;
}

if (!$hasOneToMany) {
Expand All @@ -89,12 +90,12 @@ public static function allCombinations(array $relationshipFields): iterable
// if we have at least one OneToMany relationship, we need to test with orphan removal
// let's add only one permutation with orphan removal (and all cascade to true)
$temp = [];
$permutationName = "\n";
$permutationName = [];
foreach ($relationshipFields as $relationshipField) {
$metadata = self::fromArray($relationshipField, cascade: true, orphanRemoval: $relationshipField['isOneToMany']);
$temp[] = $metadata;
$permutationName = "{$permutationName}$metadata\n";
$permutationName[] = (string) $metadata;
}
yield $permutationName => $temp;
yield implode(' / ', $permutationName) => $temp;
}
}
14 changes: 14 additions & 0 deletions tests/Integration/ORM/EdgeCasesRelationshipTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use Doctrine\Common\Collections\Collection;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\IgnorePhpunitWarnings;
use PHPUnit\Framework\Attributes\RequiresPhpunit;
use PHPUnit\Framework\Attributes\Test;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
Expand Down Expand Up @@ -44,11 +45,16 @@ final class EdgeCasesRelationshipTest extends KernelTestCase
{
use ChangesEntityRelationshipCascadePersist, Factories, RequiresORM, ResetDatabase;

// Because we're handling the provided data manually in a #[Before] method,
// PHPUnit triggers a warning, which we ignore with #[IgnorePhpunitWarnings]
public const DATA_PROVIDER_WARNING_REGEX = 'Data set "(.)*" provided by Zenstruck(.)*::provideCascadeRelationshipsCombinations has more arguments \(\d\) than the test method accepts \(0\)';

/** @test */
#[Test]
#[DataProvider('provideCascadeRelationshipsCombinations')]
#[UsingRelationships(RichDomainMandatoryRelationship\OwningSide::class, ['main'])]
#[RequiresPhpunit('>=11.4')]
#[IgnorePhpunitWarnings(self::DATA_PROVIDER_WARNING_REGEX)]
public function inversed_relationship_mandatory(): void
{
$owningSideEntityFactory = persistent_factory(RichDomainMandatoryRelationship\OwningSide::class);
Expand All @@ -68,6 +74,7 @@ public function inversed_relationship_mandatory(): void
#[DataProvider('provideCascadeRelationshipsCombinations')]
#[UsingRelationships(InversedOneToOneWithNonNullableOwning\OwningSide::class, ['inverseSide'])]
#[RequiresPhpunit('>=11.4')]
#[IgnorePhpunitWarnings(self::DATA_PROVIDER_WARNING_REGEX)]
public function inverse_one_to_one_with_non_nullable_inverse_side(): void
{
$owningSideFactory = persistent_factory(InversedOneToOneWithNonNullableOwning\OwningSide::class);
Expand All @@ -86,6 +93,7 @@ public function inverse_one_to_one_with_non_nullable_inverse_side(): void
#[DataProvider('provideCascadeRelationshipsCombinations')]
#[UsingRelationships(InversedOneToOneWithSetter\OwningSide::class, ['inverseSide'])]
#[RequiresPhpunit('>=11.4')]
#[IgnorePhpunitWarnings(self::DATA_PROVIDER_WARNING_REGEX)]
public function inverse_one_to_one_with_both_nullable(): void
{
$owningSideFactory = persistent_factory(InversedOneToOneWithSetter\OwningSide::class);
Expand All @@ -105,6 +113,7 @@ public function inverse_one_to_one_with_both_nullable(): void
#[UsingRelationships(InversedOneToOneWithOneToMany\OwningSide::class, ['inverseSide'])]
#[UsingRelationships(InversedOneToOneWithOneToMany\Item::class, ['owningSide'])]
#[RequiresPhpunit('>=11.4')]
#[IgnorePhpunitWarnings(self::DATA_PROVIDER_WARNING_REGEX)]
public function inverse_one_to_one_with_one_to_many(): void
{
$inverseSideFactory = persistent_factory(InversedOneToOneWithOneToMany\InverseSide::class);
Expand Down Expand Up @@ -145,6 +154,7 @@ public function many_to_many_to_self_referencing_inverse_side(): void
#[DataProvider('provideCascadeRelationshipsCombinations')]
#[UsingRelationships(IndexedOneToMany\ParentEntity::class, ['items'])]
#[RequiresPhpunit('>=11.4')]
#[IgnorePhpunitWarnings(self::DATA_PROVIDER_WARNING_REGEX)]
public function indexed_one_to_many(): void
{
$parentFactory = persistent_factory(IndexedOneToMany\ParentEntity::class);
Expand All @@ -167,6 +177,7 @@ public function indexed_one_to_many(): void
#[DataProvider('provideCascadeRelationshipsCombinations')]
#[UsingRelationships(InversedOneToOneWithManyToOne\InverseSide::class, ['owningSide', 'item'])]
#[RequiresPhpunit('>=11.4')]
#[IgnorePhpunitWarnings(self::DATA_PROVIDER_WARNING_REGEX)]
public function inversed_one_to_one_can_be_used_after_other_relationship(): void
{
$inverseSideFactory = persistent_factory(InversedOneToOneWithManyToOne\InverseSide::class);
Expand Down Expand Up @@ -195,6 +206,7 @@ public function inversed_one_to_one_can_be_used_after_other_relationship(): void
#[DataProvider('provideCascadeRelationshipsCombinations')]
#[UsingRelationships(InversedOneToOneWithoutAutoGeneratedId\OwningSide::class, ['inverseSide'])]
#[RequiresPhpunit('>=11.4')]
#[IgnorePhpunitWarnings(self::DATA_PROVIDER_WARNING_REGEX)]
public function inverse_one_to_one_with_custom_id(): void
{
$owningSideFactory = persistent_factory(InversedOneToOneWithoutAutoGeneratedId\OwningSide::class);
Expand All @@ -213,6 +225,7 @@ public function inverse_one_to_one_with_custom_id(): void
#[DataProvider('provideCascadeRelationshipsCombinations')]
#[UsingRelationships(OneToManyWithUnionType\OwningSideEntity::class, ['item'])]
#[RequiresPhpunit('>=11.4')]
#[IgnorePhpunitWarnings(self::DATA_PROVIDER_WARNING_REGEX)]
public function after_instantiate_flushing_using_current_object_in_relationship_one_to_one(): void
{
$owningSideFactory = persistent_factory(OneToManyWithUnionType\OwningSideEntity::class);
Expand Down Expand Up @@ -270,6 +283,7 @@ public function inverse_one_to_one_without_types_throws(): void
#[DataProvider('provideCascadeRelationshipsCombinations')]
#[UsingRelationships(InversedOneToOneWithNonNullableOwning\OwningSide::class, ['inverseSide'])]
#[RequiresPhpunit('>=11.4')]
#[IgnorePhpunitWarnings(self::DATA_PROVIDER_WARNING_REGEX)]
public function after_instantiate_flushing_using_current_object_in_relationship_inverse_one_to_one(): void
{
$owningSideFactory = persistent_factory(InversedOneToOneWithNonNullableOwning\OwningSide::class);
Expand Down
Loading