MongoRegexTest.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 MongoRegexTest extends TestCase
  9. {
  10. public function testCreate()
  11. {
  12. $regex = new \MongoRegex('/abc/i');
  13. $this->assertSame('abc', $regex->regex);
  14. $this->assertSame('i', $regex->flags);
  15. $this->assertSame('/abc/i', (string) $regex);
  16. return $regex;
  17. }
  18. /**
  19. * @depends testCreate
  20. */
  21. public function testConvertToBson(\MongoRegex $regex)
  22. {
  23. $this->skipTestUnless($regex instanceof TypeInterface);
  24. $bsonRegex = $regex->toBSONType();
  25. $this->assertInstanceOf('MongoDB\BSON\Regex', $bsonRegex);
  26. $this->assertSame('abc', $bsonRegex->getPattern());
  27. $this->assertSame('i', $bsonRegex->getFlags());
  28. }
  29. public function testCreateWithBsonType()
  30. {
  31. $this->skipTestUnless(in_array(TypeInterface::class, class_implements('MongoRegex')));
  32. $bsonRegex = new \MongoDB\BSON\Regex('abc', 'i');
  33. $regex = new \MongoRegex($bsonRegex);
  34. $this->assertSame('abc', $regex->regex);
  35. $this->assertSame('i', $regex->flags);
  36. }
  37. }