| @@ 28-80 (lines=53) @@ | ||
| 25 | * @author Noritaka Horio <[email protected]> |
|
| 26 | * @copyright Noritaka Horio <[email protected]> |
|
| 27 | */ |
|
| 28 | final class ToEndWith implements ReportableMatcher |
|
| 29 | { |
|
| 30 | /** |
|
| 31 | * @var string |
|
| 32 | */ |
|
| 33 | private $actual; |
|
| 34 | ||
| 35 | /** |
|
| 36 | * @var string |
|
| 37 | */ |
|
| 38 | private $pattern; |
|
| 39 | ||
| 40 | /** |
|
| 41 | * @param string $expected pattern keyword |
|
| 42 | */ |
|
| 43 | public function __construct($expected) |
|
| 44 | { |
|
| 45 | $this->pattern = preg_quote($expected, '/'); |
|
| 46 | } |
|
| 47 | ||
| 48 | /** |
|
| 49 | * {@inheritdoc} |
|
| 50 | */ |
|
| 51 | public function match($actual) |
|
| 52 | { |
|
| 53 | $this->actual = $actual; |
|
| 54 | $patternMatcher = new PatternMatcher("/{$this->pattern}$/"); |
|
| 55 | ||
| 56 | return $patternMatcher->match($actual); |
|
| 57 | } |
|
| 58 | ||
| 59 | /** |
|
| 60 | * {@inheritdoc} |
|
| 61 | */ |
|
| 62 | public function reportFailed(FailedMessage $message) |
|
| 63 | { |
|
| 64 | $message->appendText('Expected ') |
|
| 65 | ->appendValue($this->actual) |
|
| 66 | ->appendText(' to end with ') |
|
| 67 | ->appendValue($this->pattern); |
|
| 68 | } |
|
| 69 | ||
| 70 | /** |
|
| 71 | * {@inheritdoc} |
|
| 72 | */ |
|
| 73 | public function reportNegativeFailed(FailedMessage $message) |
|
| 74 | { |
|
| 75 | $message->appendText('Expected ') |
|
| 76 | ->appendValue($this->actual) |
|
| 77 | ->appendText(' not to end with ') |
|
| 78 | ->appendValue($this->pattern); |
|
| 79 | } |
|
| 80 | } |
|
| 81 | ||
| @@ 28-80 (lines=53) @@ | ||
| 25 | * @author Noritaka Horio <[email protected]> |
|
| 26 | * @copyright Noritaka Horio <[email protected]> |
|
| 27 | */ |
|
| 28 | final class ToMatch implements ReportableMatcher |
|
| 29 | { |
|
| 30 | /** |
|
| 31 | * @var string |
|
| 32 | */ |
|
| 33 | private $actual; |
|
| 34 | ||
| 35 | /** |
|
| 36 | * @var string |
|
| 37 | */ |
|
| 38 | private $expected; |
|
| 39 | ||
| 40 | /** |
|
| 41 | * @param string $expected String of a regular expression |
|
| 42 | */ |
|
| 43 | public function __construct($expected) |
|
| 44 | { |
|
| 45 | $this->expected = $expected; |
|
| 46 | } |
|
| 47 | ||
| 48 | /** |
|
| 49 | * {@inheritdoc} |
|
| 50 | */ |
|
| 51 | public function match($actual) |
|
| 52 | { |
|
| 53 | $this->actual = $actual; |
|
| 54 | $patternMatcher = new PatternMatcher($this->expected); |
|
| 55 | ||
| 56 | return $patternMatcher->match($this->actual); |
|
| 57 | } |
|
| 58 | ||
| 59 | /** |
|
| 60 | * {@inheritdoc} |
|
| 61 | */ |
|
| 62 | public function reportFailed(FailedMessage $message) |
|
| 63 | { |
|
| 64 | $message->appendText('Expected ') |
|
| 65 | ->appendValue($this->actual) |
|
| 66 | ->appendText(' to match ') |
|
| 67 | ->appendText($this->expected); |
|
| 68 | } |
|
| 69 | ||
| 70 | /** |
|
| 71 | * {@inheritdoc} |
|
| 72 | */ |
|
| 73 | public function reportNegativeFailed(FailedMessage $message) |
|
| 74 | { |
|
| 75 | $message->appendText('Expected ') |
|
| 76 | ->appendValue($this->actual) |
|
| 77 | ->appendText(' not to match ') |
|
| 78 | ->appendText($this->expected); |
|
| 79 | } |
|
| 80 | } |
|
| 81 | ||
| @@ 28-80 (lines=53) @@ | ||
| 25 | * @author Noritaka Horio <[email protected]> |
|
| 26 | * @copyright Noritaka Horio <[email protected]> |
|
| 27 | */ |
|
| 28 | final class ToStartWith implements ReportableMatcher |
|
| 29 | { |
|
| 30 | /** |
|
| 31 | * @var string |
|
| 32 | */ |
|
| 33 | private $actual; |
|
| 34 | ||
| 35 | /** |
|
| 36 | * @var string |
|
| 37 | */ |
|
| 38 | private $pattern; |
|
| 39 | ||
| 40 | /** |
|
| 41 | * @param string $expected pattern keyword |
|
| 42 | */ |
|
| 43 | public function __construct($expected) |
|
| 44 | { |
|
| 45 | $this->pattern = preg_quote($expected, '/'); |
|
| 46 | } |
|
| 47 | ||
| 48 | /** |
|
| 49 | * {@inheritdoc} |
|
| 50 | */ |
|
| 51 | public function match($actual) |
|
| 52 | { |
|
| 53 | $this->actual = $actual; |
|
| 54 | $patternMatcher = new PatternMatcher("/^{$this->pattern}/"); |
|
| 55 | ||
| 56 | return $patternMatcher->match($actual); |
|
| 57 | } |
|
| 58 | ||
| 59 | /** |
|
| 60 | * {@inheritdoc} |
|
| 61 | */ |
|
| 62 | public function reportFailed(FailedMessage $message) |
|
| 63 | { |
|
| 64 | $message->appendText('Expected ') |
|
| 65 | ->appendValue($this->actual) |
|
| 66 | ->appendText(' to start with ') |
|
| 67 | ->appendValue($this->pattern); |
|
| 68 | } |
|
| 69 | ||
| 70 | /** |
|
| 71 | * {@inheritdoc} |
|
| 72 | */ |
|
| 73 | public function reportNegativeFailed(FailedMessage $message) |
|
| 74 | { |
|
| 75 | $message->appendText('Expected ') |
|
| 76 | ->appendValue($this->actual) |
|
| 77 | ->appendText(' not to start with ') |
|
| 78 | ->appendValue($this->pattern); |
|
| 79 | } |
|
| 80 | } |
|
| 81 | ||