StringContainsInOrderTest.php 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace Hamcrest\Text;
  3. class StringContainsInOrderTest extends \Hamcrest\AbstractMatcherTest
  4. {
  5. private $_m;
  6. public function setUp()
  7. {
  8. $this->_m = \Hamcrest\Text\StringContainsInOrder::stringContainsInOrder(array('a', 'b', 'c'));
  9. }
  10. protected function createMatcher()
  11. {
  12. return $this->_m;
  13. }
  14. public function testMatchesOnlyIfStringContainsGivenSubstringsInTheSameOrder()
  15. {
  16. $this->assertMatches($this->_m, 'abc', 'substrings in order');
  17. $this->assertMatches($this->_m, '1a2b3c4', 'substrings separated');
  18. $this->assertDoesNotMatch($this->_m, 'cab', 'substrings out of order');
  19. $this->assertDoesNotMatch($this->_m, 'xyz', 'no substrings in string');
  20. $this->assertDoesNotMatch($this->_m, 'ac', 'substring missing');
  21. $this->assertDoesNotMatch($this->_m, '', 'empty string');
  22. }
  23. public function testAcceptsVariableArguments()
  24. {
  25. $this->assertMatches(stringContainsInOrder('a', 'b', 'c'), 'abc', 'substrings as variable arguments');
  26. }
  27. public function testHasAReadableDescription()
  28. {
  29. $this->assertDescription(
  30. 'a string containing "a", "b", "c" in order',
  31. $this->_m
  32. );
  33. }
  34. }