Author: Sebastian Bergmann (sebastian@phpunit.de)
Inheritance: implements Countable, implements PHPUnit_Framework_SelfDescribing
 protected function matches($other)
 {
     if (!$other instanceof ResponseInterface) {
         return false;
     }
     return $this->status->evaluate($other->getStatusCode(), '', true);
 }
Example #2
0
 /**
  * Evaluates the constraint for parameter $other
  *
  * If $returnResult is set to false (the default), an exception is thrown
  * in case of a failure. null is returned otherwise.
  *
  * If $returnResult is true, the result of the evaluation is returned as
  * a boolean value instead: true in case of success, false in case of a
  * failure.
  *
  * @param mixed $other
  *        	Value or object to evaluate.
  * @param string $description
  *        	Additional information about the test
  * @param bool $returnResult
  *        	Whether to return a result or throw an exception
  *        	
  * @return mixed
  *
  * @throws PHPUnit_Framework_ExpectationFailedException
  */
 public function evaluate($other, $description = '', $returnResult = false)
 {
     try {
         return $this->innerConstraint->evaluate($other, $description, $returnResult);
     } catch (PHPUnit_Framework_ExpectationFailedException $e) {
         $this->fail($other, $description);
     }
 }
 protected function matches($other)
 {
     if (!$other instanceof MessageInterface) {
         return false;
     }
     $other->getBody()->rewind();
     $body = $other->getBody()->getContents();
     return $this->constraint->evaluate($body, '', true);
 }
    public function testDefaultSchema()
    {
        $this->constraint = new ResponseBodyConstraint($this->schemaManager, '/pets', 'get', 222);
        $response = <<<JSON
{
  "code": 123456789,
  "message": "foo"
}
JSON;
        $response = json_decode($response);
        self::assertTrue($this->constraint->evaluate($response, '', true), $this->constraint->evaluate($response));
    }
 protected function matches($other)
 {
     if (!$other instanceof MessageInterface) {
         return false;
     }
     if (!$other->hasHeader($this->name)) {
         return false;
     }
     foreach ($other->getHeader($this->name) as $value) {
         if ($this->constraint->evaluate($value, '', true)) {
             return true;
         }
     }
     return false;
 }
 public function __construct($expected, $mainProperty, $secondaryProperty)
 {
     parent::__construct();
     $this->expected = $expected;
     $this->mainProperty = $mainProperty;
     $this->secondaryProperty = $secondaryProperty;
 }
 /**
  * Evaluates the constraint for parameter $other
  *
  * If $returnResult is set to false (the default), an exception is thrown
  * in case of a failure. null is returned otherwise.
  *
  * If $returnResult is true, the result of the evaluation is returned as
  * a boolean value instead: true in case of success, false in case of a
  * failure.
  *
  * @param mixed  $other        Value or object to evaluate.
  * @param string $description  Additional information about the test
  * @param bool   $returnResult Whether to return a result or throw an exception
  *
  * @return mixed
  *
  * @throws PHPUnit_Framework_ExpectationFailedException
  */
 public function evaluate($other, $description = '', $returnResult = FALSE)
 {
     $success = TRUE;
     foreach ($other as $item) {
         if (!$this->constraint->evaluate($item, '', TRUE)) {
             $success = FALSE;
             break;
         }
     }
     if ($returnResult) {
         return $success;
     }
     if (!$success) {
         $this->fail($other, $description);
     }
 }
 /**
  * @param int|float $lowerBoundary
  * @param int|float $upperBoundary
  * @param bool      $onBoundary    pass if value is same as a boundary value, or false; value must be within the boundaries values
  */
 public function __construct($lowerBoundary, $upperBoundary, $onBoundary)
 {
     parent::__construct();
     $this->lowerBoundary = $lowerBoundary;
     $this->upperBoundary = $upperBoundary;
     $this->onBoundary = $onBoundary;
 }
 /**
  * Evaluates the constraint for parameter $other
  *
  * If $returnResult is set to false (the default), an exception is thrown
  * in case of a failure. null is returned otherwise.
  *
  * If $returnResult is true, the result of the evaluation is returned as
  * a boolean value instead: true in case of success, false in case of a
  * failure.
  *
  * @param mixed  $other        Value or object to evaluate.
  * @param string $description  Additional information about the test
  * @param bool   $returnResult Whether to return a result or throw an exception
  *
  * @return mixed
  *
  * @throws PHPUnit_Framework_ExpectationFailedException
  */
 public function evaluate($other, $description = '', $returnResult = false)
 {
     $success = true;
     foreach ($other as $item) {
         if (!$this->constraint->evaluate($item, '', true)) {
             $success = false;
             break;
         }
     }
     if ($returnResult) {
         return $success;
     }
     if (!$success) {
         $this->fail($other, $description);
     }
 }
 public function __construct(string $className, string $methodName, int $paramIndex)
 {
     parent::__construct();
     $this->className = $className;
     $this->methodName = $methodName;
     $this->paramIndex = $paramIndex;
 }
 /**
  * @param int $type
  */
 public function __construct($type)
 {
     parent::__construct();
     switch ($type) {
         case self::TYPE_BOOL:
             $this->testFunction = 'is_bool';
             $this->type = 'bool';
             break;
         case self::TYPE_INT:
             $this->testFunction = 'is_int';
             $this->type = 'int';
             break;
         case self::TYPE_STRING:
             $this->testFunction = 'is_string';
             $this->type = 'string';
             break;
         case self::TYPE_FLOAT:
             $this->testFunction = 'is_float';
             $this->type = 'float';
             break;
         case self::TYPE_ARRAY:
             $this->testFunction = 'is_array';
             $this->type = 'array';
             break;
         case self::TYPE_SCALAR:
             $this->testFunction = 'is_scalar';
             $this->type = 'scalar';
             break;
         default:
             throw new \InvalidArgumentException(sprintf('Unknown ScalarConstraint type "%s" provided.', is_object($type) ? get_class($type) : (null === $type ? 'null' : gettype($type) . '#' . $type)));
     }
 }
 /**
  * Constructor
  *
  * @param string $header Cache debug header; defaults to X-Cache-Debug
  */
 public function __construct($header = null)
 {
     if ($header) {
         $this->header = $header;
     }
     parent::__construct();
 }
 /**
  * Construct the class.
  *
  * @since 0.1.0
  *
  * @param string $table
  * @param string $column
  * @param string $prefix
  */
 public function __construct($table, $column, $prefix)
 {
     parent::__construct();
     $this->table = esc_sql($table);
     $this->column = esc_sql($column);
     $this->prefix = $prefix;
 }
 /**
  * @param int|string $permissions
  */
 public function __construct($permissions)
 {
     parent::__construct();
     if (is_string($permissions)) {
         if (!ctype_digit($permissions)) {
             if (1 !== preg_match(self::$permissionFormat, $permissions)) {
                 throw new \InvalidArgumentException(sprintf('Permission to match "%s" is not formatted correctly.', $permissions));
             }
             $this->permissions = $permissions;
             return;
         }
         if ('0' === $permissions[0]) {
             $permissions = intval($permissions, 8);
         } else {
             $permissions = (int) $permissions;
         }
     }
     if (!is_int($permissions)) {
         if (is_object($permissions)) {
             $type = sprintf('%s#%s', get_class($permissions), method_exists($permissions, '__toString') ? $permissions->__toString() : '');
         } elseif (null === $permissions) {
             $type = 'null';
         } else {
             $type = gettype($permissions) . '#' . $permissions;
         }
         throw new \InvalidArgumentException(sprintf('Invalid value for permission to match "%s", expected int >= 0 or string.', $type));
     }
     if ($permissions < 0) {
         throw new \InvalidArgumentException(sprintf('Invalid value for permission to match "%d", expected >= 0.', $permissions));
     }
     $this->permissions = $permissions;
 }
 public function __construct($expected, $mainProperty, $secondaryProperty)
 {
     parent::__construct();
     $this->expected = is_array($expected) ? $expected : [$expected];
     $this->mainProperty = $mainProperty;
     $this->secondaryProperty = $secondaryProperty;
 }
    public function testInvalidHeaderType()
    {
        $headers = ['Content-Type' => 'application/json'];
        self::assertFalse($this->constraint->evaluate($headers, '', true));
        try {
            $this->constraint->evaluate($headers);
            self::fail('Expected ExpectationFailedException to be thrown');
        } catch (ExpectationFailedException $e) {
            self::assertEquals(<<<EOF
Failed asserting that {"Content-Type":"application\\/json"} is valid.
[etag] The property etag is required

EOF
, TestFailure::exceptionToString($e));
        }
    }
Example #17
0
 /**
  * Creates NumArrayEqual
  *
  * @param \NumPHP\Core\NumArray $value expected NumArray
  *
  * @since 1.0.0
  */
 public function __construct(NumArray $value)
 {
     parent::__construct();
     $this->value = clone $value;
     // flush the cache
     $this->value->flushCache();
 }
Example #18
0
 /**
  * @param mixed $value
  * @param bool  $checkForObjectIdentity
  * @param bool  $checkForNonObjectIdentity
  */
 public function __construct($value, bool $checkForObjectIdentity = true, bool $checkForNonObjectIdentity = false)
 {
     parent::__construct();
     $this->checkForObjectIdentity = $checkForObjectIdentity;
     $this->checkForNonObjectIdentity = $checkForNonObjectIdentity;
     $this->value = $value;
 }
 /**
  * @param object $schema
  * @param string|null $context
  */
 public function __construct($schema, $context = null)
 {
     parent::__construct();
     $this->schema = $schema;
     $this->context = $context ?: 'schema';
     $this->validator = new Validator($this->context);
 }
Example #20
0
 /**
  * @param  callable                    $callback
  * @throws PHPUnit_Framework_Exception
  */
 public function __construct($callback)
 {
     if (!is_callable($callback)) {
         throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'callable');
     }
     parent::__construct();
     $this->callback = $callback;
 }
Example #21
0
 /**
  * @param  string                      $type
  * @throws PHPUnit_Framework_Exception
  */
 public function __construct($type)
 {
     parent::__construct();
     if (!isset($this->types[$type])) {
         throw new PHPUnit_Framework_Exception(sprintf('Type specified for PHPUnit_Framework_Constraint_IsType <%s> ' . 'is not a valid type.', $type));
     }
     $this->type = $type;
 }
 /**
  * Overridden function to cover differences between PHPUnit 3.5 and 3.6.
  * Intentionally made final so people have to use match() from now on.
  * match() should be abstract really, but isn't, the usual PHPUnit quality...
  *
  * @param      mixed  The item to evaluate.
  * @param      string Additional information about the test (3.6+).
  * @param      bool   Whether to return a result or throw an exception (3.6+).
  *
  * @author     David Zülke <*****@*****.**>
  * @since      1.0.7
  */
 public function evaluate($other, $description = '', $returnResult = false)
 {
     if (version_compare(PHPUnit_Runner_Version::id(), '3.6', '<')) {
         return $this->matches($other);
     } else {
         return parent::evaluate($other, $description, $returnResult);
     }
 }
 /**
  * @param  int                         $value
  * @throws PHPUnit_Framework_Exception
  */
 public function __construct($value)
 {
     if (!is_int($value)) {
         throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'integer');
     }
     parent::__construct();
     $this->value = $value;
 }
Example #24
0
 /**
  * @param string $expectedCommand The expected, executed command substring
  */
 public function __construct($expectedCommand)
 {
     if (!is_string($expectedCommand)) {
         throw new \InvalidArgumentException('Expected command should be a string, ' . gettype($expectedCommand) . ' given');
     }
     $this->expectedCommand = $expectedCommand;
     parent::__construct();
 }
 /**
  * @param  array|ArrayAccess           $value
  * @throws PHPUnit_Framework_Exception
  */
 public function __construct($value)
 {
     parent::__construct();
     if (!(is_array($value) || $value instanceof ArrayAccess)) {
         throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'array or ArrayAccess');
     }
     $this->value = $value;
 }
Example #26
0
 public function __construct($value)
 {
     parent::__construct();
     if (!is_string($value)) {
         throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
     }
     $this->value = $value;
 }
 public function __construct(array $constraints, $autoConfigureGroups = true, $implicitGroupName = null)
 {
     parent::__construct();
     $this->constraintTypes = array_filter($constraints, 'is_string');
     $this->constraints = array_filter($constraints, 'is_object');
     $this->autoConfigureGroups = $autoConfigureGroups;
     $this->implicitGroupName = $implicitGroupName;
 }
 /**
  * @param SchemaManager $schemaManager
  * @param string $path Swagger path template.
  * @param string $httpMethod
  * @param int $httpCode
  */
 public function __construct(SchemaManager $schemaManager, $path, $httpMethod, $httpCode)
 {
     parent::__construct();
     $this->schemaManager = $schemaManager;
     $this->path = $path;
     $this->httpMethod = $httpMethod;
     $this->httpCode = $httpCode;
 }
Example #29
0
 /**
  * @param mixed $value
  * @param float $delta
  * @param int   $maxDepth
  * @param bool  $canonicalize
  * @param bool  $ignoreCase
  */
 public function __construct($value, float $delta = 0.0, int $maxDepth = 10, bool $canonicalize = false, bool $ignoreCase = false)
 {
     parent::__construct();
     $this->value = $value;
     $this->delta = $delta;
     $this->maxDepth = $maxDepth;
     $this->canonicalize = $canonicalize;
     $this->ignoreCase = $ignoreCase;
 }
 /**
  * Evaluates the constraint for parameter $other. Returns TRUE if the
  * constraint is met, FALSE otherwise.
  *
  * @param mixed $other Value or object to evaluate.
  * @return bool
  */
 public function evaluate($other)
 {
     foreach ($other as $item) {
         if (!$this->constraint->evaluate($item)) {
             return FALSE;
         }
     }
     return TRUE;
 }