/** * Tests cloning documents. */ public function testCloningDocuments() { $manager = $this->repository->getManager(); $document = new ProductDocument(); $document->setId('tuna_id'); $document->title = 'tuna'; $manager->persist($document); $manager->commit(); $document = $this->repository->find('tuna_id'); $clone = clone $document; $this->assertNull($clone->getId(), 'Id should be null\'ed.'); $manager->persist($clone); $manager->commit(); $search = $this->repository->createSearch()->addQuery(new TermQuery('title', 'tuna')); $this->assertCount(2, $this->repository->execute($search), '2 Results should be found.'); }
/** * Tests if document is being updated when persisted. */ public function testDocumentUpdate() { $manager = $this->getManager(); $repository = $manager->getRepository('AcmeBarBundle:ProductDocument'); $document = new ProductDocument(); $document->setId(5); $document->title = 'acme'; $manager->persist($document); $manager->commit(); // Creates document. /** @var ProductDocument $document */ $document = $repository->find(5); $this->assertEquals(['id' => '5', 'title' => 'acme'], ['id' => $document->getId(), 'title' => $document->title], 'Document should be created.'); $document->title = 'acme bar'; // Updates document. $manager->persist($document); $manager->commit(); $document = $repository->find(5); $this->assertEquals(['id' => '5', 'title' => 'acme bar'], ['id' => $document->getId(), 'title' => $document->title], 'Document should be updated.'); }