public function testInitDependencyReferenceIsUndefined() { $definition = new PropertyDefinition(); static::assertInstanceOf(UndefinedReference::class, $definition->getDependency()); }
/** * Generate property for class * * @param PropertyDefinition $propertyDefinition * @param ClassDefinition $classDefinition * @return string * @throws ReferenceNotImplementsException */ protected function generateProperty(ClassDefinition $classDefinition, PropertyDefinition $propertyDefinition) : string { $dependencyValue = $this->resolveDependency($propertyDefinition->getDependency()); $propertyName = $propertyDefinition->getPropertyName(); $className = $classDefinition->getClassName(); if ($propertyDefinition->isPublic()) { return "\t\$temp->{$propertyName} = {$dependencyValue};"; // Use reflection to setting the value } else { return "\t\$property = (new \\ReflectionClass('{$className}'))->getProperty('{$propertyName}');" . "\n\t\t\t\$property->setAccessible(true);" . "\n\t\t\t\$property->setValue(\$temp, {$dependencyValue});" . "\n\t\t\t\$property->setAccessible(false);"; } }