‪TYPO3CMS  11.5
CommandRegistryTest.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 Prophecy\PhpUnit\ProphecyTrait;
21 use Prophecy\Prophecy\ObjectProphecy;
22 use Psr\Container\ContainerInterface;
23 use Symfony\Component\Console\Command\Command;
24 use Symfony\Component\Console\CommandLoader\CommandLoaderInterface;
26 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
27 
31 class ‪CommandRegistryTest extends UnitTestCase
32 {
33  use ProphecyTrait;
34 
36  protected ObjectProphecy ‪$containerProphecy;
37 
41  protected function ‪setUp(): void
42  {
43  parent::setUp();
44 
45  $this->containerProphecy = $this->prophesize(ContainerInterface::class);
46  }
47 
51  public function ‪implementsCommandLoaderInterface(): void
52  {
53  $commandRegistry = new ‪CommandRegistry($this->containerProphecy->reveal());
54  self::assertInstanceof(CommandLoaderInterface::class, $commandRegistry);
55  }
56 
60  public function ‪iteratesLazyCommandsOfActivePackages(): void
61  {
62  $command1Mock = $this->createMock(Command::class);
63  $command2Mock = $this->createMock(Command::class);
64  $command1MockClass = get_class($command1Mock);
65  $command2MockClass = get_class($command2Mock);
66 
67  $this->containerProphecy->get('command1')->willReturn($command1Mock);
68  $this->containerProphecy->get('command2')->willReturn($command2Mock);
69 
70  $commandRegistry = new ‪CommandRegistry($this->containerProphecy->reveal());
71  $commandRegistry->addLazyCommand('test:command', 'command1');
72  $commandRegistry->addLazyCommand('test:command2', 'command2');
73 
74  $commandNames = $commandRegistry->getNames();
75 
76  self::assertCount(2, $commandNames);
77  self::assertInstanceOf($command1MockClass, $commandRegistry->get('test:command'));
78  self::assertInstanceOf($command2MockClass, $commandRegistry->get('test:command2'));
79  }
80 }
‪TYPO3\CMS\Core\Tests\Unit\Console\CommandRegistryTest\setUp
‪setUp()
Definition: CommandRegistryTest.php:40
‪TYPO3\CMS\Core\Tests\Unit\Console\CommandRegistryTest
Definition: CommandRegistryTest.php:32
‪TYPO3\CMS\Core\Tests\Unit\Console\CommandRegistryTest\iteratesLazyCommandsOfActivePackages
‪iteratesLazyCommandsOfActivePackages()
Definition: CommandRegistryTest.php:59
‪TYPO3\CMS\Core\Console\CommandRegistry
Definition: CommandRegistry.php:31
‪TYPO3\CMS\Core\Tests\Unit\Console\CommandRegistryTest\$containerProphecy
‪ObjectProphecy $containerProphecy
Definition: CommandRegistryTest.php:35
‪TYPO3\CMS\Core\Tests\Unit\Console
Definition: CommandRegistryTest.php:18
‪TYPO3\CMS\Core\Tests\Unit\Console\CommandRegistryTest\implementsCommandLoaderInterface
‪implementsCommandLoaderInterface()
Definition: CommandRegistryTest.php:50