1: <?php
2: namespace Peridot\Leo\Matcher;
3:
4: use Peridot\Leo\Matcher\Template\ArrayTemplate;
5: use Peridot\Leo\Matcher\Template\TemplateInterface;
6:
7: /**
8: * LessThanOrEqualMatcher determines if an actual value is less than or equal to the expected value.
9: *
10: * @package Peridot\Leo\Matcher
11: */
12: class LessThanOrEqualMatcher extends CountableMatcher
13: {
14: /**
15: * Match that the actual number is less than or equal
16: * to the expected value.
17: *
18: * @param $number
19: * @return bool
20: */
21: protected function matchNumeric($number)
22: {
23: return $number <= $this->expected;
24: }
25:
26: /**
27: * {@inheritdoc}
28: *
29: * @return TemplateInterface
30: */
31: public function getDefaultTemplate()
32: {
33: return new ArrayTemplate([
34: 'default' => 'Expected {{actual}} to be at most {{expected}}',
35: 'negated' => 'Expected {{actual}} to be above {{expected}}'
36: ]);
37: }
38:
39: /**
40: * {@inheritdoc}
41: *
42: * @return TemplateInterface
43: */
44: public function getDefaultCountableTemplate()
45: {
46: $count = $this->getCount();
47: return new ArrayTemplate([
48: 'default' => "Expected {{actual}} to have a length at most {{expected}} but got $count",
49: 'negated' => 'Expected {{actual}} to have a length above {{expected}}'
50: ]);
51: }
52: }
53: