Example #1
0
 public function getType(string $name) : BaseNode
 {
     if (isset($this->types[$name])) {
         $type = new $this->types[$name]();
         $type->setTypeHandler($this);
         return $type;
     }
     if ($this->isScalarCollectionType($name)) {
         $type = new ScalarCollectionNode();
         $type->setType($this->getCollectionType($name));
         $type->setTypeHandler($this);
         return $type;
     }
     if ($this->isClassType($name)) {
         $type = new ObjectNode();
         $type->setType($name);
         $type->setTypeHandler($this);
         $type->setInstantiator($this->defaultInstantiator);
         return $type;
     }
     if ($this->isCollectionType($name)) {
         $type = new CollectionNode();
         $type->setType($this->getCollectionType($name));
         $type->setTypeHandler($this);
         $type->setInstantiator($this->defaultInstantiator);
         return $type;
     }
     throw new \InvalidArgumentException('Unknown type name: ' . $name);
 }
 /**
  * @expectedException Linio\Component\Input\Exception\InvalidConstraintException
  */
 public function testIsCheckingConstraintsOnValue()
 {
     $typeHandler = $this->prophesize(TypeHandler::class);
     $typeHandler->getType('int')->willReturn(new ScalarCollectionNode());
     $constraint = $this->prophesize(ConstraintInterface::class);
     $constraint->validate([15, 25, 36])->willReturn(false);
     $constraint->getErrorMessage('foobar')->shouldBeCalled();
     $base = new ScalarCollectionNode();
     $base->setTypeHandler($typeHandler->reveal());
     $child = $base->add('foobar', 'int', ['constraints' => [$constraint->reveal()]]);
     $child->setType('int');
     $child->getValue('foobar', [15, 25, 36]);
 }