‪TYPO3CMS  11.5
ContainerTest.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 
20 use Psr\Container\ContainerInterface;
21 use Psr\Container\NotFoundExceptionInterface;
22 use Psr\Log\LoggerInterface;
29 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
30 
34 class ‪ContainerTest extends UnitTestCase
35 {
39  protected ‪$resetSingletonInstances = true;
40 
44  protected ‪$subject;
45 
49  protected ‪$logger;
50 
51  protected function ‪setUp(): void
52  {
53  parent::setUp();
54  $this->logger = $this->getMockBuilder(Logger::class)
55  ->onlyMethods(['notice'])
56  ->disableOriginalConstructor()
57  ->getMock();
58  $reflectionService = new ‪ReflectionService(new ‪NullFrontend('extbase'), 'ClassSchemata');
59 
60  $notFoundException = new class () extends \‪Exception implements NotFoundExceptionInterface {};
61 
62  $psrContainer = $this->getMockBuilder(ContainerInterface::class)
63  ->onlyMethods(['has', 'get'])
64  ->getMock();
65  $psrContainer->method('has')->willReturn(false);
66  $psrContainer->method('get')->will(self::throwException($notFoundException));
67 
68  $this->subject = $this->getMockBuilder(Container::class)
69  ->setConstructorArgs([$psrContainer])
70  ->onlyMethods(['getReflectionService'])
71  ->addMethods(['getLogger'])
72  ->getMock();
73  $this->subject->setLogger($this->logger);
74  $this->subject->method('getReflectionService')->willReturn($reflectionService);
75  }
76 
80  public function ‪getInstanceInjectsPublicProperties(): void
81  {
82  $object = $this->subject->getInstance(PublicPropertyInjectClass::class);
83  self::assertInstanceOf(ArgumentTestClassForPublicPropertyInjection::class, $object->foo);
84  }
85 }
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Object\Container\ContainerTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: ContainerTest.php:38
‪TYPO3\CMS\Extbase\Object\Container\Container
Definition: Container.php:42
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Object\Container
Definition: ContainerTest.php:18
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Object\Container\ContainerTest\$subject
‪Container $subject
Definition: ContainerTest.php:42
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Object\Container\Fixtures\ArgumentTestClassForPublicPropertyInjection
Definition: ContainerPropertyInjectionTestClasses.php:30
‪TYPO3\CMS\Core\Cache\Frontend\NullFrontend
Definition: NullFrontend.php:29
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Object\Container\ContainerTest\$logger
‪LoggerInterface PHPUnit Framework MockObject MockObject $logger
Definition: ContainerTest.php:46
‪TYPO3\CMS\Extbase\Reflection\ReflectionService
Definition: ReflectionService.php:28
‪TYPO3\CMS\Extbase\Exception
Definition: Exception.php:25
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Object\Container\ContainerTest\setUp
‪setUp()
Definition: ContainerTest.php:48
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Object\Container\ContainerTest
Definition: ContainerTest.php:35
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Object\Container\ContainerTest\getInstanceInjectsPublicProperties
‪getInstanceInjectsPublicProperties()
Definition: ContainerTest.php:77
‪TYPO3\CMS\Core\Log\Logger
Definition: Logger.php:27
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Object\Container\Fixtures\PublicPropertyInjectClass
Definition: ContainerPropertyInjectionTestClasses.php:23