MongoCodeTest.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace Alcaeus\MongoDbAdapter\Tests;
  3. use Alcaeus\MongoDbAdapter\TypeInterface;
  4. /**
  5. * @author alcaeus <alcaeus@alcaeus.org>
  6. */
  7. class MongoCodeTest extends TestCase
  8. {
  9. public function testCreate()
  10. {
  11. $code = new \MongoCode('code', ['scope' => 'bleh']);
  12. $this->assertAttributeSame('code', 'code', $code);
  13. $this->assertAttributeSame(['scope' => 'bleh'], 'scope', $code);
  14. $this->assertSame('code', (string)$code);
  15. return $code;
  16. }
  17. /**
  18. * @depends testCreate
  19. */
  20. public function testConvertToBson(\MongoCode $code)
  21. {
  22. $this->skipTestUnless($code instanceof TypeInterface);
  23. $bsonCode = $code->toBSONType();
  24. $this->assertInstanceOf('MongoDB\BSON\Javascript', $bsonCode);
  25. }
  26. public function testCreateWithBsonObject()
  27. {
  28. $this->skipTestUnless(in_array(TypeInterface::class, class_implements('MongoCode')));
  29. $bsonCode = new \MongoDB\BSON\Javascript('code', ['scope' => 'bleh']);
  30. $code = new \MongoCode($bsonCode);
  31. $this->assertAttributeSame('', 'code', $code);
  32. $this->assertAttributeSame([], 'scope', $code);
  33. }
  34. }