Completed
Push — master ( bdf534...ae9d2a )
by Mehmet
03:50
created

MongoDBTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 54
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 8 1
A testInsertGetDocument() 0 9 1
A testFindDocuments() 0 12 1
A testInsertUpdateGetDocument() 0 14 1
1
<?php
2
namespace tests;
3
4
use Soupmix\MongoDB;
5
6
class MongoDBTest extends \PHPUnit_Framework_TestCase
7
{
8
    /**
9
     * @var \Soupmix\MongoDB $client
10
     */
11
    protected $client = null;
12
13
    protected function setUp()
14
    {
15
        $this->client = new MongoDB([
16
            'db_name' => 'mydb_test',
17
            'connection_string' => "mongodb://soupmix:[email protected]",
18
            'options' => []
19
        ]);
20
    }
21
22
    public function testInsertGetDocument()
23
    {
24
        $docId = $this->client->insert('test', ['id' => 1, 'title' => 'test']);
25
        $document = $this->client->get('test', $docId);
26
        $this->assertArrayHasKey('title', $document);
27
        $this->assertArrayHasKey('id', $document);
28
        $result = $this->client->delete('test', ['id' => $docId]);
29
        $this->assertTrue($result == 1);
30
    }
31
32
    public function testFindDocuments()
33
    {
34
        $docId1 = $this->client->insert('test', ['id' => 1, 'title' => 'test']);
35
        sleep(1); // waiting to be able to be searchable on elasticsearch.
36
        $results = $this->client->find('test', ['title' => 'test']);
37
        $this->assertArrayHasKey('total', $results);
38
        $this->assertArrayHasKey('data', $results);
39
        $this->assertCount($results['total'], $results['data']);
40
41
        $result = $this->client->delete('test', ['id' => $docId1]);
42
        $this->assertTrue($result == 1);
43
    }
44
45
    public function testInsertUpdateGetDocument()
46
    {
47
//        $docId = $this->client->insert('test', ['id' => 1, 'title' => 'test']);
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
48
//        sleep(1); // waiting to be able to be searchable on elasticsearch.
49
//        $modifiedCount = $this->client->update('test', ['title' => 'test'], ['title' => 'test2']);
50
//        $this->assertTrue($modifiedCount >= 1);
51
//        sleep(1); // waiting to be able to be searchable on elasticsearch.
52
//        $document = $this->client->get('test', $docId);
53
//        $this->assertArrayHasKey('title', $document);
54
//        $this->assertEquals('test2', $document['title']);
55
//
56
//        $result = $this->client->delete('test', ['_id' => $docId]);
57
//        $this->assertTrue($result == 1);
58
    }
59
}
60