Simplify *One methods in the persister

This commit is contained in:
Tim Nagel 2014-07-03 23:37:44 +10:00
parent c200e8fdfd
commit 21e5d906a7
3 changed files with 10 additions and 26 deletions

View file

@ -71,8 +71,7 @@ class ObjectPersister implements ObjectPersisterInterface
*/
public function insertOne($object)
{
$document = $this->transformToElasticaDocument($object);
$this->type->addDocument($document);
$this->insertMany(array($object));
}
/**
@ -83,11 +82,7 @@ class ObjectPersister implements ObjectPersisterInterface
**/
public function replaceOne($object)
{
$document = $this->transformToElasticaDocument($object);
try {
$this->type->deleteById($document->getId());
} catch (NotFoundException $e) {}
$this->type->addDocument($document);
$this->replaceMany(array($object));
}
/**
@ -98,10 +93,7 @@ class ObjectPersister implements ObjectPersisterInterface
**/
public function deleteOne($object)
{
$document = $this->transformToElasticaDocument($object);
try {
$this->type->deleteById($document->getId());
} catch (NotFoundException $e) {}
$this->deleteMany(array($object));
}
/**
@ -113,9 +105,7 @@ class ObjectPersister implements ObjectPersisterInterface
**/
public function deleteById($id)
{
try {
$this->type->deleteById($id);
} catch (NotFoundException $e) {}
$this->deleteManyByIdentifiers(array($id));
}
/**

View file

@ -47,10 +47,7 @@ class ObjectPersisterTest extends \PHPUnit_Framework_TestCase
->disableOriginalConstructor()
->getMock();
$typeMock->expects($this->once())
->method('deleteById')
->with($this->equalTo(123));
$typeMock->expects($this->once())
->method('addDocument');
->method('updateDocuments');
$fields = array('name' => array());
@ -91,7 +88,7 @@ class ObjectPersisterTest extends \PHPUnit_Framework_TestCase
$typeMock->expects($this->never())
->method('deleteById');
$typeMock->expects($this->once())
->method('addDocument');
->method('addDocuments');
$fields = array('name' => array());
@ -130,7 +127,7 @@ class ObjectPersisterTest extends \PHPUnit_Framework_TestCase
->disableOriginalConstructor()
->getMock();
$typeMock->expects($this->once())
->method('deleteById');
->method('deleteDocuments');
$typeMock->expects($this->never())
->method('addDocument');

View file

@ -42,10 +42,7 @@ class ObjectSerializerPersisterTest extends \PHPUnit_Framework_TestCase
->disableOriginalConstructor()
->getMock();
$typeMock->expects($this->once())
->method('deleteById')
->with($this->equalTo(123));
$typeMock->expects($this->once())
->method('addDocument');
->method('updateDocuments');
$serializerMock = $this->getMockBuilder('FOS\ElasticaBundle\Serializer\Callback')->getMock();
$serializerMock->expects($this->once())->method('serialize');
@ -65,7 +62,7 @@ class ObjectSerializerPersisterTest extends \PHPUnit_Framework_TestCase
$typeMock->expects($this->never())
->method('deleteById');
$typeMock->expects($this->once())
->method('addDocument');
->method('addDocuments');
$serializerMock = $this->getMockBuilder('FOS\ElasticaBundle\Serializer\Callback')->getMock();
$serializerMock->expects($this->once())->method('serialize');
@ -83,7 +80,7 @@ class ObjectSerializerPersisterTest extends \PHPUnit_Framework_TestCase
->disableOriginalConstructor()
->getMock();
$typeMock->expects($this->once())
->method('deleteById');
->method('deleteDocuments');
$typeMock->expects($this->never())
->method('addDocument');