[TASK] Let GeneralUtility::makeInstance() throw exception on unknown class 93/53793/3
authorMathias Brodala <mbrodala@pagemachine.de>
Fri, 18 Aug 2017 12:53:03 +0000 (14:53 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Wed, 23 Aug 2017 20:03:59 +0000 (22:03 +0200)
Change-Id: I9e5a04c3ef0ee8fed53d22df4d6ea472266145e7
Resolves: #82131
Releases: master, 8.7
Reviewed-on: https://review.typo3.org/53793
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/core/Classes/Utility/GeneralUtility.php
typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php

index bcc6447..2b65481 100644 (file)
@@ -3898,6 +3898,9 @@ class GeneralUtility
         ) {
             return array_shift(self::$nonSingletonInstances[$finalClassName]);
         }
+        if (!class_exists($finalClassName)) {
+            throw new \InvalidArgumentException('Class "' . $className . '" not found', 1503060454);
+        }
         // Create new instance and call constructor with parameters
         $instance = new $finalClassName(...$constructorArguments);
         // Register new singleton instance
index 57ccde9..701a409 100644 (file)
@@ -4003,6 +4003,31 @@ class GeneralUtilityTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
     /**
      * @test
      */
+    public function makeInstanceWithUnknownClassThrowsException()
+    {
+        $this->expectException(\InvalidArgumentException::class);
+        $this->expectExceptionCode(1503060454);
+
+        GeneralUtility::makeInstance('UnknownClass' . time());
+    }
+
+    /**
+     * @test
+     */
+    public function makeInstanceWithUnknownClassImplementationThrowsException()
+    {
+        $this->expectException(\InvalidArgumentException::class);
+        $this->expectExceptionCode(1503060454);
+
+        GeneralUtilityFixture::resetFinalClassNameCache();
+        $GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects'][OriginalClassFixture::class] = ['className' => 'UnknownClass' . time()];
+
+        GeneralUtility::makeInstance(OriginalClassFixture::class);
+    }
+
+    /**
+     * @test
+     */
     public function makeInstanceWithBeginningSlashInClassNameThrowsException()
     {
         $this->expectException(\InvalidArgumentException::class);