1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Pouzor\MongoDBBundle\Tests\Unit\DocumentManager; |
4
|
|
|
|
5
|
|
|
use Pouzor\MongoDBBundle\DocumentManager\DocumentManager; |
6
|
|
|
use Psr\Log\NullLogger; |
7
|
|
|
|
8
|
|
|
class DocumentManagerTest extends \PHPUnit_Framework_TestCase |
9
|
|
|
{ |
10
|
|
|
private $manager = null; |
11
|
|
|
|
12
|
|
|
private $config = [ |
13
|
|
|
"db" => "mongodbbundle", |
14
|
|
|
"host" => "localhost", |
15
|
|
|
"port" => "27017", |
16
|
|
|
"username" => null, |
17
|
|
|
"password" => null, |
18
|
|
|
"schema" => ['Foo' => ['indexes' => ["bar" => -1]]], |
19
|
|
|
"options" => [] |
20
|
|
|
]; |
21
|
|
|
|
22
|
|
|
|
23
|
|
View Code Duplication |
protected function setUp() |
|
|
|
|
24
|
|
|
{ |
25
|
|
|
$logger = new NullLogger(); |
26
|
|
|
$this->manager = new DocumentManager($this->config, $logger); |
27
|
|
|
$this->manager->removeAll("Foo"); |
28
|
|
|
$this->manager->removeAll("FooFind"); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
protected function tearDown() |
32
|
|
|
{ |
33
|
|
|
$this->manager = null; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function testGetRepository() |
37
|
|
|
{ |
38
|
|
|
$repository = $this->manager->getRepository("Foo"); |
39
|
|
|
$this->assertEquals(get_class($repository), 'Pouzor\MongoDBBundle\Repository\Repository'); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function testFind() { |
43
|
|
|
$repository = $this->manager->getRepository("FooFind"); |
44
|
|
|
|
45
|
|
|
$test = $repository->insertOne(['name' => 'test', "value" => 1]); |
46
|
|
|
|
47
|
|
|
$result = $this->manager->find("FooFind", $test->getInsertedId()); |
48
|
|
|
|
49
|
|
|
$this->assertNotNull($result); |
50
|
|
|
$this->assertEquals(1, $result['value']); |
51
|
|
|
|
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function testRemoveAll() { |
55
|
|
|
$repository = $this->manager->getRepository("FooFind"); |
56
|
|
|
$repository->insertOne(['name' => 'test', "value" => 1]); |
57
|
|
|
|
58
|
|
|
$this->assertEquals(1, $repository->count()); |
59
|
|
|
$this->manager->removeAll("FooFind"); |
60
|
|
|
$this->assertEquals(0, $repository->count()); |
61
|
|
|
|
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
|
65
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.