IsEqualIgnoringWhiteSpaceTest.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace Hamcrest\Text;
  3. class IsEqualIgnoringWhiteSpaceTest extends \Hamcrest\AbstractMatcherTest
  4. {
  5. private $_matcher;
  6. public function setUp()
  7. {
  8. $this->_matcher = \Hamcrest\Text\IsEqualIgnoringWhiteSpace::equalToIgnoringWhiteSpace(
  9. "Hello World how\n are we? "
  10. );
  11. }
  12. protected function createMatcher()
  13. {
  14. return $this->_matcher;
  15. }
  16. public function testPassesIfWordsAreSameButWhitespaceDiffers()
  17. {
  18. assertThat('Hello World how are we?', $this->_matcher);
  19. assertThat(" Hello \rWorld \t how are\nwe?", $this->_matcher);
  20. }
  21. public function testFailsIfTextOtherThanWhitespaceDiffers()
  22. {
  23. assertThat('Hello PLANET how are we?', not($this->_matcher));
  24. assertThat('Hello World how are we', not($this->_matcher));
  25. }
  26. public function testFailsIfWhitespaceIsAddedOrRemovedInMidWord()
  27. {
  28. assertThat('HelloWorld how are we?', not($this->_matcher));
  29. assertThat('Hello Wo rld how are we?', not($this->_matcher));
  30. }
  31. public function testFailsIfMatchingAgainstNull()
  32. {
  33. assertThat(null, not($this->_matcher));
  34. }
  35. public function testHasAReadableDescription()
  36. {
  37. $this->assertDescription(
  38. "equalToIgnoringWhiteSpace(\"Hello World how\\n are we? \")",
  39. $this->_matcher
  40. );
  41. }
  42. }