Пример #1
0
 /**
  * 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)));
     }
 }
Пример #2
0
 /**
  * @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];
 }
Пример #3
0
 /**
  * {@inheritdoc}
  */
 public function negativeMatch($name, $subject, array $arguments)
 {
     $count = $this->countDifference($subject, (int) $arguments[0]);
     if (self::EQUAL === $count) {
         throw new FailureException(sprintf('Expected %s not to have %s items, but got it.', $this->presenter->presentValue($subject), $this->presenter->presentString((int) $arguments[0])));
     }
     return $subject;
 }
Пример #4
0
 /**
  * @param string $keyword
  * @param mixed  $subject
  * @param array  $arguments
  *
  * @return Matcher
  *
  * @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);
 }
Пример #5
0
 function let(Presenter $presenter)
 {
     $presenter->presentValue(Argument::any())->willReturn('val');
     $presenter->presentString(Argument::any())->willReturnArgument();
     $this->beConstructedWith('custom', function () {
     }, $presenter);
 }
Пример #6
0
 function it_creates_an_accessing_property_on_non_object_exception(Presenter $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);
 }
Пример #7
0
 function let(Presenter $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);
 }
Пример #8
0
 function let(Presenter $presenter)
 {
     $presenter->presentValue(Argument::any())->willReturn('val1', 'val2');
     $presenter->presentString(Argument::any())->willReturnArgument();
     $this->beConstructedWith($presenter);
 }
Пример #9
0
 /**
  * @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 start with %s, but it does.', $this->presenter->presentString($subject), $this->presenter->presentString($arguments[0])));
 }
Пример #10
0
 function let(Presenter $presenter)
 {
     $presenter->presentString(Argument::type('string'))->willReturnArgument();
     $this->beConstructedWith($presenter);
 }
Пример #11
0
 /**
  * @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)));
 }
Пример #12
0
 /**
  * @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');
 }
Пример #13
0
 /**
  * @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))));
 }
Пример #14
0
 /**
  * @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]))));
 }
Пример #15
0
 /**
  * @param string $property
  *
  * @return SubjectException
  */
 public function gettingPropertyOnNonObject($property)
 {
     return new SubjectException(sprintf('Getting property %s on a non-object.', $this->presenter->presentString($property)));
 }