MongoBinDataTest.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace Alcaeus\MongoDbAdapter\Tests;
  3. use Alcaeus\MongoDbAdapter\TypeInterface;
  4. /**
  5. * @author alcaeus <alcaeus@alcaeus.org>
  6. */
  7. class MongoBinDataTest extends TestCase
  8. {
  9. public function testCreate()
  10. {
  11. $bin = new \MongoBinData('foo', \MongoBinData::FUNC);
  12. $this->assertAttributeSame('foo', 'bin', $bin);
  13. $this->assertAttributeSame(\MongoBinData::FUNC, 'type', $bin);
  14. $this->assertSame('<Mongo Binary Data>', (string)$bin);
  15. return $bin;
  16. }
  17. /**
  18. * @depends testCreate
  19. */
  20. public function testConvertToBson(\MongoBinData $bin)
  21. {
  22. $this->skipTestUnless($bin instanceof TypeInterface);
  23. $bsonBinary = $bin->toBSONType();
  24. $this->assertInstanceOf('MongoDB\BSON\Binary', $bsonBinary);
  25. $this->assertSame('foo', $bsonBinary->getData());
  26. $this->assertSame(\MongoDB\BSON\Binary::TYPE_FUNCTION, $bsonBinary->getType());
  27. }
  28. public function testCreateWithBsonBinary()
  29. {
  30. $this->skipTestUnless(in_array(TypeInterface::class, class_implements('MongoBinData')));
  31. $bsonBinary = new \MongoDB\BSON\Binary('foo', \MongoDB\BSON\Binary::TYPE_UUID);
  32. $bin = new \MongoBinData($bsonBinary);
  33. $this->assertAttributeSame('foo', 'bin', $bin);
  34. $this->assertAttributeSame(\MongoBinData::UUID_RFC4122, 'type', $bin);
  35. }
  36. }