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
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);
36
        $this->assertEquals($ts1->asSeconds(), (int)floor(((int)$md1->__toString())/1000));
37
        $this->assertEquals($ts1->asMilliseconds()%1000, ((int)$md1->__toString())%1000);
38
    }
39
}
40