/** * @inheritdoc */ public function getHydratorFor($className) { if (!isset($this->hydrators[$className])) { $metadata = $this->dm->getClassMetadata($className); $this->hydrators[$className] = new DynamicHydrator($this->dm, $this->dm->getUnitOfWork(), $metadata); } return $this->hydrators[$className]; }
/** * @test */ public function hydrate_contact_with_link_list() { $md = $this->manager->getClassMetadata(Stub\Linked\Contact::class); $dh = new DynamicHydrator($this->manager, $this->manager->getUnitOfWork(), $md); $c = new Stub\Linked\Contact(); $d = json_decode(<<<JSON { "@rid": "#1:1", "name": "Sydney", "phones": [ "#3:1", "#3:2" ] } JSON , true); $hd = $dh->hydrate($c, $d); $this->assertEquals(['rid', 'name', 'phones'], array_keys($hd)); $this->assertEquals('#1:1', $hd['rid']); $this->assertEquals('Sydney', $hd['name']); /** @var Stub\Linked\Phone[] $phones */ $phones = $c->getPhones()->toArray(); $this->assertCount(2, $phones); $phone = $phones[0]; $this->assertEquals('work', $phone->type); $this->assertEquals(UnitOfWork::STATE_MANAGED, $this->uow->getDocumentState($phone)); $this->assertTrue($this->uow->isInIdentityMap($phone)); $phone = $phones[1]; $this->assertEquals('home', $phone->type); $this->assertEquals(UnitOfWork::STATE_MANAGED, $this->uow->getDocumentState($phone)); $this->assertTrue($this->uow->isInIdentityMap($phone)); }
/** * Initializes a new instance of the <tt>ProxyFactory</tt> class that is * connected to the given <tt>DocumentManager</tt>. * * @param DocumentManager $manager * @param string $proxyDir The directory to use for the proxy classes. It * must exist. * @param string $proxyNamespace The namespace to use for the proxy classes. * @param int $autoGenerate Whether to automatically generate proxy classes. */ public function __construct(DocumentManager $manager, $proxyDir, $proxyNamespace, $autoGenerate = AbstractProxyFactory::AUTOGENERATE_NEVER) { $this->metadataFactory = $manager->getMetadataFactory(); $this->uow = $manager->getUnitOfWork(); $this->proxyNamespace = $proxyNamespace; $proxyGenerator = new ProxyGenerator($proxyDir, $proxyNamespace); $proxyGenerator->setPlaceholder('baseProxyInterface', 'Doctrine\\ODM\\OrientDB\\Proxy\\Proxy'); parent::__construct($proxyGenerator, $this->metadataFactory, $autoGenerate); }
/** * @depends detach_will_remove_existing_managed_document * @test */ public function getDocumentState_returns_STATE_DETACHED_for_existing_document() { $uow = $this->manager->getUnitOfWork(); $c = new Contact(); $c->rid = "#1:1"; $c->name = "Sydney"; $uow->registerManaged($c, $c->rid, $uow->getDocumentActualData($c)); $dp = $this->prophesize(DocumentPersister::class); $dp->exists($c)->willReturn(true); $uow->setDocumentPersister(Contact::class, $dp->reveal()); $uow->detach($c); $this->assertEquals($uow::STATE_DETACHED, $uow->getDocumentState($c)); }
/** * @test */ public function getDocumentChangeSet_includes_embedded_list_for_new() { $uow = $this->manager->getUnitOfWork(); $c = new Contact(); $this->manager->persist($c); $c->name = "Sydney"; $phone = new Phone(); $phone->type = "work"; $phone->phoneNumber = "4804441919"; $c->phones[] = $phone; $md = $this->manager->getClassMetadata(Contact::class); $uow->computeChangeSet($md, $c); $cs = $uow->getDocumentChangeSet($c); $this->assertEquals(['name', 'email', 'phones'], array_keys($cs)); }
/** * @test */ public function getDocumentChangeSet_update_nulls_linked() { $c = new Contact(); $c->name = "Sydney"; $c->rid = "#1:1"; $e = new EmailAddress(); $e->rid = "#2:1"; $e->type = "work"; $e->email = "*****@*****.**"; $c->setEmail($e); $e->contact = $c; $uow = $this->manager->getUnitOfWork(); $uow->registerManaged($c, $c->rid, ['rid' => $c->rid, 'name' => 'Sydney', 'email' => $e]); $uow->registerManaged($e, $e->rid, ['rid' => $e->rid, 'type' => 'home', 'email' => '*****@*****.**', 'contact' => $c]); $c->setEmail(null); $uow->computeChangeSets(); $cs = $uow->getDocumentChangeSet($c); $this->assertEquals(['email'], array_keys($cs)); $this->assertEquals([$e, null], $cs['email']); }