Skip to content

Commit

Permalink
test ManyToManyMultipleRelationshipSameTargetEntity with ID field of …
Browse files Browse the repository at this point in the history
…both common and custom names
  • Loading branch information
Vladimir Klimes committed Aug 23, 2024
1 parent d058a8f commit e1072fc
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace Sonata\EntityAuditBundle\Tests\Fixtures\Relation;

use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity]
class ManyToManyMultipleRelationshipCustomIdNamedEntity extends ManyToManyMultipleRelationshipEntity
{
/**
* @var int|null
*/
#[ORM\Id]
#[ORM\Column(name: 'strange_owned_id_name', type: Types::INTEGER)]
#[ORM\GeneratedValue]
protected $id;
}
37 changes: 36 additions & 1 deletion tests/RelationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Sonata\EntityAuditBundle\Tests\Fixtures\Relation\DataLegalEntity;
use Sonata\EntityAuditBundle\Tests\Fixtures\Relation\DataPrivateEntity;
use Sonata\EntityAuditBundle\Tests\Fixtures\Relation\FoodCategory;
use Sonata\EntityAuditBundle\Tests\Fixtures\Relation\ManyToManyMultipleRelationshipCustomIdNamedEntity;
use Sonata\EntityAuditBundle\Tests\Fixtures\Relation\ManyToManyMultipleRelationshipEntity;
use Sonata\EntityAuditBundle\Tests\Fixtures\Relation\ManyToManyMultipleTargetEntity;
use Sonata\EntityAuditBundle\Tests\Fixtures\Relation\OneToOneAuditedEntity;
Expand Down Expand Up @@ -67,6 +68,7 @@ final class RelationTest extends BaseTest
DataLegalEntity::class,
DataPrivateEntity::class,
DataContainerEntity::class,
ManyToManyMultipleRelationshipCustomIdNamedEntity::class,
ManyToManyMultipleRelationshipEntity::class,
ManyToManyMultipleTargetEntity::class,
];
Expand All @@ -91,6 +93,7 @@ final class RelationTest extends BaseTest
DataLegalEntity::class,
DataPrivateEntity::class,
DataContainerEntity::class,
ManyToManyMultipleRelationshipCustomIdNamedEntity::class,
ManyToManyMultipleRelationshipEntity::class,
ManyToManyMultipleTargetEntity::class,
];
Expand Down Expand Up @@ -379,12 +382,24 @@ public function testManyToManyMultipleRelationshipSameTargetEntity(): void
$manyToMany->addPrimaryTarget($targetOne);
$manyToMany->addSecondaryTarget($targetTwo);

$targetThree = new ManyToManyMultipleTargetEntity();
$targetFour = new ManyToManyMultipleTargetEntity();

$manyToManyWithCustomNameOfIdColumn = new ManyToManyMultipleRelationshipCustomIdNamedEntity();
$manyToManyWithCustomNameOfIdColumn->setTitle('manyToMany#2');
$manyToManyWithCustomNameOfIdColumn->addPrimaryTarget($targetThree);
$manyToManyWithCustomNameOfIdColumn->addSecondaryTarget($targetFour);

$em->persist($targetOne);
$em->persist($targetTwo);
$em->persist($targetThree);
$em->persist($targetFour);
$em->persist($manyToMany);
$em->persist($manyToManyWithCustomNameOfIdColumn);

$em->flush(); // #1
$em->flush(); // #1 + #2

// manyToMany#1
$manyToManyId = $manyToMany->getId();
static::assertNotNull($manyToManyId);

Expand All @@ -399,6 +414,26 @@ public function testManyToManyMultipleRelationshipSameTargetEntity(): void
// ensure that there is an audited entry for the secondaryTargets property
static::assertInstanceOf(Collection::class, $audited->getSecondaryTargets());
static::assertCount(1, $audited->getSecondaryTargets());

// manyToMany#2
$manyToManyId = $manyToManyWithCustomNameOfIdColumn->getId();
static::assertNotNull($manyToManyId);

$audited = $auditReader->find(
ManyToManyMultipleRelationshipCustomIdNamedEntity::class,
$manyToManyId,
1
);

static::assertNotNull($audited);

// ensure that there is an audited entry for the primaryTargets property
static::assertInstanceOf(Collection::class, $audited->getPrimaryTargets());
static::assertCount(1, $audited->getPrimaryTargets());

// ensure that there is an audited entry for the secondaryTargets property
static::assertInstanceOf(Collection::class, $audited->getSecondaryTargets());
static::assertCount(1, $audited->getSecondaryTargets());
}

/**
Expand Down

0 comments on commit e1072fc

Please sign in to comment.