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('DateTime')->willReturn(new CollectionNode()); $constraint = $this->prophesize(ConstraintInterface::class); $constraint->validate([['timestamp' => 1389312000]])->willReturn(false); $constraint->getErrorMessage('foobar')->shouldBeCalled(); $base = new CollectionNode(); $base->setTypeHandler($typeHandler->reveal()); $child = $base->add('foobar', 'DateTime', ['constraints' => [$constraint->reveal()]]); $child->setType('DateTime'); $child->getValue('foobar', [['timestamp' => 1389312000]]); }