コード例 #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
 function let(PresenterInterface $presenter)
 {
     $presenter->presentValue(Argument::any())->willReturn('val');
     $presenter->presentString(Argument::any())->willReturnArgument();
     $this->beConstructedWith('custom', function () {
     }, $presenter);
 }
コード例 #3
0
ファイル: WrappedObject.php プロジェクト: mawaha/tracker
 /**
  * @param array $args
  *
  * @throws \PhpSpec\Exception\Wrapper\SubjectException
  */
 public function beConstructedWith($args)
 {
     if (null === $this->classname) {
         throw new SubjectException(sprintf('You can not set object arguments. Behavior subject is %s.', $this->presenter->presentValue(null)));
     }
     $this->beAnInstanceOf($this->classname, $args);
 }
コード例 #4
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];
 }
コード例 #5
0
 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);
 }
コード例 #6
0
 /**
  * @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);
 }
コード例 #7
0
 function it_writes_a_fail_message_for_a_failing_example(Template $template, ExampleEvent $event, Presenter $presenter)
 {
     $event->getTitle()->willReturn(self::EVENT_TITLE);
     $event->getMessage()->willReturn(self::EVENT_MESSAGE);
     $event->getBacktrace()->willReturn(self::$BACKTRACE);
     $event->getException()->willReturn(new \Exception());
     $template->render(Template::DIR . '/Template/ReportFailed.html', array('title' => self::EVENT_TITLE, 'message' => self::EVENT_MESSAGE, 'backtrace' => self::BACKTRACE, 'code' => self::CODE, 'index' => 1, 'specification' => 1))->shouldBeCalled();
     $presenter->presentException(Argument::cetera())->willReturn(self::CODE);
     $this->write(1);
 }
コード例 #8
0
 /**
  * @param array $args
  *
  * @throws \PhpSpec\Exception\Wrapper\SubjectException
  */
 public function beConstructedWith($args)
 {
     if (null === $this->classname) {
         throw new SubjectException(sprintf('You can not set object arguments. Behavior subject is %s.', $this->presenter->presentValue(null)));
     }
     if ($this->isInstantiated()) {
         throw new SubjectException('You can not change object construction method when it is already instantiated');
     }
     $this->beAnInstanceOf($this->classname, $args);
 }
コード例 #9
0
 /**
  * @param mixed $subject
  * @param array $arguments
  *
  * @return boolean
  */
 protected function matches($subject, array $arguments)
 {
     if (!$this->isRestViewObject($subject)) {
         $this->exception = new FailureException(sprintf('Expected %s to be an instance of FOS\\RestBundle\\View\\View', $this->presenter->presentValue($subject)));
         return false;
     }
     /** @var View $subject */
     $argument = isset($arguments[0]) ? $arguments[0] : [];
     if (!$this->dataMatches($subject, $argument)) {
         $this->exception = new FailureException(sprintf('Expected %s to be a data of the View, but it is not. Instead got: %s', $this->presenter->presentValue($argument['data']), $this->presenter->presentValue($subject->getData())));
         return false;
     }
     if (!$this->statusCodeMatches($subject, $argument)) {
         $this->exception = new FailureException(sprintf('Expected %s to be a status code of the View, but it is not. Instead got: %s', $this->presenter->presentValue($argument['statusCode']), $this->presenter->presentValue($subject->getStatusCode())));
         return false;
     }
     if (!$this->headersMatches($subject, $argument)) {
         $this->exception = new FailureException(sprintf('Expected headers to be %s, but it is not. Instead got: %s. Details: %s', $this->presenter->presentValue($argument['headers']), $this->presenter->presentValue($subject->getHeaders()), $this->matcher->getError()));
         return false;
     }
     if (!$this->serializationGroupsMatches($subject, $argument)) {
         $this->exception = new FailureException(sprintf('Expected serialization group to be %s, but they are not', empty($argument['serializationGroups']) ? 'empty (it\'s impossible!)' : implode(', ', $argument['serializationGroups'])));
         return false;
     }
 }
コード例 #10
0
 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);
 }
