Added Test #16552: Add unit tests for t3lib_div::makeInstance (Thanks to Oliver Klee)
authorSteffen Kamper <info@sk-typo3.de>
Thu, 25 Nov 2010 23:45:40 +0000 (23:45 +0000)
committerSteffen Kamper <info@sk-typo3.de>
Thu, 25 Nov 2010 23:45:40 +0000 (23:45 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@9642 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
tests/t3lib/t3lib_divTest.php

index 0e56579..b42b2d3 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -13,6 +13,7 @@
 
 2010-11-25  Steffen Kamper  <steffen@typo3.org>
 
+       * Added Test #16552: Add unit tests for t3lib_div::makeInstance (Thanks to Oliver Klee)
        * Fixed bug #16526: EM resolve dependencies by moving common objects to API class
        * Fixed bug #16527: EM: delete of extension does not work
        * Fixed bug #16528: EM: remove dependency to $TBE_TEMPLATE
index 88bef17..0b6ffea 100644 (file)
@@ -22,7 +22,6 @@
 *  This copyright notice MUST APPEAR in all copies of the script!
 ***************************************************************/
 
-
 /**
  * Testcase for class t3lib_div
  *
@@ -1815,5 +1814,77 @@ class t3lib_divTest extends tx_phpunit_testcase {
                        t3lib_div::dirname($input)
                );
        }
+
+
+       //////////////////////////////////
+       // Tests concerning makeInstance
+       //////////////////////////////////
+
+       /**
+        * @test
+        */
+       public function makeInstanceReturnsClassInstance() {
+               $className = get_class($this->getMock('foo'));
+
+               $this->assertTrue(
+                       t3lib_div::makeInstance($className) instanceof $className
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function makeInstancePassesParametersToConstructor() {
+               $className = 'testingClass' . uniqid();
+               if (!class_exists($className, FALSE)) {
+                       eval(
+                               'class ' . $className . ' {' .
+                               '  public $constructorParameter1;' .
+                               '  public $constructorParameter2;' .
+                               '  public function __construct($parameter1, $parameter2) {' .
+                               '    $this->constructorParameter1 = $parameter1;' .
+                               '    $this->constructorParameter2 = $parameter2;' .
+                               '  }' .
+                               '}'
+                       );
+               }
+
+               $instance = t3lib_div::makeInstance($className, 'one parameter', 'another parameter');
+
+               $this->assertEquals(
+                       'one parameter',
+                       $instance->constructorParameter1,
+                       'The first constructor parameter has not been set.'
+               );
+               $this->assertEquals(
+                       'another parameter',
+                       $instance->constructorParameter2,
+                       'The second constructor parameter has not been set.'
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function makeInstanceCalledTwoTimesForNonSingletonClassReturnsDifferentInstances() {
+               $className = get_class($this->getMock('foo'));
+
+               $this->assertNotSame(
+                       t3lib_div::makeInstance($className),
+                       t3lib_div::makeInstance($className)
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function makeInstanceCalledTwoTimesForSingletonClassReturnsSameInstance() {
+               $className = get_class($this->getMock('t3lib_Singleton'));
+
+               $this->assertSame(
+                       t3lib_div::makeInstance($className),
+                       t3lib_div::makeInstance($className)
+               );
+       }
 }
 ?>
\ No newline at end of file