菜谱项目

StringContainsIgnoringCaseTest.php 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. }