Scalr\Tests\Functional\Api\V2\SpecSchema\Constraint\Validator::check PHP Method

check() public method

Invokes the validation of an element
public check ( mixed $value, AbstractSpecObject $schema )
$value mixed value what we should check
$schema Scalr\Tests\Functional\Api\V2\SpecSchema\DataTypes\AbstractSpecObject schema value generated of api specification
    public function check($value, $schema)
    {
        if (is_object($schema)) {
            // check object properties
            if (is_object($value)) {
                $this->checkObject($value, isset($schema->entity) ? $schema->entity : $schema);
            }
            // check items
            if (is_array($value)) {
                $this->checkItems($value, $schema);
            }
            //check property types
            if (is_scalar($value) || empty($value)) {
                $this->checkProperty($value, $schema);
            }
            // check required field
            if (isset($schema->required)) {
                $this->checkRequired($value, $schema);
            }
        } else {
            $value = is_array($value) ? get_object_vars(array_shift($value)) : get_object_vars($value);
            $this->appendError(implode(' ,', array_keys($value)), ' properties doesn\'t exist in api definitions');
        }
    }

Usage Example

 /**
  * {@inheritdoc}
  * @see \PHPUnit_Framework_Constraint::matches()
  */
 protected function matches($other)
 {
     $this->validator->check($other, $this->specObject);
     return $this->validator->isValid();
 }