1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10:
11: namespace expect\context;
12:
13: use expect\Context;
14: use expect\MatcherEvaluator;
15: use expect\MatcherFactory;
16: use expect\ResultReporter;
17:
18: class EvaluateContext implements Context
19: {
20: private $actual;
21: private $negated;
22: private $factory;
23: private $reporter;
24:
25: public function __construct(MatcherFactory $factory, ResultReporter $reporter)
26: {
27: $this->actual = null;
28: $this->negated = false;
29: $this->factory = $factory;
30: $this->reporter = $reporter;
31: }
32:
33: public function actual($actual)
34: {
35: $this->actual = $actual;
36:
37: return $this;
38: }
39:
40: public function not()
41: {
42: $this->negated = true;
43:
44: return $this;
45: }
46:
47: public function evaluate($name, $arguments = [])
48: {
49: $matcher = $this->factory->create($name, $arguments);
50:
51: $evaluator = MatcherEvaluator::fromMatcher($matcher);
52:
53: if ($this->negated) {
54: $evaluator->negated();
55: }
56:
57: $result = $evaluator->evaluate($this->actual);
58: $result->reportTo($this->reporter);
59: }
60:
61: public function __call($name, $arguments = [])
62: {
63: if (method_exists($this, $name)) {
64: return call_user_func_array([$this, $name], $arguments);
65: } else {
66: $this->evaluate($name, $arguments);
67: }
68: }
69: }
70: