Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function getInstance(Constraint $constraint)
 {
     $className = $constraint->validatedBy();
     if (!isset($this->validators[$className]) || $className === 'Symfony\\Component\\Validator\\Constraints\\CollectionValidator') {
         $this->validators[$className] = new $className();
     }
     return $this->validators[$className];
 }
Ejemplo n.º 2
0
 /**
  * Search in $scopeModule for test cases that uses page class in $pageModule
  * Only check classes in TestCase and Constraint
  *
  * @param $scopeModule
  * @param $pageModule
  * @return array
  */
 protected function getTestClassesByCrossModulePageReference($scopeModule, $pageModule)
 {
     $affectedTestCases = [];
     $testCases = $this->getTestClassesByType(self::CLASS_TYPE_TESTCASE, $scopeModule);
     $constraints = $this->getTestClassesByType(self::CLASS_TYPE_CONSTRAINT, $scopeModule);
     $pattern = str_replace('_', '\\', $pageModule) . '\\Test\\Page';
     /** @var $testCaseClass \ReflectionClass */
     foreach ($testCases as $testCaseClassName => $testCaseClass) {
         $testClassFileName = $testCaseClass->getFileName();
         if ($this->matchFileContentIgnoreCase($testClassFileName, $pattern)) {
             $affectedTestCases[$testCaseClassName] = $testCaseClassName;
         }
     }
     /** @var $constraintClass \ReflectionClass */
     foreach ($constraints as $constraintClassName => $constraintClass) {
         $constraintClassFileName = $constraintClass->getFileName();
         if ($this->matchFileContentIgnoreCase($constraintClassFileName, $pattern)) {
             $constraintName = lcfirst($constraintClass->getShortName());
             $testCases = $this->constraintChecker->getTestCasesByConstraintReference($constraintName);
             foreach ($testCases as $testCase) {
                 $moduleName = $this->mapClassNameToModule($testCase);
                 if ($moduleName == $scopeModule) {
                     $affectedTestCases[$testCase] = $testCase;
                 }
             }
         }
     }
     return $affectedTestCases;
 }
Ejemplo n.º 3
0
 public function validate($data)
 {
     parent::validate($data);
     if (preg_match("/" . str_replace("/", "\\/", $this->value) . "/", $data) === 0) {
         $this->throwException("ValueException", "The data did not match the pattern " . (empty($this->format) ? "({$this->value})" : "for {$this->format}"), $data);
     }
 }
 function __construct($args = array(), $isSimpleInstance = false)
 {
     $this->setWithTable("test_i005_recipiente");
     $this->addAttribute("material", Datatypes::TEXT);
     $this->addAttribute("capacidad", Datatypes::FLOAT_NUMBER);
     $this->addAttribute("tieneTapa", Datatypes::BOOLEAN);
     $this->addConstraints("material", array(Constraint::maxLength(30), Constraint::blank(false)));
     $this->addConstraints("capacidad", array(Constraint::between(0.0, 10.0)));
     $this->addConstraints("tieneTapa", array(Constraint::nullable(true)));
     /*
     $this->constraints = array (
        "material" => array (
           Constraint :: maxLength(30),
           Constraint :: blank(false)
        ),
        "capacidad" => array (
           Constraint :: between(0.0, 10.0)
        ),
        "tieneTapa" => array (
           Constraint :: nullable(true)
        )
     );
     */
     parent::__construct($args, $isSimpleInstance);
 }
Ejemplo n.º 5
0
 public function __construct($columns, $name = null)
 {
     if (empty($name)) {
         $name = 'key_' . uniqid();
     }
     parent::__construct($columns, $name);
 }
Ejemplo n.º 6
0
 function __construct($args = array(), $isSimpleInstance = false)
 {
     $this->setWithTable("test_i006_vaso1");
     $this->addAttribute("marca", Datatypes::TEXT);
     // TODO: seria bueno probar una Constraint de que el volumen
     // del contenido no pueda ser mayor que la capacidad del recipiente.
     $this->addHasOne("contenido", "Contenido1");
     parent::__construct($args, $isSimpleInstance);
     // WARNING:
     // para definir una restriccion sobre un atributo de la superclase,
     // debe inicializarse la superclase primero.
     $this->addConstraints("material", array(Constraint::maxLength(30), Constraint::blank(false), Constraint::inList(array("vidrio", "plastico"))));
     $this->addConstraints("marca", array(Constraint::nullable(true)));
     /*
     $this->constraints = array (
        "material" => array (
           Constraint :: maxLength(30),
           Constraint :: blank(false),
           Constraint :: inList( array("vidrio","plastico") ) // TODO: probar si se verifican estas restricciones para Vaso o si se verifican las de Recipiente...
        ),
        "marca" => array (
           Constraint :: nullable(true)
        )
     );
     */
     // WARNING: atributos del padre se inicializan luego de inicializar el padre!
     // Supongo que estos vasos no tienen tapa
     $this->setTieneTapa(false);
 }
