MongoTimestampTest.php 1.6 KB

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