[BUGFIX] Show original error in ReflectionService exception 30/58730/7
authorSusanne Moog <susanne.moog@typo3.org>
Sat, 27 Oct 2018 10:58:50 +0000 (12:58 +0200)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Sat, 27 Oct 2018 19:18:26 +0000 (21:18 +0200)
Instead of displaying a custom error message, let the original
exception message be part of the ReflectionException to differentiate
if the original class or any of the type hints has a problem.

Resolves: #86742
Releases: master, 8.7
Change-Id: I215ce779812b43f8bca5e6dfd2052461686482a7
Reviewed-on: https://review.typo3.org/58730
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Susanne Moog <susanne.moog@typo3.org>
Tested-by: Susanne Moog <susanne.moog@typo3.org>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Sybille Peters <sypets@gmx.de>
Reviewed-by: Sybille Peters <sypets@gmx.de>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
typo3/sysext/extbase/Classes/Reflection/ReflectionService.php
typo3/sysext/extbase/Tests/Unit/Reflection/Fixture/DummyClassWithInvalidTypeHint.php [new file with mode: 0644]
typo3/sysext/extbase/Tests/Unit/Reflection/ReflectionServiceTest.php [new file with mode: 0644]
typo3/sysext/extbase/Tests/UnitDeprecated/Reflection/Fixture/DummyClassWithAllTypesOfProperties.php
typo3/sysext/extbase/Tests/UnitDeprecated/Reflection/Fixture/DummyClassWithTags.php [new file with mode: 0644]
typo3/sysext/extbase/Tests/UnitDeprecated/Reflection/ReflectionServiceTest.php

index eeca1dc..350801d 100644 (file)
@@ -360,7 +360,7 @@ class ReflectionService implements SingletonInterface
         try {
             $classSchema = new ClassSchema($className);
         } catch (\ReflectionException $e) {
-            throw new Exception\UnknownClassException('The classname "' . $className . '" was not found and thus can not be reflected.', 1278450972, $e);
+            throw new Exception\UnknownClassException($e->getMessage() . '. Reflection failed.', 1278450972, $e);
         }
         $this->classSchemata[$className] = $classSchema;
         $this->dataCacheNeedsUpdate = true;
