1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10:
11: namespace expect\matcher;
12:
13: use expect\FailedMessage;
14:
15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27:
28: final class ToBeLessThan implements ReportableMatcher
29: {
30: 31: 32:
33: private $actual;
34:
35: 36: 37:
38: private $expected;
39:
40: 41: 42: 43: 44:
45: public function __construct($expected)
46: {
47: $this->expected = $expected;
48: }
49:
50: 51: 52:
53: public function match($actual)
54: {
55: $this->actual = $actual;
56:
57: return $this->actual < $this->expected;
58: }
59:
60: 61: 62:
63: public function reportFailed(FailedMessage $message)
64: {
65: $detail = $this->createDetailMessage();
66: $message->appendText('Expected ')
67: ->appendValue($this->actual)
68: ->appendText(' to be less than ')
69: ->appendValue($this->expected)
70: ->appendText($detail);
71: }
72:
73: 74: 75:
76: public function reportNegativeFailed(FailedMessage $message)
77: {
78: $detail = $this->createDetailMessage(' not');
79: $message->appendText('Expected ')
80: ->appendValue($this->actual)
81: ->appendText(' not to be less than ')
82: ->appendValue($this->expected)
83: ->appendText($detail);
84: }
85:
86: private function createDetailMessage($prefixMessage = '')
87: {
88: $message = FailedMessage::fromString("\n\n");
89: $message->appendText(' expected')
90: ->appendText($prefixMessage)
91: ->appendText(': < ')
92: ->appendValue($this->expected)
93: ->appendText("\n")
94: ->appendSpace(strlen($prefixMessage))
95: ->appendText(' got: ')
96: ->appendValue($this->actual);
97:
98: return (string) $message;
99: }
100: }
101: