[TASK] Test for dangling instances in unit test execution 69/55769/4
authorChristian Kuhn <lolli@schwarzbu.ch>
Fri, 16 Feb 2018 22:11:35 +0000 (23:11 +0100)
committerAndreas Fernandez <a.fernandez@scripting-base.de>
Sat, 17 Feb 2018 15:37:49 +0000 (16:37 +0100)
If a test adds some mock or prophecy revelation to the
GeneralUtility::makeInstance() stack using addInstance(),
it is important the test subject actually consumes that
instance. Otherwise, the dangling instance can have
side effects on other tests run afterwards.

The patch raises typo3/testing-framework from 3.0.0 to
3.1.0 which extends tearDown() with a test to verify the
instance stack is empty. If not, the test fails with
an accordig message.

composer command used:
composer update typo3/testing-framework

An @internal method to GeneralUtility is added to
retrieve the current instance stack, and one test
is fixed which violates this rule.

Change-Id: I769b82bf704834bf5d1718cbf39b9b411438e30c
Resolves: #83948
Releases: master
Reviewed-on: https://review.typo3.org/55769
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
composer.lock
typo3/sysext/core/Classes/Utility/GeneralUtility.php
typo3/sysext/core/Tests/Unit/Authentication/BackendUserAuthenticationTest.php

index 6a64e2e..5032e58 100644 (file)
         },
         {
             "name": "typo3/testing-framework",
-            "version": "3.0.0",
+            "version": "3.1.0",
             "source": {
                 "type": "git",
                 "url": "https://github.com/TYPO3/testing-framework.git",
-                "reference": "0793e458c801f746c8da55453d8c98744d477ede"
+                "reference": "5d50470d7aa5f782c4f2574bfbfbae94f70fb4bb"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/TYPO3/testing-framework/zipball/0793e458c801f746c8da55453d8c98744d477ede",
-                "reference": "0793e458c801f746c8da55453d8c98744d477ede",
+                "url": "https://api.github.com/repos/TYPO3/testing-framework/zipball/5d50470d7aa5f782c4f2574bfbfbae94f70fb4bb",
+                "reference": "5d50470d7aa5f782c4f2574bfbfbae94f70fb4bb",
                 "shasum": ""
             },
             "require": {
                 "tests",
                 "typo3"
             ],
-            "time": "2018-02-13T22:48:10+00:00"
+            "time": "2018-02-16T22:04:44+00:00"
         },
         {
             "name": "webmozart/assert",
index 5e9a257..3cf65c0 100644 (file)
@@ -3633,6 +3633,22 @@ class GeneralUtility
     }
 
     /**
+     * Get all currently registered non singleton instances
+     *
+     * Warning:
+     * This is NOT a public API method and must not be used in own extensions!
+     * This method is only used in UnitTestCase base test tearDown() to verify tests
+     * have no left over instances that were previously added using addInstance().
+     *
+     * @internal
+     * @return array $className => $objects[]
+     */
+    public static function getInstances()
+    {
+        return static::$nonSingletonInstances;
+    }
+
+    /**
      * Sets the instance of a non-singleton class to be returned by makeInstance.
      *
      * If this function is called multiple times for the same $className,
index 2d388c9..6f52979 100644 (file)
@@ -89,16 +89,6 @@ class BackendUserAuthenticationTest extends UnitTestCase
 
         GeneralUtility::addInstance(ConnectionPool::class, $connectionPool->reveal());
 
-        /** @var ObjectProphecy|Connection $connection */
-        $connection = $this->prophesize(Connection::class);
-        $connection->delete('be_sessions', Argument::cetera())->willReturn(1);
-
-        /** @var ObjectProphecy|ConnectionPool $connectionPool */
-        $connectionPool = $this->prophesize(ConnectionPool::class);
-        $connectionPool->getConnectionForTable(Argument::cetera())->willReturn($connection->reveal());
-
-        GeneralUtility::addInstance(ConnectionPool::class, $connectionPool->reveal());
-
         /** @var ObjectProphecy|\TYPO3\CMS\Core\FormProtection\AbstractFormProtection $formProtection */
         $formProtection = $this->prophesize(\TYPO3\CMS\Core\FormProtection\BackendFormProtection::class);
         $formProtection->clean()->shouldBeCalled();