StringEndsWithTest.php 1.9KB

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