/** * @test * @author Robert Lemke <*****@*****.**> */ public function allBasicOptionsAreSetCorrectly() { $factoryClassName = uniqid('ConfigurationBuilderTest'); eval('class ' . $factoryClassName . ' { public function manufacture() {} } '); $configurationArray = array(); $configurationArray['scope'] = 'prototype'; $configurationArray['className'] = __CLASS__; $configurationArray['factoryClassName'] = $factoryClassName; $configurationArray['factoryMethodName'] = 'manufacture'; $configurationArray['lifecycleInitializationMethodName'] = 'initializationMethod'; $configurationArray['lifecycleShutdownMethodName'] = 'shutdownMethod'; $configurationArray['autowiring'] = FALSE; $objectConfiguration = new \F3\FLOW3\Object\Configuration\Configuration('TestObject', __CLASS__); $objectConfiguration->setScope(\F3\FLOW3\Object\Configuration\Configuration::SCOPE_PROTOTYPE); $objectConfiguration->setClassName(__CLASS__); $objectConfiguration->setFactoryClassName($factoryClassName); $objectConfiguration->setFactoryMethodName('manufacture'); $objectConfiguration->setLifecycleInitializationMethodName('initializationMethod'); $objectConfiguration->setLifecycleShutdownMethodName('shutdownMethod'); $objectConfiguration->setAutowiring(FALSE); $builtObjectConfiguration = \F3\FLOW3\Object\Configuration\ConfigurationBuilder::buildFromConfigurationArray('TestObject', $configurationArray, __CLASS__); $this->assertEquals($objectConfiguration, $builtObjectConfiguration, 'The manually created and the built object configuration don\'t match.'); }
/** * @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 Robert Lemke <*****@*****.**> */ public function getObjectCallsTheObjectFactoryInOrderToCreateANewPrototypeObject() { $expectedObject = new \ArrayObject(); $mockObjectFactory = $this->getMock('F3\\FLOW3\\Object\\ObjectFactoryInterface'); $mockObjectFactory->expects($this->once())->method('create')->will($this->returnValue($expectedObject)); $objectManager = new \F3\FLOW3\Object\ObjectManager(); $objectManager->injectObjectBuilder($this->getMock('F3\\FLOW3\\Object\\ObjectBuilder')); $objectManager->injectObjectFactory($mockObjectFactory); $objectManager->injectSingletonObjectsRegistry($this->getMock('F3\\FLOW3\\Object\\TransientRegistry')); $objectManager->injectReflectionService($this->getMock('F3\\FLOW3\\Reflection\\ReflectionService')); $objectConfiguration = new \F3\FLOW3\Object\Configuration\Configuration('F3\\Foo\\Bar\\Fixture\\Object'); $objectConfiguration->setScope(\F3\FLOW3\Object\Configuration\Configuration::SCOPE_PROTOTYPE); $objectManager->setObjectConfiguration($objectConfiguration); $retrievedObject = $objectManager->getObject('F3\\Foo\\Bar\\Fixture\\Object'); $this->assertSame($expectedObject, $retrievedObject); }
/** * 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; }