/** * @test */ public function passingAnEmptyArrayToSetArgumentsRemovesAllExistingArguments() { $someArguments = array(1 => new \TYPO3\Flow\Object\Configuration\ConfigurationArgument(1, 'simple string'), 2 => new \TYPO3\Flow\Object\Configuration\ConfigurationArgument(2, 'another string')); $this->objectConfiguration->setArguments($someArguments); $this->assertEquals($someArguments, $this->objectConfiguration->getArguments(), 'The set arguments could not be retrieved again.'); $this->objectConfiguration->setArguments(array()); $this->assertEquals(array(), $this->objectConfiguration->getArguments(), 'The constructor arguments have not been cleared.'); }
/** * Builds code which injects an object which was specified by its object configuration * * @param Configuration $objectConfiguration Configuration of the object to inject into * @param string $propertyName Name of the property to inject * @param Configuration $propertyConfiguration Configuration of the object to inject * @return array PHP code * @throws \TYPO3\Flow\Object\Exception\UnknownObjectException */ protected function buildPropertyInjectionCodeByConfiguration(Configuration $objectConfiguration, $propertyName, Configuration $propertyConfiguration) { $className = $objectConfiguration->getClassName(); $propertyObjectName = $propertyConfiguration->getObjectName(); $propertyClassName = $propertyConfiguration->getClassName(); if ($propertyClassName === null) { $preparedSetterArgument = $this->buildCustomFactoryCall($propertyConfiguration->getFactoryObjectName(), $propertyConfiguration->getFactoryMethodName(), $propertyConfiguration->getArguments()); } else { if (!is_string($propertyClassName) || !isset($this->objectConfigurations[$propertyClassName])) { $configurationSource = $objectConfiguration->getConfigurationSourceHint(); throw new \TYPO3\Flow\Object\Exception\UnknownObjectException('Unknown class "' . $propertyClassName . '", specified as property "' . $propertyName . '" in the object configuration of object "' . $objectConfiguration->getObjectName() . '" (' . $configurationSource . ').', 1296130876); } if ($this->objectConfigurations[$propertyClassName]->getScope() === Configuration::SCOPE_PROTOTYPE) { $preparedSetterArgument = 'new \\' . $propertyClassName . '(' . $this->buildMethodParametersCode($propertyConfiguration->getArguments()) . ')'; } else { $preparedSetterArgument = '\\TYPO3\\Flow\\Core\\Bootstrap::$staticObjectManager->get(\'' . $propertyClassName . '\')'; } } $result = $this->buildSetterInjectionCode($className, $propertyName, $preparedSetterArgument); if ($result !== null) { return $result; } return $this->buildLazyPropertyInjectionCode($propertyObjectName, $propertyClassName, $propertyName, $preparedSetterArgument); }