MongoCodeTest.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 MongoCodeTest extends TestCase
  9. {
  10. public function testCreate()
  11. {
  12. $code = new \MongoCode('code', ['scope' => 'bleh']);
  13. $this->assertAttributeSame('code', 'code', $code);
  14. $this->assertAttributeSame(['scope' => 'bleh'], 'scope', $code);
  15. $this->assertSame('code', (string) $code);
  16. return $code;
  17. }
  18. /**
  19. * @depends testCreate
  20. */
  21. public function testConvertToBson(\MongoCode $code)
  22. {
  23. $this->skipTestUnless($code instanceof TypeInterface);
  24. $bsonCode = $code->toBSONType();
  25. $this->assertInstanceOf('MongoDB\BSON\Javascript', $bsonCode);
  26. }
  27. public function testCreateWithBsonObject()
  28. {
  29. $this->skipTestUnless(in_array(TypeInterface::class, class_implements('MongoCode')));
  30. $bsonCode = new \MongoDB\BSON\Javascript('code', ['scope' => 'bleh']);
  31. $code = new \MongoCode($bsonCode);
  32. $this->assertAttributeSame('code', 'code', $code);
  33. $this->assertAttributeSame(['scope' => 'bleh'], 'scope', $code);
  34. }
  35. }