Ejemplo n.º 7
0
 function __construct($args = array(), $isSimpleInstance = false)
 {
     $this->setWithTable('test_issue37_ccc');
     $this->addAttribute('attrCCC', Datatypes::TEXT);
     $this->addConstraints('attrCCC', array(Constraint::minLength(5)));
     parent::__construct($args, $isSimpleInstance);
 }
Ejemplo n.º 8
0
 public function __construct(string $name, array $columns, string $schema, string $table, string $column)
 {
     parent::__construct(Constraint::TYPE_FOREIGN, $name, $columns);
     $this->schema = $schema;
     $this->table = $table;
     $this->column = $column;
 }
Ejemplo n.º 9
0
 function __construct($args = array(), $isSimpleInstance = false)
 {
     $this->setWithTable('test_002_cara');
     $this->addAttribute('color', Datatypes::TEXT);
     $this->addHasOne('nariz', 'Nariz');
     $this->addConstraints('color', array(Constraint::inList(array('blanco', 'negro', 'pardo')), Constraint::nullable(true)));
     parent::__construct($args, $isSimpleInstance);
 }
Ejemplo n.º 10
0
 function __construct($args = array(), $isSimpleInstance = false)
 {
     $this->setWithTable("test_002_nariz");
     $this->belongsTo = array('Cara');
     $this->addAttribute("tamanio", Datatypes::TEXT);
     $this->addConstraints("tamanio", array(Constraint::inList(array("chica", "mediana", "grande"))));
     parent::__construct($args, $isSimpleInstance);
 }
Ejemplo n.º 11
0
 function __construct($args = array(), $isSimpleInstance = false)
 {
     $this->setWithTable("hello_world_persona");
     $this->addAttribute("nombre", Datatypes::TEXT);
     $this->addAttribute("edad", Datatypes::INT_NUMBER);
     $this->addConstraints("nombre", array(Constraint::maxLength(30), Constraint::blank(false)));
     $this->addConstraints("edad", array(Constraint::between(10, 100)));
     parent::__construct($args, $isSimpleInstance);
 }
Ejemplo n.º 12
0
 public function validate($data)
 {
     parent::validate($data);
     foreach ($this->value as $field) {
         if (!isset($data->{$field})) {
             $this->throwException("RequirementException", "A required field was missing", $field);
         }
     }
 }
Ejemplo n.º 13
0
 function __construct($args = array(), $isSimpleInstance = false)
 {
     $this->setWithTable("test_m003_mano");
     $this->addHasMany('dedos', 'Dedo');
     // La unica diferencia con respecto al test i005
     $this->addAttribute("tamanio", Datatypes::TEXT);
     $this->addConstraints("tamanio", array(Constraint::inList(array("grande", "mediana", "chica"))));
     parent::__construct($args, $isSimpleInstance);
 }
Ejemplo n.º 14
0
 /**
  * Constructs a new index.
  *
  * @param string|null $name the name of the index
  * @param string|null $table the table for which the index should be created
  * @param boolean $unique <code>true</code> for a unique index
  * @param array $fields an array of fields for which this index is created
  */
 public function __construct($name = null, $table = null, $unique = true, $fields = array())
 {
     assert(is_null($name) || is_string($name));
     assert(is_null($table) || is_string($table));
     assert(is_bool($unique));
     assert(is_array($fields));
     $this->unique = $unique;
     $this->fields = $fields;
     parent::__construct($name, $table);
 }
Ejemplo n.º 15
0
 public function fixConstraint($constraint)
 {
     if (Constraint::isDisjunctive($constraint)) {
         $constraint = Constraint::findMax(explode('|', $constraint));
     }
     $pos = strpos($constraint, '@');
     if ($pos !== false) {
         $constraint = substr($constraint, 0, $pos);
     }
     return $constraint;
 }