diff --git a/typo3/sysext/extbase/Tests/Unit/Reflection/Fixture/DummyClassWithInvalidTypeHint.php b/typo3/sysext/extbase/Tests/Unit/Reflection/Fixture/DummyClassWithInvalidTypeHint.php
new file mode 100644 (file)
index 0000000..8be25ab
--- /dev/null
@@ -0,0 +1,27 @@
+<?php
+declare(strict_types = 1);
+
+namespace TYPO3\CMS\Extbase\Tests\Unit\Reflection\Fixture;
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+/**
+ * Dummy class with invalid type hint
+ */
+class DummyClassWithInvalidTypeHint
+{
+    public function __construct(\Foo\Bar\Not\Found $invalid)
+    {
+    }
+}
diff --git a/typo3/sysext/extbase/Tests/Unit/Reflection/ReflectionServiceTest.php b/typo3/sysext/extbase/Tests/Unit/Reflection/ReflectionServiceTest.php
new file mode 100644 (file)
index 0000000..b7feeac
--- /dev/null
@@ -0,0 +1,55 @@
+<?php
+declare(strict_types = 1);
+
+namespace TYPO3\CMS\Extbase\Tests\Unit\Reflection;
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+use TYPO3\CMS\Extbase\Reflection\Exception\UnknownClassException;
+use TYPO3\CMS\Extbase\Reflection\ReflectionService;
+use TYPO3\CMS\Extbase\Tests\Unit\Reflection\Fixture\DummyClassWithInvalidTypeHint;
+use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
+
+/**
+ * Test case
+ * @see test for reflection
+ * @link second test for reflection
+ * @link second test for reflection with second value
+ */
+class ReflectionServiceTest extends UnitTestCase
+{
+    /**
+     * @test
+     */
+    public function getClassSchemaThrowsExceptionIfClassIsNotFound(): void
+    {
+        $this->expectException(UnknownClassException::class);
+        $this->expectExceptionCode(1278450972);
+        $this->expectExceptionMessage('Class Foo\Bar\Not\Existing does not exist. Reflection failed.');
+        $reflectionService = new ReflectionService();
+        $reflectionService->getClassSchema('Foo\Bar\Not\Existing');
+    }
+
+    /**
+     * @test
+     */
+    public function getClassSchemaThrowsExceptionIfTypeHintedClassWasNotFound(): void
+    {
+        $this->expectException(UnknownClassException::class);
+        $this->expectExceptionCode(1278450972);
+        $this->expectExceptionMessage('Class Foo\Bar\Not\Found does not exist. Reflection failed.');
+        $reflectionService = new ReflectionService();
+        $reflectionService->getClassSchema(DummyClassWithInvalidTypeHint::class);
+    }
+}
index 4c2bfea..1766cc0 100644 (file)
@@ -21,6 +21,32 @@ namespace TYPO3\CMS\Extbase\Tests\UnitDeprecated\Reflection\Fixture;
  */
 class DummyClassWithAllTypesOfProperties
 {
+    public $publicProperty;
+
+    protected $protectedProperty;
+
+    private $privateProperty;
+
+    public static $publicStaticProperty;
+
+    protected static $protectedStaticProperty;
+
+    private static $privateStaticProperty;
+
+    /**
+     * @license
+     * @copyright
+     * @author
+     * @version
+     */
+    public $propertyWithIgnoredTags;
+
+    /**
+     * @inject
+     * @var DummyClassWithAllTypesOfProperties
+     */
+    public $propertyWithInjectAnnotation;
+
     /**
      * @transient
      */
@@ -36,4 +62,9 @@ class DummyClassWithAllTypesOfProperties
      * @cascade remove
      */
     public $propertyWithCascadeAnnotationWithoutVarAnnotation;
+
+    /**
+     * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Tests\Unit\Reflection\Fixture\DummyClassWithAllTypesOfProperties>
+     */
+    public $propertyWithObjectStorageAnnotation;
 }
diff --git a/typo3/sysext/extbase/Tests/UnitDeprecated/Reflection/Fixture/DummyClassWithTags.php b/typo3/sysext/extbase/Tests/UnitDeprecated/Reflection/Fixture/DummyClassWithTags.php
new file mode 100644 (file)
index 0000000..215d34e
--- /dev/null
@@ -0,0 +1,29 @@
+<?php
+namespace TYPO3\CMS\Extbase\Tests\UnitDeprecated\Reflection\Fixture;
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+/**
+ * Fixture class with tags
+ *
+ * @license
+ * @copyright
+ * @author
+ * @version
+ *
+ * @see
+ */
+class DummyClassWithTags
+{
+}
index ce106dc..acd0473 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 declare(strict_types = 1);
 
-namespace TYPO3\CMS\Extbase\Tests\Unit\Reflection;
+namespace TYPO3\CMS\Extbase\Tests\UnitDeprecated\Reflection;
 
 /*
  * This file is part of the TYPO3 CMS project.
@@ -220,7 +220,7 @@ class ReflectionServiceTest extends UnitTestCase
         $this->assertTrue($service->isPropertyTaggedWith(
             Fixture\DummyClassWithAllTypesOfProperties::class,
             'propertyWithInjectAnnotation',
-            'extbase\inject'
+            'inject'
         ));
 
         $this->assertFalse($service->isPropertyTaggedWith(
@@ -238,7 +238,7 @@ class ReflectionServiceTest extends UnitTestCase
         $this->assertFalse($service->isPropertyTaggedWith(
             'NonExistantNamespace\\NonExistantClass',
             'propertyWithInjectAnnotation',
-            'extbase\inject'
+            'inject'
         ));
     }
 
@@ -269,7 +269,7 @@ class ReflectionServiceTest extends UnitTestCase
         $service = new ReflectionService();
         $this->assertSame(
             [
-                'extbase\inject' => [],
+                'inject' => [],
                 'var' => [
                     'DummyClassWithAllTypesOfProperties'
                 ]