StringContainsIgnoringCaseTest.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace Hamcrest\Text;
  3. class StringContainsIgnoringCaseTest extends \Hamcrest\AbstractMatcherTest
  4. {
  5. const EXCERPT = 'ExcErPt';
  6. private $_stringContains;
  7. public function setUp()
  8. {
  9. $this->_stringContains = \Hamcrest\Text\StringContainsIgnoringCase::containsStringIgnoringCase(
  10. strtolower(self::EXCERPT)
  11. );
  12. }
  13. protected function createMatcher()
  14. {
  15. return $this->_stringContains;
  16. }
  17. public function testEvaluatesToTrueIfArgumentContainsSpecifiedSubstring()
  18. {
  19. $this->assertTrue(
  20. $this->_stringContains->matches(self::EXCERPT . 'END'),
  21. 'should be true if excerpt at beginning'
  22. );
  23. $this->assertTrue(
  24. $this->_stringContains->matches('START' . self::EXCERPT),
  25. 'should be true if excerpt at end'
  26. );
  27. $this->assertTrue(
  28. $this->_stringContains->matches('START' . self::EXCERPT . 'END'),
  29. 'should be true if excerpt in middle'
  30. );
  31. $this->assertTrue(
  32. $this->_stringContains->matches(self::EXCERPT . self::EXCERPT),
  33. 'should be true if excerpt is repeated'
  34. );
  35. $this->assertFalse(
  36. $this->_stringContains->matches('Something else'),
  37. 'should not be true if excerpt is not in string'
  38. );
  39. $this->assertFalse(
  40. $this->_stringContains->matches(substr(self::EXCERPT, 1)),
  41. 'should not be true if part of excerpt is in string'
  42. );
  43. }
  44. public function testEvaluatesToTrueIfArgumentIsEqualToSubstring()
  45. {
  46. $this->assertTrue(
  47. $this->_stringContains->matches(self::EXCERPT),
  48. 'should be true if excerpt is entire string'
  49. );
  50. }
  51. public function testEvaluatesToTrueIfArgumentContainsExactSubstring()
  52. {
  53. $this->assertTrue(
  54. $this->_stringContains->matches(strtolower(self::EXCERPT)),
  55. 'should be false if excerpt is entire string ignoring case'
  56. );
  57. $this->assertTrue(
  58. $this->_stringContains->matches('START' . strtolower(self::EXCERPT) . 'END'),
  59. 'should be false if excerpt is contained in string ignoring case'
  60. );
  61. }
  62. public function testHasAReadableDescription()
  63. {
  64. $this->assertDescription(
  65. 'a string containing in any case "'
  66. . strtolower(self::EXCERPT) . '"',
  67. $this->_stringContains
  68. );
  69. }
  70. }