Skip to content

Commit 21e5d90

Browse files
committed
Simplify *One methods in the persister
1 parent c200e8f commit 21e5d90

File tree

3 files changed

+10
-26
lines changed

3 files changed

+10
-26
lines changed

Persister/ObjectPersister.php

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ private function log(BulkException $e)
7171
*/
7272
public function insertOne($object)
7373
{
74-
$document = $this->transformToElasticaDocument($object);
75-
$this->type->addDocument($document);
74+
$this->insertMany(array($object));
7675
}
7776

7877
/**
@@ -83,11 +82,7 @@ public function insertOne($object)
8382
**/
8483
public function replaceOne($object)
8584
{
86-
$document = $this->transformToElasticaDocument($object);
87-
try {
88-
$this->type->deleteById($document->getId());
89-
} catch (NotFoundException $e) {}
90-
$this->type->addDocument($document);
85+
$this->replaceMany(array($object));
9186
}
9287

9388
/**
@@ -98,10 +93,7 @@ public function replaceOne($object)
9893
**/
9994
public function deleteOne($object)
10095
{
101-
$document = $this->transformToElasticaDocument($object);
102-
try {
103-
$this->type->deleteById($document->getId());
104-
} catch (NotFoundException $e) {}
96+
$this->deleteMany(array($object));
10597
}
10698

10799
/**
@@ -113,9 +105,7 @@ public function deleteOne($object)
113105
**/
114106
public function deleteById($id)
115107
{
116-
try {
117-
$this->type->deleteById($id);
118-
} catch (NotFoundException $e) {}
108+
$this->deleteManyByIdentifiers(array($id));
119109
}
120110

121111
/**

Tests/Persister/ObjectPersisterTest.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,7 @@ public function testThatCanReplaceObject()
4747
->disableOriginalConstructor()
4848
->getMock();
4949
$typeMock->expects($this->once())
50-
->method('deleteById')
51-
->with($this->equalTo(123));
52-
$typeMock->expects($this->once())
53-
->method('addDocument');
50+
->method('updateDocuments');
5451

5552
$fields = array('name' => array());
5653

@@ -91,7 +88,7 @@ public function testThatCanInsertObject()
9188
$typeMock->expects($this->never())
9289
->method('deleteById');
9390
$typeMock->expects($this->once())
94-
->method('addDocument');
91+
->method('addDocuments');
9592

9693
$fields = array('name' => array());
9794

@@ -130,7 +127,7 @@ public function testThatCanDeleteObject()
130127
->disableOriginalConstructor()
131128
->getMock();
132129
$typeMock->expects($this->once())
133-
->method('deleteById');
130+
->method('deleteDocuments');
134131
$typeMock->expects($this->never())
135132
->method('addDocument');
136133

Tests/Persister/ObjectSerializerPersisterTest.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,7 @@ public function testThatCanReplaceObject()
4242
->disableOriginalConstructor()
4343
->getMock();
4444
$typeMock->expects($this->once())
45-
->method('deleteById')
46-
->with($this->equalTo(123));
47-
$typeMock->expects($this->once())
48-
->method('addDocument');
45+
->method('updateDocuments');
4946

5047
$serializerMock = $this->getMockBuilder('FOS\ElasticaBundle\Serializer\Callback')->getMock();
5148
$serializerMock->expects($this->once())->method('serialize');
@@ -65,7 +62,7 @@ public function testThatCanInsertObject()
6562
$typeMock->expects($this->never())
6663
->method('deleteById');
6764
$typeMock->expects($this->once())
68-
->method('addDocument');
65+
->method('addDocuments');
6966

7067
$serializerMock = $this->getMockBuilder('FOS\ElasticaBundle\Serializer\Callback')->getMock();
7168
$serializerMock->expects($this->once())->method('serialize');
@@ -83,7 +80,7 @@ public function testThatCanDeleteObject()
8380
->disableOriginalConstructor()
8481
->getMock();
8582
$typeMock->expects($this->once())
86-
->method('deleteById');
83+
->method('deleteDocuments');
8784
$typeMock->expects($this->never())
8885
->method('addDocument');
8986

0 commit comments

Comments
 (0)