parent
0a1a84163e
commit
112a402016
@ -16,6 +16,7 @@ use Doctrine\ORM\Mapping\Entity;
|
|||||||
use Doctrine\ORM\Mapping\Id;
|
use Doctrine\ORM\Mapping\Id;
|
||||||
use Doctrine\ORM\Mapping\GeneratedValue;
|
use Doctrine\ORM\Mapping\GeneratedValue;
|
||||||
use Doctrine\ORM\Mapping\ManyToOne;
|
use Doctrine\ORM\Mapping\ManyToOne;
|
||||||
|
use Doctrine\ORM\PersistentCollection;
|
||||||
use Doctrine\ORM\Proxy\Proxy;
|
use Doctrine\ORM\Proxy\Proxy;
|
||||||
use Doctrine\Tests\Models\DDC6613\Phone;
|
use Doctrine\Tests\Models\DDC6613\Phone;
|
||||||
use Doctrine\Tests\Models\DDC6613\User;
|
use Doctrine\Tests\Models\DDC6613\User;
|
||||||
@ -31,8 +32,8 @@ class DDC6613Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
|||||||
try {
|
try {
|
||||||
$this->setUpEntitySchema(
|
$this->setUpEntitySchema(
|
||||||
[
|
[
|
||||||
Phone::class,
|
DDC6613Phone::class,
|
||||||
User::class
|
DDC6613User::class
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
} catch (SchemaException $e) {
|
} catch (SchemaException $e) {
|
||||||
@ -41,8 +42,7 @@ class DDC6613Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
|||||||
|
|
||||||
public function testFail()
|
public function testFail()
|
||||||
{
|
{
|
||||||
$user = new User();
|
$user = new DDC6613User();
|
||||||
$user->id = 1;
|
|
||||||
$this->_em->persist($user);
|
$this->_em->persist($user);
|
||||||
$this->_em->flush();
|
$this->_em->flush();
|
||||||
|
|
||||||
@ -50,18 +50,78 @@ class DDC6613Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
|||||||
|
|
||||||
/** @var User $user */
|
/** @var User $user */
|
||||||
$user = $this->_em->find(User::class, 1);
|
$user = $this->_em->find(User::class, 1);
|
||||||
$phone1 = new Phone();
|
$phone1 = new DDC6613Phone();
|
||||||
$phone1->id = 1;
|
$phones = $user->phones;
|
||||||
$user->phones->add($phone1);
|
$user->phones->add($phone1);
|
||||||
$this->_em->persist($phone1);
|
$this->_em->persist($phone1);
|
||||||
$this->_em->flush();
|
$this->_em->flush();
|
||||||
|
|
||||||
$phone2 = new Phone();
|
$phone2 = new DDC6613Phone();
|
||||||
$phone2->id = 2;
|
|
||||||
$user->phones->add($phone2);
|
$user->phones->add($phone2);
|
||||||
$this->_em->persist($phone2);
|
$this->_em->persist($phone2);
|
||||||
$user->phones->toArray();
|
|
||||||
|
/* @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();
|
$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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user