MongoBinDataTest.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 MongoBinDataTest extends TestCase
  9. {
  10. public function testCreate()
  11. {
  12. $bin = new \MongoBinData('foo', \MongoBinData::FUNC);
  13. $this->assertAttributeSame('foo', 'bin', $bin);
  14. $this->assertAttributeSame(\MongoBinData::FUNC, 'type', $bin);
  15. $this->assertSame('<Mongo Binary Data>', (string)$bin);
  16. return $bin;
  17. }
  18. /**
  19. * @depends testCreate
  20. */
  21. public function testConvertToBson(\MongoBinData $bin)
  22. {
  23. $this->skipTestUnless($bin instanceof TypeInterface);
  24. $bsonBinary = $bin->toBSONType();
  25. $this->assertInstanceOf('MongoDB\BSON\Binary', $bsonBinary);
  26. $this->assertSame('foo', $bsonBinary->getData());
  27. $this->assertSame(\MongoDB\BSON\Binary::TYPE_FUNCTION, $bsonBinary->getType());
  28. }
  29. public function testCreateWithBsonBinary()
  30. {
  31. $this->skipTestUnless(in_array(TypeInterface::class, class_implements('MongoBinData')));
  32. $bsonBinary = new \MongoDB\BSON\Binary('foo', \MongoDB\BSON\Binary::TYPE_UUID);
  33. $bin = new \MongoBinData($bsonBinary);
  34. $this->assertAttributeSame('foo', 'bin', $bin);
  35. $this->assertAttributeSame(\MongoBinData::UUID_RFC4122, 'type', $bin);
  36. }
  37. }