[+BUGFIX] Extbase (Object): constructor injection fails if default value for a depend...
authorSebastian Kurfürst <sebastian@typo3.org>
Fri, 21 Jan 2011 13:01:39 +0000 (13:01 +0000)
committerSebastian Kurfürst <sebastian@typo3.org>
Fri, 21 Jan 2011 13:01:39 +0000 (13:01 +0000)
In Container class the existence of a default value was checked with
isset($argumentInformation['defaultValue']) which returns false if
$argumentInformation['defaultValue'] === NULL.

This commit fixes this issue using array_key_exists() instead and adds a unit test.

Thanks to Lienhart Woitok for the patch!

Resolves: #11623

typo3/sysext/extbase/Classes/Object/Container/Container.php
typo3/sysext/extbase/Tests/Unit/Object/Container/ContainerTest.php
typo3/sysext/extbase/Tests/Unit/Object/Container/Fixtures/Testclasses.php

index 596e874..fe1ffe3 100644 (file)
@@ -240,7 +240,7 @@ class Tx_Extbase_Object_Container_Container implements t3lib_Singleton {
                                // injection, and thus the passed constructor takes precendence over
                                // autowiring.
                                $parameter = array_shift($givenConstructorArguments);
-                       } elseif (isset($argumentInformation['defaultValue'])) {
+                       } elseif (array_key_exists('defaultValue', $argumentInformation)) {
                                // no value to set anymore, we take default value
                                $parameter = $argumentInformation['defaultValue'];
                        } else {
index 658fe0e..6716ea7 100644 (file)
@@ -77,6 +77,15 @@ class Tx_Extbase_Tests_Unit_Object_Container_ContainerTest extends Tx_Extbase_Te
 
        /**
         * @test
+        */
+       public function getInstanceReturnsInstanceOfAClassWithMixedSimpleTypeAndConstructorInjectionWithNullDefaultValue() {
+               $object = $this->container->getInstance('t3lib_object_tests_amixed_null');
+               $this->assertType('t3lib_object_tests_amixed_null', $object);
+               $this->assertNull($object->myvalue);
+       }
+
+       /**
+        * @test
         * @expectedException Tx_Extbase_Object_Exception
         */
        public function getInstanceThrowsExceptionWhenTryingToInstanciateASingletonWithConstructorParameters() {
index 8047866..2d2c7a0 100644 (file)
@@ -37,6 +37,21 @@ class t3lib_object_tests_amixed_array {
 }
 
 /**
+ * test class A that depends on B and C and has a third default parameter in constructor that defaults to NULL
+ *
+ */
+class t3lib_object_tests_amixed_null {
+       public $b;
+       public $c;
+       public $myvalue;
+       public function __construct(t3lib_object_tests_b $b, t3lib_object_tests_c $c, $myvalue = NULL) {
+               $this->b = $b;
+               $this->c = $c;
+               $this->myvalue = $myvalue;
+       }
+}
+
+/**
  * test class A that depends on B and C and has a third default parameter in constructor
  *
  */