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

tests/MongodbAdapterTests.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
4
use Litipk\Jiffy\UniversalTimestamp;
5
6
7
class MongodbAdapterTests extends \PHPUnit_Framework_TestCase
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
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