}); expect($result->isMatch())->to->equal(true); }); it('should return false result if callable throws different type', function () { $result = $this->matcher->match(function () { throw new RuntimeException('hello world'); }); expect($result->isMatch())->to->equal(false); }); it('should throw exception if callable is not valid', function () { $obj = new stdClass(); $matcher = new ExceptionMatcher('DomainException'); expect([$matcher, 'match'])->with([$obj, 'nope'])->to->throw('BadFunctionCallException'); }); it('should return false when function throws no exception', function () { $matcher = new ExceptionMatcher('Exception'); $result = $matcher->match(function () { }); expect($result->isMatch())->to->equal(false); }); context('when inverted', function () { it('should return true result if exceptions are different', function () { $result = $this->matcher->invert()->match(function () { throw new RuntimeException(); }); expect($result->isMatch())->to->equal(true); }); it('should return false result if exceptions are same', function () { $result = $this->matcher->invert()->match(function () { throw new DomainException(); });
$assertion->addMethod('with', function () { return $this->flag('arguments', func_get_args()); }); $assertion->addProperty('loosely', function () { return $this->flag('loosely', true); }); $assertion->addMethod('equal', function ($expected, $message = '') { $this->flag('message', $message); if ($this->flag('loosely')) { return new EqualMatcher($expected); } return new SameMatcher($expected); }); $assertion->addMethod('throw', function ($exceptionType, $exceptionMessage = '', $message = '') { $this->flag('message', $message); $matcher = new ExceptionMatcher($exceptionType); $matcher->setExpectedMessage($exceptionMessage); $matcher->setArguments($this->flag('arguments') ?: []); return $matcher; }); $type = function ($expected, $message = '') { $this->flag('message', $message); return new TypeMatcher($expected); }; $assertion->addMethod('a', $type)->addMethod('an', $type); $include = function ($expected, $message = '') { $this->flag('message', $message); return new InclusionMatcher($expected); }; $assertion->addMethod('include', $include)->addMethod('contain', $include); $contain = function () {