MongoRegexTest.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace Alcaeus\MongoDbAdapter\Tests;
  3. use Alcaeus\MongoDbAdapter\TypeInterface;
  4. /**
  5. * @author alcaeus <alcaeus@alcaeus.org>
  6. */
  7. class MongoRegexTest extends TestCase
  8. {
  9. public function testCreate()
  10. {
  11. $regex = new \MongoRegex('/abc/i');
  12. $this->assertAttributeSame('abc', 'regex', $regex);
  13. $this->assertAttributeSame('i', 'flags', $regex);
  14. $this->assertSame('/abc/i', (string) $regex);
  15. return $regex;
  16. }
  17. /**
  18. * @depends testCreate
  19. */
  20. public function testConvertToBson(\MongoRegex $regex)
  21. {
  22. $this->skipTestUnless($regex instanceof TypeInterface);
  23. $bsonRegex = $regex->toBSONType();
  24. $this->assertInstanceOf('MongoDB\BSON\Regex', $bsonRegex);
  25. $this->assertSame('abc', $bsonRegex->getPattern());
  26. $this->assertSame('i', $bsonRegex->getFlags());
  27. }
  28. public function testCreateWithBsonType()
  29. {
  30. $this->skipTestUnless(in_array(TypeInterface::class, class_implements('MongoRegex')));
  31. $bsonRegex = new \MongoDB\BSON\Regex('abc', 'i');
  32. $regex = new \MongoRegex($bsonRegex);
  33. $this->assertAttributeSame('abc', 'regex', $regex);
  34. $this->assertAttributeSame('i', 'flags', $regex);
  35. }
  36. }