Ejemplo n.º 16
0
 function __construct($args = array(), $isSimpleInstance = false)
 {
     $this->setWithTable("test_001_botella");
     $this->addAttribute("material", Datatypes::TEXT);
     $this->addAttribute("capacidad", Datatypes::FLOAT_NUMBER);
     $this->addAttribute("tapaRosca", Datatypes::BOOLEAN);
     $this->addConstraints("material", array(Constraint::maxLength(30), Constraint::blank(false)));
     $this->addConstraints("capacidad", array(Constraint::between(0.0, 10.0)));
     $this->addConstraints("tapaRosca", array(Constraint::nullable(true)));
     parent::__construct($args, $isSimpleInstance);
 }
 function __construct($args = array(), $isSimpleInstance = false)
 {
     $this->setWithTable("test_003_persona");
     // BUG #19
     $this->addAttribute("nombre", Datatypes::TEXT);
     $this->addAttribute("edad", Datatypes::INT_NUMBER);
     $this->addAttribute("num", Datatypes::INT_NUMBER);
     $this->addConstraints("edad", array(Constraint::min(10)));
     $this->addConstraints("num", array(Constraint::max(20)));
     parent::__construct($args, $isSimpleInstance);
 }
Ejemplo n.º 18
0
 function __construct($args = array(), $isSimpleInstance = false)
 {
     $this->setWithTable("test_a004_pagina");
     $this->addAttribute("titulo", Datatypes::TEXT);
     $this->addAttribute("contenido", Datatypes::TEXT);
     // Pagina padre
     $this->addHasOne('owner', 'Pagina');
     // Paginas hijas
     $this->addHasMany('subpages', 'Pagina');
     $this->addConstraints("titulo", array(Constraint::maxLength(255)));
     $this->addConstraints("contenido", array(Constraint::maxLength(100000)));
     $this->addConstraints("owner", array(Constraint::nullable(true)));
     parent::__construct($args, $isSimpleInstance);
 }
Ejemplo n.º 19
0
 public function validate($data)
 {
     parent::validate($data);
     $copy = $data;
     foreach ($data as $key => $value) {
         foreach ($copy as $key2 => $check) {
             if ($value === $check || is_object($value) && $value == $check) {
                 $this->throwException("ValueException", "The data contained values that aren't unique");
             }
         }
         // no need to check this key against any others
         // remove it from the check array to improve performance
         unset($copy[$key]);
     }
 }
Ejemplo n.º 20
0
 function __construct($args = array(), $isSimpleInstance = false)
 {
     $this->setWithTable(self::TABLE);
     // message data
     $this->addAttribute('text', Datatypes::TEXT);
     $this->addAttribute('createdOn', Datatypes::DATETIME);
     // associations
     $this->addHasOne('createdBy', 'TUser');
     // the user that creates this twitter message
     // default values
     $this->setCreatedOn(date("Y-m-d H:i:s"));
     // Ya con formato de MySQL!
     // constraints
     $this->addConstraints('text', array(Constraint::maxLength(160), Constraint::nullable(false), Constraint::blank(false)));
     parent::__construct($args, $isSimpleInstance);
 }
Ejemplo n.º 21
0
 function __construct($args = array(), $isSimpleInstance = false)
 {
     $this->setWithTable(self::TABLE);
     // user data
     $this->addAttribute('name', Datatypes::TEXT);
     $this->addAttribute('email', Datatypes::TEXT);
     // auth
     $this->addAttribute('username', Datatypes::TEXT);
     $this->addAttribute('password', Datatypes::TEXT);
     // associations
     $this->addHasMany('following', 'TUser', PersistentObject::HASMANY_SET);
     // users I follow, is a set
     // constraints
     $this->addConstraints('name', array(Constraint::minLength(1), Constraint::maxLength(255), Constraint::nullable(false), Constraint::blank(false)));
     $this->addConstraints('username', array(Constraint::blank(false)));
     $this->addConstraints('password', array(Constraint::minLength(4)));
     $this->addConstraints('email', array(Constraint::email()));
     parent::__construct($args, $isSimpleInstance);
 }
Ejemplo n.º 22
0
 public function validate($data)
 {
     parent::validate($data);
     $float = $data / $this->value;
     $int = (int) $float;
     /**
      * we have to the epsilon method of comparison because floating point numbers are imprecise
      * and comparing them will give unexpected results.
      * I won't implement a relative Epsilon or ULP method here as that would be overkill, but it's
      * something to consider if we start finding this type of bug
      *
      * @link http://www.php.net/manual/en/language.types.float.php
      * @link http://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/
      */
     $epsilon = abs($float - $int);
     if (!($epsilon <= self::EPSILON || 1 - $epsilon <= self::EPSILON)) {
         $this->throwException("ValueException", "The data is not a multiple of the value (epsilon = {$epsilon})", $data);
     }
 }
