/** * @return $this * @throws \RuntimeException */ public function initialize() { if ($this->getInitializer() !== null && !$this->isInitialized) { $this->isInitialized = true; $unknownType = new UnknownType(call_user_func($this->getInitializer())); if (!$unknownType->isCollection()) { throw new \RuntimeException(sprintf('Unexpected type given: %s', gettype($unknownType->getValue()))); } foreach ($unknownType->getAsCollection() as $element) { $this->getCollection()->add($element); } } return $this; }
public function testGetObjectAsEnumReturnsEnum() { $u = new UnknownType(new EnumMock(1, true)); $this->assertTrue($u->isEnum()); $this->assertTrue($u->isObject()); $this->assertFalse($u->isBoolean()); $this->assertFalse($u->isScalar()); $this->assertInstanceOf('PHPExtra\\Type\\Enum\\EnumInterface', $u->getAsEnum()); }