2 declare(strict_types
=1);
3 namespace TYPO3\CMS\Core\Tests\Unit\Console
;
6 * This file is part of the TYPO3 CMS project.
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.
12 * For the full copyright and license information, please read the
13 * LICENSE.txt file that was distributed with this source code.
15 * The TYPO3 project - inspiring people to share!
18 use org\bovigo\vfs\vfsStream
;
19 use Symfony\Component\Console\Command\Command
;
20 use TYPO3\CMS\Core\Console\CommandNameAlreadyInUseException
;
21 use TYPO3\CMS\Core\Console\CommandRegistry
;
22 use TYPO3\CMS\Core\Package\PackageInterface
;
23 use TYPO3\CMS\Core\Package\PackageManager
;
24 use TYPO3\TestingFramework\Core\Unit\UnitTestCase
;
27 * Testcase for CommandRegistry
29 class CommandRegistryTest
extends UnitTestCase
32 * @var \org\bovigo\vfs\vfsStreamDirectory
34 protected $rootDirectory;
37 * @var PackageManager|\Prophecy\Prophecy\ObjectProphecy
39 protected $packageManagerProphecy;
42 * Set up this testcase
44 protected function setUp()
46 $commandMockClass = $this->getMockClass(Command
::class, ['dummy']);
47 $this->rootDirectory
= vfsStream
::setup('root', null, [
50 'Commands.php' => '<?php return ["first:command" => [ "class" => "' . $commandMockClass . '" ]];',
55 'Commands.php' => '<?php return ["second:command" => [ "class" => "' . $commandMockClass . '" ]];',
60 'Commands.php' => '<?php return ["third:command" => [ "class" => "' . $commandMockClass . '" ]];',
65 'Commands.php' => '<?php return ["third:command" => [ "class" => "' . $commandMockClass . '" ]];',
70 /** @var PackageManager */
71 $this->packageManagerProphecy
= $this->prophesize(PackageManager
::class);
77 public function iteratesCommandsOfActivePackages()
79 /** @var PackageInterface */
80 $package1 = $this->prophesize(PackageInterface
::class);
81 $package1->getPackagePath()->willReturn($this->rootDirectory
->getChild('package1')->url() . '/');
82 /** @var PackageInterface */
83 $package2 = $this->prophesize(PackageInterface
::class);
84 $package2->getPackagePath()->willReturn($this->rootDirectory
->getChild('package2')->url() . '/');
86 $this->packageManagerProphecy
->getActivePackages()->willReturn([$package1->reveal(), $package2->reveal()]);
88 $commandRegistry = new CommandRegistry($this->packageManagerProphecy
->reveal());
89 $commands = iterator_to_array($commandRegistry);
91 $this->assertCount(2, $commands);
92 $this->assertContainsOnlyInstancesOf(Command
::class, $commands);
98 public function throwsExceptionOnDuplicateCommand()
100 /** @var PackageInterface */
101 $package3 = $this->prophesize(PackageInterface
::class);
102 $package3->getPackagePath()->willReturn($this->rootDirectory
->getChild('package3')->url() . '/');
103 /** @var PackageInterface */
104 $package4 = $this->prophesize(PackageInterface
::class);
105 $package4->getPackagePath()->willReturn($this->rootDirectory
->getChild('package4')->url() . '/');
106 $package4->getPackageKey()->willReturn('package4');
108 $this->packageManagerProphecy
->getActivePackages()->willReturn([$package3->reveal(), $package4->reveal()]);
110 $this->expectException(CommandNameAlreadyInUseException
::class);
111 $this->expectExceptionCode(1484486383);
113 $commandRegistry = new CommandRegistry($this->packageManagerProphecy
->reveal());
114 iterator_to_array($commandRegistry);