StringEndsWith.php 755 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace Hamcrest\Text;
  3. /*
  4. Copyright (c) 2009 hamcrest.org
  5. */
  6. /**
  7. * Tests if the argument is a string that ends with a substring.
  8. */
  9. class StringEndsWith extends SubstringMatcher
  10. {
  11. public function __construct($substring)
  12. {
  13. parent::__construct($substring);
  14. }
  15. /**
  16. * Matches if value is a string that ends with $substring.
  17. *
  18. * @factory
  19. */
  20. public static function endsWith($substring)
  21. {
  22. return new self($substring);
  23. }
  24. // -- Protected Methods
  25. protected function evalSubstringOf($string)
  26. {
  27. return (substr($string, (-1 * strlen($this->_substring))) === $this->_substring);
  28. }
  29. protected function relationship()
  30. {
  31. return 'ending with';
  32. }
  33. }