Ejemplo n.º 23
0
 function __construct($args = array(), $isSimpleInstance = false)
 {
     $this->setWithTable("test_i005_contenido");
     $this->addAttribute("elemento", Datatypes::TEXT);
     $this->addAttribute("volumen", Datatypes::FLOAT_NUMBER);
     $this->addConstraints("elemento", array(Constraint::maxLength(30), Constraint::blank(false)));
     $this->addConstraints("volumen", array(Constraint::between(0.0, 10.0)));
     /*
     $this->constraints = array (
        "elemento" => array (
           Constraint :: maxLength(30),
           Constraint :: blank(false)
        ),
        "volumen" => array (
           Constraint :: between(0.0, 10.0)
        )
     );
     */
     parent::__construct($args, $isSimpleInstance);
 }
 function __construct($args = array(), $isSimpleInstance = false)
 {
     $this->setWithTable("test_i006_contenido1");
     $this->belongsTo = array('Vaso1');
     // La unica diferencia con respecto al test i005
     $this->addAttribute("elemento", Datatypes::TEXT);
     $this->addAttribute("volumen", Datatypes::FLOAT_NUMBER);
     $this->addConstraints("elemento", array(Constraint::maxLength(30), Constraint::blank(false)));
     $this->addConstraints("volumen", array(Constraint::between(0.0, 10.0)));
     /*
     $this->constraints = array (
        "elemento" => array (
           Constraint :: maxLength(30),
           Constraint :: blank(false)
        ),
        "volumen" => array (
           Constraint :: between(0.0, 10.0)
        )
     );
     */
     parent::__construct($args, $isSimpleInstance);
 }
Ejemplo n.º 25
0
 public function getConstraintString()
 {
     $sql[] = parent::getConstraintString();
     foreach ($this->references as $rk) {
         $reference_keys[] = $rk->getName();
     }
     $reference_table_name = $rk->getTable()->getFullName();
     $sql[] = 'REFERENCES';
     $sql[] = $reference_table_name . '(' . implode(', ', $reference_keys) . ')';
     $sql[] = 'ON DELETE ' . $this->getOptionString($this->on_delete);
     $sql[] = 'ON UPDATE ' . $this->getOptionString($this->on_update);
     return implode(' ', $sql);
 }
Ejemplo n.º 26
0
 /**
  * Parses a bracketted expression.
  *
  * @param  Constraint $constraint
  * @return void
  * @throws SparqlParserException
  */
 protected function parseBrackettedExpression(&$constraint)
 {
     $open = 1;
     $exp = "";
     $this->_fastForward();
     while ($open != 0 && current($this->tokens) != false) {
         switch (current($this->tokens)) {
             case "(":
                 $open++;
                 $exp = $exp . current($this->tokens);
                 break;
             case ")":
                 $open--;
                 if ($open != 0) {
                     $exp = $exp . current($this->tokens);
                 }
                 break;
             case false:
                 throw new SparqlParserException("Unexpected end of query.", null, key($this->tokens));
             default:
                 $exp = $exp . current($this->tokens);
                 break;
         }
         next($this->tokens);
     }
     $constraint->addExpression($exp);
 }
Ejemplo n.º 27
0
 function __construct($var1, $var2, $strength)
 {
     parent::__construct($strength);
     $this->v1 = $var1;
     $this->v2 = $var2;
     $this->direction = Direction::NONE;
     $this->addConstraint();
 }
Ejemplo n.º 28
0
 function __construct($var1, $var2, $strength)
 {
     Constraint::__construct($strength);
     $this->v1 = $var1;
     $this->v2 = $var2;
     $this->direction = $this->nodirection;
     $this->addConstraint();
 }
Ejemplo n.º 29
0
 /**
  * Constructor.
  *
  * @param mixed $value
  * @param array $options
  */
 public function __construct($value, $options = array())
 {
     $options = lAtts(array('message' => 'should_be_false'), $options, false);
     parent::__construct($value, $options);
 }
Ejemplo n.º 30
0
 public function __construct($name, $columns)
 {
     parent::__construct(Constraint::TYPE_UNIQUE, $name, $columns);
 }