1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
<?php
declare(strict_types=1);
namespace Doctrine\Tests\ORM\Persisters;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\Name\UnquotedIdentifierFolding;
use Doctrine\ORM\Persisters\Collection\ManyToManyPersister;
use Doctrine\Tests\Models\ManyToManyPersister\ChildClass;
use Doctrine\Tests\Models\ManyToManyPersister\OtherParentClass;
use Doctrine\Tests\Models\ManyToManyPersister\ParentClass;
use Doctrine\Tests\OrmTestCase;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\RequiresPhpunit;
use function enum_exists;
#[CoversClass(ManyToManyPersister::class)]
final class ManyToManyPersisterTest extends OrmTestCase
{
#[Group('GH-6991')]
#[Group('ManyToManyPersister')]
#[RequiresPhpunit('< 12')]
public function testDeleteManyToManyCollection(): void
{
$driver = $this->createMock(Driver::class);
$driver->method('connect')
->willReturn($this->createMock(Driver\Connection::class));
$connection = $this->getMockBuilder(Connection::class)
->setConstructorArgs([[], $driver])
->onlyMethods(['executeStatement', 'getDatabasePlatform'])
->getMock();
$connection->method('getDatabasePlatform')
->willReturn($this->getMockForAbstractClass(AbstractPlatform::class, enum_exists(UnquotedIdentifierFolding::class) ? [UnquotedIdentifierFolding::UPPER] : []));
$parent = new ParentClass(1);
$otherParent = new OtherParentClass(42);
$child = new ChildClass(1, $otherParent);
$parent->children->add($child);
$child->parents->add($parent);
$em = $this->createTestEntityManagerWithConnection($connection);
$em->persist($parent);
$em->flush();
$childReloaded = $em->find(ChildClass::class, ['id1' => 1, 'otherParent' => $otherParent]);
self::assertInstanceOf(ChildClass::class, $childReloaded);
$connection->expects($this->once())
->method('executeStatement')
->with('DELETE FROM parent_child WHERE child_id1 = ? AND child_id2 = ?', [1, 42]);
$persister = new ManyToManyPersister($em);
$persister->delete($childReloaded->parents);
}
}
|