MongoTimestampTest.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace Alcaeus\MongoDbAdapter\Tests;
  3. /**
  4. * @author alcaeus <alcaeus@alcaeus.org>
  5. */
  6. class MongoTimestampTest extends TestCase
  7. {
  8. public function testCreate()
  9. {
  10. $timestamp = new \MongoTimestamp(1234567890, 987654321);
  11. $this->assertAttributeSame(1234567890, 'sec', $timestamp);
  12. $this->assertAttributeSame(987654321, 'inc', $timestamp);
  13. $this->assertSame('1234567890', (string) $timestamp);
  14. $bsonTimestamp = $timestamp->toBSONType();
  15. $this->assertInstanceOf('MongoDB\BSON\Timestamp', $bsonTimestamp);
  16. $this->assertSame('[1234567890:987654321]', (string) $bsonTimestamp);
  17. }
  18. public function testCreateWithGlobalInc()
  19. {
  20. $timestamp1 = new \MongoTimestamp(1234567890);
  21. $timestamp2 = new \MongoTimestamp(1234567890);
  22. $this->assertAttributeSame(0, 'inc', $timestamp1);
  23. $this->assertAttributeSame(1, 'inc', $timestamp2);
  24. }
  25. public function testCreateWithBsonTimestamp()
  26. {
  27. $bsonTimestamp = new \MongoDB\BSON\Timestamp(1234567890, 987654321);
  28. $timestamp = new \MongoTimestamp($bsonTimestamp);
  29. $this->assertAttributeSame(1234567890, 'sec', $timestamp);
  30. $this->assertAttributeSame(987654321, 'inc', $timestamp);
  31. }
  32. }