コード例 #11
0
ファイル: ThrowMatcher.php プロジェクト: edwardricardo/zenska
 /**
  * @param callable $callable
  * @param array $arguments
  * @param string|null $exception
  *
  * @throws \PhpSpec\Exception\Example\FailureException
  */
 public function verifyNegative($callable, array $arguments, $exception = null)
 {
     try {
         call_user_func_array($callable, $arguments);
     } catch (\Exception $e) {
         if (null === $exception) {
             throw new FailureException(sprintf('Expected to not throw any exceptions, but got %s.', $this->presenter->presentValue($e)));
         }
         if ($e instanceof $exception) {
             $invalidProperties = array();
             if (is_object($exception)) {
                 $exceptionRefl = $this->factory->create($exception);
                 foreach ($exceptionRefl->getProperties() as $property) {
                     if (in_array($property->getName(), self::$ignoredProperties)) {
                         continue;
                     }
                     $property->setAccessible(true);
                     $expected = $property->getValue($exception);
                     $actual = $property->getValue($e);
                     if (null !== $expected && $actual === $expected) {
                         $invalidProperties[] = sprintf('  `%s`=%s', $property->getName(), $this->presenter->presentValue($expected));
                     }
                 }
             }
             $withProperties = '';
             if (count($invalidProperties) > 0) {
                 $withProperties = sprintf(' with' . PHP_EOL . '%s,' . PHP_EOL, implode(",\n", $invalidProperties));
             }
             throw new FailureException(sprintf('Expected to not throw %s exception%s but got it.', $this->presenter->presentValue($exception), $withProperties));
         }
     }
 }
コード例 #12
0
 /**
  * @param string $classname
  * @param array $arguments
  *
  * @throws \PhpSpec\Exception\Wrapper\SubjectException
  */
 public function beAnInstanceOf($classname, array $arguments = array())
 {
     if (!is_string($classname)) {
         throw new SubjectException(sprintf('Behavior subject classname should be a string, %s given.', $this->presenter->presentValue($classname)));
     }
     $this->classname = $classname;
     $unwrapper = new Unwrapper();
     $this->arguments = $unwrapper->unwrapAll($arguments);
     $this->isInstantiated = false;
     $this->factoryMethod = null;
 }
コード例 #13
0
 /**
  * @param string $name
  * @param mixed $subject
  * @param array $arguments
  *
  * @throws \PhpSpec\Exception\Example\FailureException
  * @throws \PhpSpec\Exception\Fracture\MethodNotFoundException
  */
 public function negativeMatch($name, $subject, array $arguments)
 {
     preg_match(self::$regex, $name, $matches);
     $method = ('be' === $matches[1] ? 'is' : 'has') . ucfirst($matches[2]);
     $callable = array($subject, $method);
     if (!method_exists($subject, $method)) {
         throw new MethodNotFoundException(sprintf('Method %s not found.', $this->presenter->presentValue($callable)), $subject, $method, $arguments);
     }
     if (false !== ($result = call_user_func_array($callable, $arguments))) {
         throw $this->getFailureExceptionFor($callable, false, $result);
     }
 }
コード例 #14
0
 /**
  *
  * @param array $arguments        	
  *
  * @return null|string
  * @throws \PhpSpec\Exception\Example\MatcherException
  */
 private function getException(array $arguments)
 {
     if (0 == count($arguments)) {
         return null;
     }
     if (is_string($arguments[0])) {
         return $arguments[0];
     }
     if (is_object($arguments[0]) && $arguments[0] instanceof \Exception) {
         return $arguments[0];
     }
     throw new MatcherException(sprintf("Wrong argument provided in throw matcher.\n" . "Fully qualified classname or exception instance expected,\n" . "Got %s.", $this->presenter->presentValue($arguments[0])));
 }
