コード例 #1
0
 /**
  * Checks if autowiring doesn't override constructor arguments which have already been defined in the object configuration
  * @test
  * @author Robert Lemke <*****@*****.**>
  */
 public function autoWiringForConstructorInjectionRespectsAlreadyDefinedArguments()
 {
     $objectName = 'F3\\FLOW3\\Tests\\Object\\Fixture\\ClassWithSomeImplementationInjected';
     $this->mockObjectManager->expects($this->at(0))->method('getObject')->with('F3\\FLOW3\\Tests\\Object\\Fixture\\SomeInterface')->will($this->returnValue(new \F3\FLOW3\Tests\Object\Fixture\SomeImplementation()));
     $this->mockReflectionService->expects($this->once())->method('getClassConstructorName')->with($objectName)->will($this->returnValue('__construct'));
     $constructorParameters = array('argument1' => array('position' => 0, 'byReference' => FALSE, 'array' => FALSE, 'optional' => FALSE, 'allowsNull' => FALSE, 'class' => 'F3\\FLOW3\\Tests\\Object\\Fixture\\SomeInterface'), 'argument2' => array('position' => 1, 'byReference' => FALSE, 'array' => FALSE, 'optional' => FALSE, 'allowsNull' => FALSE, 'class' => 'F3\\FLOW3\\Tests\\Object\\Fixture\\BasicClass'));
     $this->mockReflectionService->expects($this->at(1))->method('getMethodParameters')->with($objectName, '__construct')->will($this->returnValue($constructorParameters));
     $injectedClassName = uniqid('Injected');
     eval('namespace F3\\Virtual; class ' . $injectedClassName . ' extends \\F3\\FLOW3\\Tests\\Object\\Fixture\\BasicClass {}');
     $injectedClassName = 'F3\\Virtual\\' . $injectedClassName;
     $injectedClass = new $injectedClassName();
     $this->mockObjectManager->expects($this->at(1))->method('getObject')->with($injectedClassName)->will($this->returnValue($injectedClass));
     $objectConfiguration = new \F3\FLOW3\Object\Configuration\Configuration('F3\\FLOW3\\Tests\\Object\\Fixture\\ClassWithSomeImplementationInjected');
     $objectConfiguration->setArguments(array(new \F3\FLOW3\Object\Configuration\ConfigurationArgument(2, $injectedClassName, \F3\FLOW3\Object\Configuration\ConfigurationArgument::ARGUMENT_TYPES_OBJECT)));
     $object = $this->objectBuilder->createObject($objectName, $objectConfiguration);
     $this->assertSame($object->argument2, $injectedClass, 'Autowiring didn\'t respect that the second constructor argument was already set in the object configuration!');
 }