‪TYPO3CMS  ‪main
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 PHPUnit\Framework\Attributes\Test;
21 use PHPUnit\Framework\MockObject\MockObject;
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 
28 final class ‪CommandRegistryTest extends UnitTestCase
29 {
30  protected ContainerInterface&MockObject ‪$containerMock;
31 
32  protected function ‪setUp(): void
33  {
34  parent::setUp();
35 
36  $this->containerMock = $this->createMock(ContainerInterface::class);
37  }
38 
39  #[Test]
40  public function ‪implementsCommandLoaderInterface(): void
41  {
42  $commandRegistry = new ‪CommandRegistry($this->containerMock);
43  self::assertInstanceof(CommandLoaderInterface::class, $commandRegistry);
44  }
45 
46  #[Test]
48  {
49  $command1Mock = $this->createMock(Command::class);
50  $command2Mock = $this->createMock(Command::class);
51 
52  $this->containerMock->method('get')->willReturnMap([
53  ['command1', $command1Mock],
54  ['command2', $command2Mock],
55  ]);
56 
57  $commandRegistry = new ‪CommandRegistry($this->containerMock);
58  $commandRegistry->addLazyCommand('test:command', 'command1');
59  $commandRegistry->addLazyCommand('test:command2', 'command2');
60 
61  $commandNames = $commandRegistry->getNames();
62 
63  self::assertCount(2, $commandNames);
64  self::assertInstanceOf(get_class($command1Mock), $commandRegistry->get('test:command'));
65  self::assertInstanceOf(get_class($command2Mock), $commandRegistry->get('test:command2'));
66  }
67 }
‪TYPO3\CMS\Core\Tests\Unit\Console\CommandRegistryTest\setUp
‪setUp()
Definition: CommandRegistryTest.php:32
‪TYPO3\CMS\Core\Tests\Unit\Console\CommandRegistryTest
Definition: CommandRegistryTest.php:29
‪TYPO3\CMS\Core\Tests\Unit\Console\CommandRegistryTest\iteratesLazyCommandsOfActivePackages
‪iteratesLazyCommandsOfActivePackages()
Definition: CommandRegistryTest.php:47
‪TYPO3\CMS\Core\Console\CommandRegistry
Definition: CommandRegistry.php:31
‪TYPO3\CMS\Core\Tests\Unit\Console
Definition: CommandRegistryTest.php:18
‪TYPO3\CMS\Core\Tests\Unit\Console\CommandRegistryTest\implementsCommandLoaderInterface
‪implementsCommandLoaderInterface()
Definition: CommandRegistryTest.php:40
‪TYPO3\CMS\Core\Tests\Unit\Console\CommandRegistryTest\$containerMock
‪ContainerInterface &MockObject $containerMock
Definition: CommandRegistryTest.php:30