Completed
Push — master ( 58c1c3...bed08d )
by Andreu
04:34
created

MongodbAdapterTests   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testFromMongoDate() 0 16 2
A testAsMongoDate() 0 13 2
1
<?php
2
3
4
use Litipk\Jiffy\UniversalTimestamp;
5
6
7
class MongodbAdapterTests extends \PHPUnit_Framework_TestCase
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
8
{
9
    public function testFromMongoDate()
10
    {
11
        if (!extension_loaded('mongodb')) return;
12
13
        $uTs_A = UniversalTimestamp::now();
14
        $uTs_B = UniversalTimestamp::fromMongodbUTCDateTime(
15
            new \MongoDB\BSON\UTCDatetime($uTs_A->asMilliseconds()+1)
16
        );
17
        $uTs_C = UniversalTimestamp::fromMillisecondsTimestamp($uTs_A->asMilliseconds()+2);
18
19
        $this->assertGreaterThanOrEqual(4, 5);
20
21
        $this->assertGreaterThanOrEqual($uTs_A->asMilliseconds(), $uTs_B->asMilliseconds());
22
        $this->assertGreaterThanOrEqual($uTs_B->asMilliseconds(), $uTs_C->asMilliseconds());
23
        $this->assertGreaterThanOrEqual($uTs_A->asMilliseconds(), $uTs_C->asMilliseconds());
24
    }
25
26
    public function testAsMongoDate()
27
    {
28
        if (!extension_loaded('mongodb')) return;
29
30
        $ts1 = UniversalTimestamp::fromMongodbUTCDateTime(
31
            new \MongoDB\BSON\UTCDatetime(UniversalTimestamp::now()->asMilliseconds())
32
        );
33
        $md1 = $ts1->asMongodbUTCDateTime();
34
35
        $this->assertTrue($md1 instanceof \MongoDB\BSON\UTCDatetime);
0 ignored issues
show
Bug introduced by
The class MongoDB\BSON\UTCDatetime does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
36
        $this->assertEquals($ts1->asSeconds(), (int)floor(((int)$md1->__toString())/1000));
37
        $this->assertEquals($ts1->asMilliseconds()%1000, ((int)$md1->__toString())%1000);
38
    }
39
}
40