/** * Evaluates negative match. * * @param string $name * @param mixed $subject * @param array $arguments * * @throws \PhpSpec\Exception\Example\FailureException * @return boolean */ public function negativeMatch($name, $subject, array $arguments) { $checker = $this->getCheckerName($name); if (call_user_func($checker, $subject)) { throw new FailureException(sprintf('%s not expected to return %s, but it did.', $this->presenter->presentString(sprintf('%s(%s)', $checker, $this->presenter->presentValue($subject))), $this->presenter->presentValue(true))); } }
/** * @param string $name * * @return Collaborator * * @throws \PhpSpec\Exception\Wrapper\CollaboratorException */ public function get($name) { if (!$this->has($name)) { throw new CollaboratorException(sprintf('Collaborator %s not found.', $this->presenter->presentString($name))); } return $this->collaborators[$name]; }
/** * @param $keyword * @param $subject * @param array $arguments * @return mixed * @throws \PhpSpec\Exception\Wrapper\MatcherNotFoundException */ public function find($keyword, $subject, array $arguments) { foreach ($this->matchers as $matcher) { if (true === $matcher->supports($keyword, $subject, $arguments)) { return $matcher; } } throw new MatcherNotFoundException(sprintf('No %s(%s) matcher found for %s.', $this->presenter->presentString($keyword), $this->presenter->presentValue($arguments), $this->presenter->presentValue($subject)), $keyword, $subject, $arguments); }
function let(PresenterInterface $presenter) { $presenter->presentValue(Argument::any())->willReturn('val'); $presenter->presentString(Argument::any())->willReturnArgument(); $this->beConstructedWith('custom', function () { }, $presenter); }
function it_creates_an_accessing_property_on_non_object_exception(PresenterInterface $presenter) { $presenter->presentString("{$this->fixture->property}")->shouldBeCalled()->willReturn("\"{$this->fixture->property}\""); $fixtureMessage = "Getting property \"{$this->fixture->property}\" on a non-object."; $exception = $this->gettingPropertyOnNonObject($this->fixture->property); $exception->shouldHaveType('PhpSpec\\Exception\\Wrapper\\SubjectException'); $exception->getMessage()->shouldBe($fixtureMessage); }
function let(PresenterInterface $presenter) { $presenter->presentValue(Argument::any())->will(function ($subject) { if (is_array($subject[0])) { return 'array'; } if (is_object($subject[0])) { return 'object'; } return $subject[0]; }); $presenter->presentString(Argument::any())->willReturnArgument(); $this->beConstructedWith($presenter); }
function let(PresenterInterface $presenter) { $presenter->presentString(Argument::type('string'))->willReturnArgument(); $this->beConstructedWith($presenter); }
/** * @param string $name * @param mixed $subject * @param array $arguments * * @return FailureException */ protected function getNegativeFailureException($name, $subject, array $arguments) { return new FailureException(sprintf('Expected %s not to match %s regex, but it does.', $this->presenter->presentString($subject), $this->presenter->presentString($arguments[0]))); }
function let(PresenterInterface $presenter) { $presenter->presentValue(Argument::any())->willReturn('countable'); $presenter->presentString(Argument::any())->willReturnArgument(); $this->beConstructedWith($presenter); }
/** * @param string $property * * @return SubjectException */ public function gettingPropertyOnNonObject($property) { return new SubjectException(sprintf('Getting property %s on a non-object.', $this->presenter->presentString($property))); }
/** * @param string $name * @param mixed $subject * @param array $arguments * * @return FailureException */ protected function getNegativeFailureException($name, $subject, array $arguments) { return new FailureException(sprintf('%s not expected to %s(%s), but it did.', $this->presenter->presentValue($subject), $this->presenter->presentString($name), implode(', ', array_map(array($this->presenter, 'presentValue'), $arguments)))); }
/** * @return InterfaceNotImplementedException */ private function interfaceNotImplemented() { return new InterfaceNotImplementedException(sprintf('%s does not implement %s interface, but should.', $this->presenter->presentValue($this->caller->getWrappedObject()), $this->presenter->presentString('ArrayAccess')), $this->caller->getWrappedObject(), 'ArrayAccess'); }
/** * @param string $name * @param mixed $subject * @param array $arguments * * @return FailureException */ protected function getNegativeFailureException($name, $subject, array $arguments) { return new FailureException(sprintf('Did not expect instance of %s, but got %s.', $this->presenter->presentString($arguments[0]), $this->presenter->presentValue($subject))); }
/** * @param string $name * @param mixed $subject * @param array $arguments * * @return FailureException */ protected function getNegativeFailureException($name, $subject, array $arguments) { return new FailureException(sprintf('Expected %s not to have %s items, but got it.', $this->presenter->presentValue($subject), $this->presenter->presentString(intval($arguments[0])))); }