/** * Private access Constructor. */ private function __construct() { $this->formatter = new Formatter(); $this->responder = new ExceptionResponder($this->formatter); $this->assertion = new Assertion($this->responder); $this->assertion->extend(__DIR__ . '/Core/Definitions.php'); }
/** * Register http assertion methods. * * @param Assertion $assertion */ public function __invoke(Assertion $assertion) { /** * Asserts that the allowed headers match the expected array of methods. */ $assertion->addMethod('allow', function ($expected, $message = "") { $this->flag('message', $message); return new AllowedMatcher($expected); }); /** * Asserts that the response has the expected status code. */ $assertion->addMethod('status', function ($expected, $message = "") { $this->flag('message', $message); return new StatusMatcher($expected); }); /** * Property converts response body to json object (or array) and sets it * as the new subject of the assertion chain. */ $assertion->addProperty('json', function ($assoc = false, $depth = 512, $options = 0) { $parser = new JsonParser($this->getActual()); return $this->setActual($parser->getJsonObject($assoc, $depth, $options)); }); }
/** * Compare two values using the given operator. * * @param mixed $left * @param string $operator * @param mixed $right * @param string $message */ public function operator($left, $operator, $right, $message = '') { if (!isset(static::$operators[$operator])) { throw new \InvalidArgumentException("Invalid operator {$operator}"); } $this->assertion->setActual($left); return $this->assertion->{static::$operators[$operator]}($right, $message); }