/**
  * @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;
     }
 }
예제 #2
0
 public function test_matcher_with_array_value()
 {
     $value = array('users' => array(array('id' => 1, 'firstName' => 'Norbert', 'lastName' => 'Orzechowicz', 'enabled' => true), array('id' => 2, 'firstName' => 'Michał', 'lastName' => 'Dąbrowski', 'enabled' => true)), 'readyToUse' => true, 'data' => new \stdClass());
     $expecation = array('users' => array(array('id' => '@integer@', 'firstName' => '@string@', 'lastName' => 'Orzechowicz', 'enabled' => '@boolean@'), array('id' => '@integer@', 'firstName' => '@string@', 'lastName' => 'Dąbrowski', 'enabled' => '@boolean@')), 'readyToUse' => true, 'data' => '@wildcard@');
     $this->assertTrue($this->matcher->match($value, $expecation), $this->matcher->getError());
     $this->assertTrue(match($value, $expecation));
 }
예제 #3
0
 public function test_error_when_json_value_does_not_match_json_pattern()
 {
     $pattern = '{"a": @null@, "b": 4}';
     $value = '{"a": null, "b": 5}';
     $this->assertFalse($this->matcher->match($value, $pattern));
     $this->assertSame('"5" does not match "4".', $this->matcher->getError());
 }
 /**
  * {@inheritdoc}
  */
 public function diff($actual, $expected)
 {
     if (!$this->matcher->match($actual, $expected)) {
         return $this->matcher->getError();
     }
 }
 /**
  * @param mixed $other
  *
  * @return null|string
  */
 protected function additionalFailureDescription($other)
 {
     return $this->matcher->getError();
 }
 /**
  * @param string $name
  * @param mixed  $subject
  * @param array  $arguments
  *
  * @return FailureException
  */
 protected function getNegativeFailureException($name, $subject, array $arguments)
 {
     return new FailureException($this->matcher->getError());
 }
예제 #7
0
파일: ApiContext.php 프로젝트: php-lug/lug
 /**
  * @param PyStringNode $json
  *
  * @Then the response should contain:
  */
 public function assertResponseContains(PyStringNode $json)
 {
     $this->matcher->match((string) $this->response->getBody(), $json->getRaw());
     \PHPUnit_Framework_Assert::assertNull($this->matcher->getError());
 }