| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- <?php
- namespace Alcaeus\MongoDbAdapter\Tests;
- class MongoDeleteBatchTest extends TestCase
- {
- public function testDeleteOne()
- {
- $collection = $this->getCollection();
- $batch = new \MongoDeleteBatch($collection);
- $collection->insert(['foo' => 'bar']);
- $collection->insert(['foo' => 'bar']);
- $this->assertTrue($batch->add(['q' => ['foo' => 'bar'], 'limit' => 1]));
- $expected = [
- 'ok' => 1.0,
- 'nInserted' => 0,
- 'nMatched' => 0,
- 'nModified' => 0,
- 'nUpserted' => 0,
- 'nRemoved' => 1,
- ];
- $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);
- $collection->insert(['foo' => 'bar']);
- $collection->insert(['foo' => 'bar']);
- $this->assertTrue($batch->add(['q' => ['foo' => 'bar'], 'limit' => 0]));
- $expected = [
- 'ok' => 1.0,
- 'nInserted' => 0,
- 'nMatched' => 0,
- 'nModified' => 0,
- 'nUpserted' => 0,
- 'nRemoved' => 2,
- ];
- $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', 'invalid item');
- $batch->add([]);
- }
- }
|