‪TYPO3CMS  9.5
ReflectionServiceTest.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
3 
5 
6 /*
7  * This file is part of the TYPO3 CMS project.
8  *
9  * It is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License, either version 2
11  * of the License, or any later version.
12  *
13  * For the full copyright and license information, please read the
14  * LICENSE.txt file that was distributed with this source code.
15  *
16  * The TYPO3 project - inspiring people to share!
17  */
18 
25 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
26 
33 class ‪ReflectionServiceTest extends UnitTestCase
34 {
39  {
40  $this->expectException(UnknownClassException::class);
41  $this->expectExceptionCode(1278450972);
42  $this->expectExceptionMessage('Class Foo\Bar\Not\Existing does not exist. Reflection failed.');
43  $reflectionService = new ‪ReflectionService();
44  $reflectionService->getClassSchema('Foo\Bar\Not\Existing');
45  }
46 
51  {
52  $this->expectException(UnknownClassException::class);
53  $this->expectExceptionCode(1278450972);
54  $this->expectExceptionMessage('Class Foo\Bar\Not\Found does not exist. Reflection failed.');
55  $reflectionService = new ‪ReflectionService();
56  $reflectionService->getClassSchema(DummyClassWithInvalidTypeHint::class);
57  }
58 
63  {
64  $class = new class() {
65  };
66 
67  $reflectionService = new ‪ReflectionService();
68  $serialized = serialize($reflectionService);
69  unset($reflectionService);
70 
71  $reflectionService = unserialize($serialized, ['allowed_classes' => [ReflectionService::class]]);
72 
73  self::assertInstanceOf(ReflectionService::class, $reflectionService);
74  self::assertInstanceOf(ClassSchema::class, $reflectionService->getClassSchema($class));
75  }
76 
81  {
82  $cacheProphecy = $this->prophesize(FrontendInterface::class);
83  $cacheProphecy->get('ClassSchematas')->willReturn(false);
84  $cacheManager = $this->prophesize(CacheManager::class);
85  $cacheManager->getCache('extbase_reflection')->willReturn($cacheProphecy->reveal());
86 
87  $class = new class() {
88  };
89 
90  $reflectionService = new ‪ReflectionService($cacheManager->reveal());
91  $serialized = serialize($reflectionService);
92  unset($reflectionService);
93 
94  $reflectionService = unserialize($serialized, ['allowed_classes' => [ReflectionService::class]]);
95 
96  self::assertInstanceOf(ReflectionService::class, $reflectionService);
97  self::assertInstanceOf(ClassSchema::class, $reflectionService->getClassSchema($class));
98  }
99 
104  {
105  $insecureString = file_get_contents(__DIR__ . '/Fixture/InsecureSerializedReflectionService.txt');
106  $reflectionService = unserialize($insecureString);
107 
108  $reflectionClass = new \ReflectionClass($reflectionService);
109  $classSchemaProperty = $reflectionClass->getProperty('classSchemata');
110  $classSchemaProperty->setAccessible(true);
111 
112  self::assertSame([], $classSchemaProperty->getValue($reflectionService));
113  }
114 }
‪TYPO3\CMS\Extbase\Tests\Unit\Reflection\ReflectionServiceTest\getClassSchemaThrowsExceptionIfClassIsNotFound
‪getClassSchemaThrowsExceptionIfClassIsNotFound()
Definition: ReflectionServiceTest.php:38
‪TYPO3\CMS\Extbase\Tests\Unit\Reflection\ReflectionServiceTest
Definition: ReflectionServiceTest.php:34
‪TYPO3\CMS\Extbase\Tests\Unit\Reflection\ReflectionServiceTest\reflectionServiceIsResetDuringWakeUp
‪reflectionServiceIsResetDuringWakeUp()
Definition: ReflectionServiceTest.php:103
‪TYPO3\CMS\Extbase\Reflection\ReflectionService
Definition: ReflectionService.php:27
‪TYPO3\CMS\Extbase\Reflection\Exception\UnknownClassException
Definition: UnknownClassException.php:21
‪TYPO3\CMS\Extbase\Tests\Unit\Reflection\ReflectionServiceTest\reflectionServiceCanBeSerializedAndUnserialized
‪reflectionServiceCanBeSerializedAndUnserialized()
Definition: ReflectionServiceTest.php:62
‪TYPO3\CMS\Core\Cache\CacheManager
Definition: CacheManager.php:34
‪TYPO3\CMS\Core\Cache\Frontend\FrontendInterface
Definition: FrontendInterface.php:21
‪TYPO3\CMS\Extbase\Reflection\ClassSchema
Definition: ClassSchema.php:41
‪TYPO3\CMS\Extbase\Tests\Unit\Reflection\ReflectionServiceTest\reflectionServiceCanBeSerializedAndUnserializedWithCacheManager
‪reflectionServiceCanBeSerializedAndUnserializedWithCacheManager()
Definition: ReflectionServiceTest.php:80
‪TYPO3\CMS\Extbase\Tests\Unit\Reflection\Fixture\DummyClassWithInvalidTypeHint
Definition: DummyClassWithInvalidTypeHint.php:23
‪TYPO3\CMS\Extbase\Tests\Unit\Reflection
Definition: ClassSchemaTest.php:2
‪TYPO3\CMS\Extbase\Tests\Unit\Reflection\ReflectionServiceTest\getClassSchemaThrowsExceptionIfTypeHintedClassWasNotFound
‪getClassSchemaThrowsExceptionIfTypeHintedClassWasNotFound()
Definition: ReflectionServiceTest.php:50