‪TYPO3CMS  11.5
ConsoleCommandPassTest.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\Argument;
21 use Prophecy\PhpUnit\ProphecyTrait;
22 use Psr\Container\ContainerInterface;
23 use Symfony\Component\Console\Command\Command;
26 use TYPO3\CMS\Core\DependencyInjection\ContainerBuilder;
28 use TYPO3\CMS\Core\Package\PackageManager;
31 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
32 
33 class ‪ConsoleCommandPassTest extends UnitTestCase
34 {
35  use ProphecyTrait;
36 
37  protected function ‪buildContainer(string $uniqid, array $packages = []): ContainerInterface
38  {
39  $packageManagerProphecy = $this->prophesize(PackageManager::class);
40  $activePackages = [];
41  foreach ($packages as $packageKey => $config) {
42  $packageProphecy = $this->prophesize(Package::class);
43  $packageProphecy->getPackageKey()->willReturn($packageKey);
44  $packageProphecy->getPackagePath()->willReturn($config['path']);
45  $packageProphecy->isPartOfMinimalUsableSystem()->willReturn(false);
46  $packageProphecy->getServiceProvider()->willReturn($config['serviceProvider'] ?? NullServiceProvider::class);
47  $activePackages[$packageKey] = $packageProphecy->reveal();
48 
49  $packageManagerProphecy->getPackage($packageKey)->willReturn($packageProphecy->reveal());
50  $packageManagerProphecy->isPackageActive($packageKey)->willReturn(true);
51  }
52  $packageManagerProphecy->getCacheIdentifier()->willReturn('PackageManager.' . $uniqid);
53  $packageManagerProphecy->getActivePackages()->willReturn($activePackages);
54 
55  $cache = $this->prophesize(PhpFrontend::class);
56  $cache->requireOnce(Argument::type('string'))->willReturn(false);
57  $cache->set(Argument::type('string'), Argument::type('string'))->will(function (‪$args) {
58  $sourceCode = ‪$args[1];
59  eval($sourceCode);
60  });
61 
62  $containerBuilder = new ContainerBuilder([]);
63  return $containerBuilder->createDependencyInjectionContainer($packageManagerProphecy->reveal(), $cache->reveal());
64  }
65 
69  public function ‪commandRegistrationViaTags(): void
70  {
71  $container = $this->‪buildContainer(__METHOD__, [
72  'command-registry-package' => [
73  'path' => __DIR__ . '/Fixtures/CommandRegistryPackage/',
74  'serviceProvider' => CommandRegistryServiceProvider::class,
75  ],
76  'package1' => [
77  'path' => __DIR__ . '/Fixtures/Package1/',
78  ],
79  ]);
80 
81  $commandRegistry = $container->get(CommandRegistry::class);
82 
83  self::assertTrue($commandRegistry->has('test:cmd'));
84  self::assertEquals(['test:cmd'], $commandRegistry->getNames());
85  self::assertEquals('Dummy description including new as word', $commandRegistry->filter()['test:cmd']['description'] ?? '');
86  self::assertInstanceOf(Command::class, $commandRegistry->getCommandByIdentifier('test:cmd'));
87  }
88 
92  public function ‪withoutConfiguration(): void
93  {
94  $container = $this->‪buildContainer(__METHOD__, [
95  'command-registry-package' => [
96  'path' => __DIR__ . '/Fixtures/CommandRegistryPackage/',
97  'serviceProvider' => CommandRegistryServiceProvider::class,
98  ],
99  ]);
100 
101  $commandRegistry = $container->get(CommandRegistry::class);
102 
103  self::assertEquals([], $commandRegistry->getNames());
104  self::assertFalse($commandRegistry->has('unknown:command'));
105  }
106 }
‪TYPO3\CMS\Core\Tests\Unit\DependencyInjection\ConsoleCommandPassTest\buildContainer
‪buildContainer(string $uniqid, array $packages=[])
Definition: ConsoleCommandPassTest.php:36
‪TYPO3\CMS\Core\Tests\Unit\DependencyInjection\ConsoleCommandPassTest\withoutConfiguration
‪withoutConfiguration()
Definition: ConsoleCommandPassTest.php:91
‪TYPO3\CMS\Core\Tests\Unit\DependencyInjection\ConsoleCommandPassTest\commandRegistrationViaTags
‪commandRegistrationViaTags()
Definition: ConsoleCommandPassTest.php:68
‪TYPO3\CMS\Core\Cache\Frontend\PhpFrontend
Definition: PhpFrontend.php:25
‪TYPO3\CMS\Core\Tests\Unit\DependencyInjection\ConsoleCommandPassTest
Definition: ConsoleCommandPassTest.php:34
‪TYPO3\CMS\Core\Tests\Unit\DependencyInjection\Fixtures\NullServiceProvider
Definition: NullServiceProvider.php:23
‪TYPO3\CMS\Core\Console\CommandRegistry
Definition: CommandRegistry.php:31
‪TYPO3\CMS\Core\Tests\Unit\DependencyInjection
Definition: ConsoleCommandPassTest.php:18
‪TYPO3\CMS\Core\Package\Package
Definition: Package.php:28
‪TYPO3\CMS\Core\Tests\Unit\DependencyInjection\Fixtures\CommandRegistryPackage\CommandRegistryServiceProvider
Definition: CommandRegistryServiceProvider.php:25
‪$args
‪$args
Definition: validateRstFiles.php:214