From df7c9e4c12176e42d5a4b432b7357a3c3ab28d7c Mon Sep 17 00:00:00 2001 From: Martynas Sudintas Date: Tue, 4 Nov 2014 10:55:30 +0200 Subject: [PATCH] document update fix --- ORM/Manager.php | 2 +- Tests/Functional/ORM/ManagerTest.php | 2 -- Tests/Functional/ORM/RepositoryTest.php | 39 +++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/ORM/Manager.php b/ORM/Manager.php index cda35ee2..7da28f16 100644 --- a/ORM/Manager.php +++ b/ORM/Manager.php @@ -101,7 +101,7 @@ public function persist(DocumentInterface $object) $document = $this->convertToArray($object, $repository['getters']); $this->getConnection()->bulk( - 'create', + 'index', $repository['type'], $document ); diff --git a/Tests/Functional/ORM/ManagerTest.php b/Tests/Functional/ORM/ManagerTest.php index 83d2f9c8..b4d17956 100644 --- a/Tests/Functional/ORM/ManagerTest.php +++ b/Tests/Functional/ORM/ManagerTest.php @@ -50,8 +50,6 @@ public function testPersist() $manager->persist($product); $manager->commit(); - $manager->flush(); - $manager->refresh(); $repository = $manager->getRepository('AcmeTestBundle:Product'); /** @var Product[] $actualProduct */ diff --git a/Tests/Functional/ORM/RepositoryTest.php b/Tests/Functional/ORM/RepositoryTest.php index 6b2f1ec9..b2bcc81c 100644 --- a/Tests/Functional/ORM/RepositoryTest.php +++ b/Tests/Functional/ORM/RepositoryTest.php @@ -246,4 +246,43 @@ protected function getProductsArray() { return $this->getDataArray()['default']['product']; } + + /** + * Tests if document is being updated when persisted. + */ + public function testDocumentUpdate() + { + $manager = $this->getManager(); + $repository = $manager->getRepository('AcmeTestBundle:Product'); + + /** @var Product $document */ + $document = $repository->createDocument(); + + $document->setId(5); + $document->title = 'awesome'; + + $manager->persist($document); + $manager->commit(); + + // Creates document. + $document = $repository->find(5); + $this->assertEquals( + ['id' => '5', 'title' => 'awesome'], + array_filter(get_object_vars($document)), + 'Document should be created.' + ); + + $document->title = 'more awesome'; + + // Updates document. + $manager->persist($document); + $manager->commit(); + + $document = $repository->find(5); + $this->assertEquals( + ['id' => '5', 'title' => 'more awesome'], + array_filter(get_object_vars($document)), + 'Document should be updated.' + ); + } }