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