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
|
|||
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 dependenciesPHP Analyzer uses your Are you sure this class is defined by one of your dependencies, or did you maybe
not list a dependency in either the 2. Missing use statementPHP does not complain about undefined classes in 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 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.