StringStartsWithTest.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace Hamcrest\Text;
  3. class StringStartsWithTest extends \Hamcrest\AbstractMatcherTest
  4. {
  5. const EXCERPT = 'EXCERPT';
  6. private $_stringStartsWith;
  7. public function setUp()
  8. {
  9. $this->_stringStartsWith = \Hamcrest\Text\StringStartsWith::startsWith(self::EXCERPT);
  10. }
  11. protected function createMatcher()
  12. {
  13. return $this->_stringStartsWith;
  14. }
  15. public function testEvaluatesToTrueIfArgumentContainsSpecifiedSubstring()
  16. {
  17. $this->assertTrue(
  18. $this->_stringStartsWith->matches(self::EXCERPT . 'END'),
  19. 'should be true if excerpt at beginning'
  20. );
  21. $this->assertFalse(
  22. $this->_stringStartsWith->matches('START' . self::EXCERPT),
  23. 'should be false if excerpt at end'
  24. );
  25. $this->assertFalse(
  26. $this->_stringStartsWith->matches('START' . self::EXCERPT . 'END'),
  27. 'should be false if excerpt in middle'
  28. );
  29. $this->assertTrue(
  30. $this->_stringStartsWith->matches(self::EXCERPT . self::EXCERPT),
  31. 'should be true if excerpt is at beginning and repeated'
  32. );
  33. $this->assertFalse(
  34. $this->_stringStartsWith->matches('Something else'),
  35. 'should be false if excerpt is not in string'
  36. );
  37. $this->assertFalse(
  38. $this->_stringStartsWith->matches(substr(self::EXCERPT, 1)),
  39. 'should be false if part of excerpt is at start of string'
  40. );
  41. }
  42. public function testEvaluatesToTrueIfArgumentIsEqualToSubstring()
  43. {
  44. $this->assertTrue(
  45. $this->_stringStartsWith->matches(self::EXCERPT),
  46. 'should be true if excerpt is entire string'
  47. );
  48. }
  49. public function testHasAReadableDescription()
  50. {
  51. $this->assertDescription('a string starting with "EXCERPT"', $this->_stringStartsWith);
  52. }
  53. }