/** * @test * @author Robert Lemke <*****@*****.**> */ public function createRegistersShutdownObjectsAtTheComponentManager() { $className = 'SomeClass' . uniqid(); eval('class ' . $className . ' {}'); $object = new $className(); $objectName = 'F3\\Virtual\\BasicClass'; $objectConfiguration = new \F3\FLOW3\Object\Configuration\Configuration($objectName); $objectConfiguration->setScope('prototype'); $this->mockObjectManager->expects($this->once())->method('isObjectRegistered')->with($objectName)->will($this->returnValue(TRUE)); $this->mockObjectManager->expects($this->once())->method('getObjectConfiguration')->with($objectName)->will($this->returnValue($objectConfiguration)); $this->mockObjectManager->expects($this->once())->method('registerShutdownObject')->with($object, 'shutdownObject'); $this->mockObjectBuilder->expects($this->once())->method('createObject')->will($this->returnValue($object)); $this->objectFactory->create($objectName); }
/** * @test * @author Karsten Dambekalns <*****@*****.**> */ public function reinjectDependenciesTriesToDependencyInjectPropertiesWhichAreNotPersistable() { $mockReflectionService = $this->getMock('F3\\FLOW3\\Reflection\\ReflectionService'); $mockReflectionService->expects($this->any())->method('getPropertyNamesByTag')->will($this->returnValue(array())); $objectBuilder = new \F3\FLOW3\Object\ObjectBuilder(); $objectBuilder->injectObjectManager($this->mockObjectManager); $objectBuilder->injectObjectFactory($this->mockObjectFactory); $objectBuilder->injectReflectionService($mockReflectionService); $objectConfiguration = new \F3\FLOW3\Object\Configuration\Configuration('F3\\FLOW3\\Tests\\Object\\Fixture\\ReconstitutableClassWithSimpleProperties'); $objectConfiguration->setProperty(new \F3\FLOW3\Object\Configuration\ConfigurationProperty('stringDependency', 'wasInjected')); $object = $objectBuilder->createEmptyObject('F3\\FLOW3\\Tests\\Object\\Fixture\\ReconstitutableClassWithSimpleProperties', $objectConfiguration); $objectBuilder->reinjectDependencies($object, $objectConfiguration); $this->assertEquals('wasInjected', $object->FLOW3_AOP_Proxy_getProperty('stringDependency')); }
/** * @test * @author Robert Lemke <*****@*****.**> */ public function settingsCanBeInjectedAsArgumentOrProperty() { $configurationArray = array(); $configurationArray['arguments'][1]['setting'] = 'F3.Foo.Bar'; $configurationArray['properties']['someProperty']['setting'] = 'F3.Bar.Baz'; $objectConfiguration = new \F3\FLOW3\Object\Configuration\Configuration('TestObject', 'TestObject'); $objectConfiguration->setArgument(new \F3\FLOW3\Object\Configuration\ConfigurationArgument(1, 'F3.Foo.Bar', \F3\FLOW3\Object\Configuration\ConfigurationProperty::PROPERTY_TYPES_SETTING)); $objectConfiguration->setProperty(new \F3\FLOW3\Object\Configuration\ConfigurationProperty('someProperty', 'F3.Bar.Baz', \F3\FLOW3\Object\Configuration\ConfigurationProperty::PROPERTY_TYPES_SETTING)); $builtObjectConfiguration = \F3\FLOW3\Object\Configuration\ConfigurationBuilder::buildFromConfigurationArray('TestObject', $configurationArray, __CLASS__); $this->assertEquals($objectConfiguration, $builtObjectConfiguration); }
/** * @test * @author Robert Lemke <*****@*****.**> */ public function getObjectPassesAdditionalArgumentsToTheObjectBuilderWhenItCreatesANewSingletonObject() { $someObject = new \ArrayObject(); $arguments = array(1 => new \F3\FLOW3\Object\Configuration\ConfigurationArgument(1, 'arg1', \F3\FLOW3\Object\Configuration\ConfigurationArgument::ARGUMENT_TYPES_STRAIGHTVALUE), 2 => new \F3\FLOW3\Object\Configuration\ConfigurationArgument(2, $someObject, \F3\FLOW3\Object\Configuration\ConfigurationArgument::ARGUMENT_TYPES_STRAIGHTVALUE)); $className = 'SomeClass' . uniqid(); eval('class ' . $className . ' {}'); $objectConfiguration = new \F3\FLOW3\Object\Configuration\Configuration($className); $objectConfiguration->setConfigurationSourceHint('F3\\FLOW3\\Object\\ObjectManager'); $mockObjectBuilder = $this->getMock('F3\\FLOW3\\Object\\ObjectBuilder'); $mockObjectBuilder->expects($this->once())->method('createObject')->with($className, $objectConfiguration, $arguments)->will($this->returnValue(new $className())); $mockSingletonObjectsRegistry = $this->getMock('F3\\FLOW3\\Object\\TransientRegistry'); $mockSingletonObjectsRegistry->expects($this->once())->method('objectExists')->with($className)->will($this->returnValue(FALSE)); $objectManager = new \F3\FLOW3\Object\ObjectManager(); $objectManager->injectObjectBuilder($mockObjectBuilder); $objectManager->injectObjectFactory($this->getMock('F3\\FLOW3\\Object\\ObjectFactoryInterface')); $objectManager->injectSingletonObjectsRegistry($mockSingletonObjectsRegistry); $objectManager->injectReflectionService($this->getMock('F3\\FLOW3\\Reflection\\ReflectionService')); $objectManager->registerObject($className); $objectManager->getObject($className, 'arg1', $someObject); }
/** * Register the given interface as an object type * * @param string $objectName The name of the object type * @return void * @author Robert Lemke <*****@*****.**> * @api */ public function registerObjectType($objectName) { $className = $this->reflectionService->getDefaultImplementationClassNameForInterface($objectName); $objectConfiguration = new \F3\FLOW3\Object\Configuration\Configuration($objectName); if ($className !== FALSE) { $objectConfiguration->setClassName($className); if ($this->reflectionService->isClassTaggedWith($className, 'scope')) { $scope = trim(implode('', $this->reflectionService->getClassTagValues($className, 'scope'))); $objectConfiguration->setScope($scope); } $this->registeredClasses[$className] = $objectName; } else { } $this->registeredObjects[$objectName] = strtolower($objectName); $this->objectConfigurations[$objectName] = $objectConfiguration; }