IsEqualIgnoringWhiteSpaceTest.php 1.4 KB

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