-
Notifications
You must be signed in to change notification settings - Fork 129
/
Copy pathMongoDeleteBatchTest.php
71 lines (52 loc) · 1.87 KB
/
MongoDeleteBatchTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
namespace Alcaeus\MongoDbAdapter\Tests\Mongo;
use Alcaeus\MongoDbAdapter\Tests\TestCase;
class MongoDeleteBatchTest extends TestCase
{
public function testSerialize()
{
$batch = new \MongoDeleteBatch($this->getCollection());
$this->assertInternalType('string', serialize($batch));
}
public function testDeleteOne()
{
$collection = $this->getCollection();
$batch = new \MongoDeleteBatch($collection);
$document = ['foo' => 'bar'];
$collection->insert($document);
unset($document['_id']);
$collection->insert($document);
$this->assertTrue($batch->add(['q' => ['foo' => 'bar'], 'limit' => 1]));
$expected = [
'nRemoved' => 1,
'ok' => true,
];
$this->assertSame($expected, $batch->execute());
$newCollection = $this->getCheckDatabase()->selectCollection('test');
$this->assertSame(1, $newCollection->count());
}
public function testDeleteMany()
{
$collection = $this->getCollection();
$batch = new \MongoDeleteBatch($collection);
$document = ['foo' => 'bar'];
$collection->insert($document);
unset($document['_id']);
$collection->insert($document);
$this->assertTrue($batch->add(['q' => ['foo' => 'bar'], 'limit' => 0]));
$expected = [
'nRemoved' => 2,
'ok' => true,
];
$this->assertSame($expected, $batch->execute());
$newCollection = $this->getCheckDatabase()->selectCollection('test');
$this->assertSame(0, $newCollection->count());
}
public function testValidateItem()
{
$collection = $this->getCollection();
$batch = new \MongoDeleteBatch($collection);
$this->setExpectedException('Exception', "Expected \$item to contain 'q' key");
$batch->add([]);
}
}