2017-08-11 14:21:56 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* User: Uladzimir Struts <Sysaninster@gmail.com>
|
|
|
|
* Date: 11.08.2017
|
|
|
|
* Time: 12:28
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
|
|
|
|
2017-08-11 14:23:21 +02:00
|
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
2017-08-11 14:21:56 +02:00
|
|
|
use Doctrine\DBAL\Schema\SchemaException;
|
|
|
|
use Doctrine\ORM\Mapping\Column;
|
|
|
|
use Doctrine\ORM\Mapping\Entity;
|
|
|
|
use Doctrine\ORM\Mapping\GeneratedValue;
|
2017-08-11 14:23:21 +02:00
|
|
|
use Doctrine\ORM\Mapping\Id;
|
2017-08-11 14:21:56 +02:00
|
|
|
use Doctrine\ORM\PersistentCollection;
|
2017-08-11 14:23:21 +02:00
|
|
|
use Doctrine\Tests\OrmFunctionalTestCase;
|
2017-08-11 14:21:56 +02:00
|
|
|
|
2017-08-11 14:23:21 +02:00
|
|
|
/**
|
|
|
|
* @group #6613
|
|
|
|
* @group #6614
|
|
|
|
*/
|
|
|
|
class DDC6613Test extends OrmFunctionalTestCase
|
2017-08-11 14:21:56 +02:00
|
|
|
{
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
try {
|
|
|
|
$this->setUpEntitySchema(
|
|
|
|
[
|
|
|
|
DDC6613Phone::class,
|
2017-08-11 14:23:21 +02:00
|
|
|
DDC6613User::class,
|
2017-08-11 14:21:56 +02:00
|
|
|
]
|
|
|
|
);
|
|
|
|
} catch (SchemaException $e) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testFail()
|
|
|
|
{
|
|
|
|
$user = new DDC6613User();
|
|
|
|
$this->_em->persist($user);
|
|
|
|
$this->_em->flush();
|
|
|
|
|
|
|
|
$this->_em->clear();
|
|
|
|
|
|
|
|
/** @var User $user */
|
2017-08-11 14:23:21 +02:00
|
|
|
$user = $this->_em->find(User::class, 1);
|
2017-08-11 14:21:56 +02:00
|
|
|
$phone1 = new DDC6613Phone();
|
|
|
|
$phones = $user->phones;
|
|
|
|
$user->phones->add($phone1);
|
|
|
|
$this->_em->persist($phone1);
|
|
|
|
$this->_em->flush();
|
|
|
|
|
|
|
|
$phone2 = new DDC6613Phone();
|
|
|
|
$user->phones->add($phone2);
|
|
|
|
$this->_em->persist($phone2);
|
|
|
|
|
|
|
|
/* @var $phones PersistentCollection */
|
|
|
|
// $phones = $user->phones;
|
|
|
|
|
|
|
|
self::assertInstanceOf(PersistentCollection::class, $phones);
|
|
|
|
self::assertFalse($phones->isInitialized());
|
|
|
|
|
|
|
|
$phones->initialize();
|
|
|
|
|
|
|
|
self::assertTrue($phones->isInitialized());
|
|
|
|
self::assertCount(2, $phones);
|
|
|
|
|
|
|
|
$this->_em->flush();
|
|
|
|
|
|
|
|
self::assertFalse($phones->isDirty());
|
|
|
|
self::assertTrue($phones->isInitialized());
|
|
|
|
self::assertCount(2, $user->phones);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Entity
|
|
|
|
* @Table(name="ddc6613_user")
|
|
|
|
*/
|
|
|
|
class DDC6613User
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @Id
|
|
|
|
* @GeneratedValue(strategy="NONE")
|
|
|
|
* @Column(type="string")
|
|
|
|
*/
|
|
|
|
private $id;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ManyToMany(targetEntity="Phone", fetch="LAZY", cascade={"remove", "detach"})
|
|
|
|
*/
|
|
|
|
public $phones;
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->id = uniqid('user', true);
|
|
|
|
$this->phones = new ArrayCollection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Table(name="ddc6613_phone")
|
|
|
|
*/
|
|
|
|
class DDC6613Phone
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @Id
|
|
|
|
* @GeneratedValue(strategy="NONE")
|
|
|
|
* @Column(type="integer")
|
|
|
|
*/
|
|
|
|
public $id;
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->id = uniqid('phone', true);
|
|
|
|
}
|
|
|
|
}
|