コード例 #15
0
 /**
  * @param ExampleEvent $event
  */
 protected function printException(ExampleEvent $event)
 {
     if (null === ($exception = $event->getException())) {
         return;
     }
     $title = str_replace('\\', DIRECTORY_SEPARATOR, $event->getSpecification()->getTitle());
     $title = str_pad($title, 50, ' ', STR_PAD_RIGHT);
     $message = $this->presenter->presentException($exception, $this->io->isVerbose());
     if ($exception instanceof PendingException) {
         $this->io->writeln(sprintf('<pending-bg>%s</pending-bg>', $title));
         $this->io->writeln(sprintf('<lineno>%4d</lineno>  <pending>- %s</pending>', $event->getExample()->getFunctionReflection()->getStartLine(), $event->getExample()->getTitle()));
         $this->io->writeln(sprintf('<pending>%s</pending>', lcfirst($message)), 6);
     } elseif (ExampleEvent::FAILED === $event->getResult()) {
         $this->io->writeln(sprintf('<failed-bg>%s</failed-bg>', $title));
         $this->io->writeln(sprintf('<lineno>%4d</lineno>  <failed>✘ %s</failed>', $event->getExample()->getFunctionReflection()->getStartLine(), $event->getExample()->getTitle()));
         $this->io->writeln(sprintf('<failed>%s</failed>', lcfirst($message)), 6);
     } else {
         $this->io->writeln(sprintf('<broken-bg>%s</broken-bg>', $title));
         $this->io->writeln(sprintf('<lineno>%4d</lineno>  <broken>! %s</broken>', $event->getExample()->getFunctionReflection()->getStartLine(), $event->getExample()->getTitle()));
         $this->io->writeln(sprintf('<broken>%s</broken>', lcfirst($message)), 6);
     }
     $this->io->writeln();
 }
コード例 #16
0
 function let(PresenterInterface $presenter)
 {
     $presenter->presentString(Argument::type('string'))->willReturnArgument();
     $this->beConstructedWith($presenter);
 }
コード例 #17
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 be odd, but it is.', $this->presenter->presentValue($subject)));
 }
コード例 #18
0
 /**
  *
  * @param int $index        	
  */
 public function write($index)
 {
     $code = $this->presenter->presentException($this->event->getException(), true);
     $this->template->render(Template::DIR . '/Template/ReportFailed.html', array('title' => htmlentities(strip_tags($this->event->getTitle())), 'message' => htmlentities(strip_tags($this->event->getMessage())), 'backtrace' => $this->formatBacktrace(), 'code' => $code, 'index' => self::$failingExamplesCount++, 'specification' => $index));
 }
コード例 #19
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 match %s regex, but it does.', $this->presenter->presentString($subject), $this->presenter->presentString($arguments[0])));
 }
コード例 #20
0
 function let(PresenterInterface $presenter)
 {
     $presenter->presentValue(Argument::any())->willReturn('countable');
     $presenter->presentString(Argument::any())->willReturnArgument();
     $this->beConstructedWith($presenter);
 }
コード例 #21
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]))));
 }
コード例 #22
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 contain %s, but it does.', $this->presenter->presentValue($subject), $this->presenter->presentValue($arguments[0])));
 }
コード例 #23
0
 function let(PresenterInterface $presenter)
 {
     $presenter->presentValue(Argument::any())->willReturn('val1', 'val2');
     $this->beConstructedWith($presenter);
 }
コード例 #24
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)));
 }
コード例 #25
0
ファイル: CallbackMatcher.php プロジェクト: mawaha/tracker
 /**
  * @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))));
 }
コード例 #26
0
 /**
  * @param mixed $subject
  *
  * @return SubjectException
  */
 private function cantUseAsArray($subject)
 {
     return new SubjectException(sprintf('Can not use %s as array.', $this->presenter->presentValue($subject)));
 }
コード例 #27
0
ファイル: ThrowMatcherSpec.php プロジェクト: focuslife/v0.1
 function let(Unwrapper $unwrapper, PresenterInterface $presenter)
 {
     $unwrapper->unwrapAll(Argument::any())->willReturnArgument();
     $presenter->presentValue(Argument::any())->willReturn('val1', 'val2');
     $this->beConstructedWith($unwrapper, $presenter);
 }
コード例 #28
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 %s relationship on %s but got %s', $this->presenter->presentString($arguments[0]), $this->presenter->presentString($arguments[1]), $this->presenter->presentValue($subject)));
 }
コード例 #29
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 %s, but got one.', $this->presenter->presentValue($subject)));
 }
コード例 #30
0
 /**
  * @param callable $callable
  * @param Boolean  $expectedBool
  * @param Boolean  $result
  *
  * @return FailureException
  */
 private function getFailureExceptionFor($callable, $expectedBool, $result)
 {
     return new FailureException(sprintf("Expected %s to return %s, but got %s.", $this->presenter->presentValue($callable), $this->presenter->presentValue($expectedBool), $this->presenter->presentValue($result)));
 }