MongoTimestampTest.php 1.6 KB

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