diff --git a/composer.json b/composer.json index 446eddc8..a6cc3c18 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ "joomla/test": "^4.0", "phpunit/phpunit": "^12.0", "psr/container": "^2.0", - "squizlabs/php_codesniffer": "~3.10.2", + "squizlabs/php_codesniffer": "^3.10.2", "phpstan/phpstan": "2.1.17", "phpstan/phpstan-deprecation-rules": "2.0.3" }, diff --git a/tests/ApplicationTest.php b/tests/ApplicationTest.php index fce3f2ad..a7841d62 100644 --- a/tests/ApplicationTest.php +++ b/tests/ApplicationTest.php @@ -12,10 +12,15 @@ use Joomla\Console\Command\HelpCommand; use Joomla\Console\Command\ListCommand; use Joomla\Console\ConsoleEvents; +use Joomla\Console\Descriptor\ApplicationDescription; +use Joomla\Console\Descriptor\TextDescriptor; use Joomla\Console\Event\ApplicationErrorEvent; use Joomla\Console\Event\BeforeCommandExecuteEvent; use Joomla\Console\Event\CommandErrorEvent; +use Joomla\Console\Event\ConsoleEvent; +use Joomla\Console\Event\TerminateEvent; use Joomla\Console\Exception\NamespaceNotFoundException; +use Joomla\Console\Helper\DescriptorHelper; use Joomla\Console\Loader\ContainerLoader; use Joomla\Console\Tests\Fixtures\Command\AliasedCommand; use Joomla\Console\Tests\Fixtures\Command\AnonymousCommand; @@ -25,8 +30,10 @@ use Joomla\Console\Tests\Fixtures\Command\TopNamespacedCommand; use Joomla\Event\Dispatcher; use Joomla\Test\TestHelper; -use PHPUnit\Framework\TestCase; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\UsesClass; +use PHPUnit\Framework\TestCase; use Psr\Container\ContainerInterface; use Psr\Container\NotFoundExceptionInterface; use Symfony\Component\Console\Exception\CommandNotFoundException; @@ -40,6 +47,19 @@ /** * Test class for \Joomla\Console\Application */ +#[CoversClass(Application::class)] +#[UsesClass(AbstractCommand::class)] +#[UsesClass(HelpCommand::class)] +#[UsesClass(ListCommand::class)] +#[UsesClass(ApplicationDescription::class)] +#[UsesClass(TextDescriptor::class)] +#[UsesClass(ApplicationErrorEvent::class)] +#[UsesClass(BeforeCommandExecuteEvent::class)] +#[UsesClass(CommandErrorEvent::class)] +#[UsesClass(ConsoleEvent::class)] +#[UsesClass(TerminateEvent::class)] +#[UsesClass(DescriptorHelper::class)] +#[UsesClass(ContainerLoader::class)] class ApplicationTest extends TestCase { /** @@ -58,15 +78,6 @@ protected function setUp(): void $this->object = new Application(); } - /** - * @covers Joomla\Console\Application - * @uses Joomla\Console\Command\AbstractCommand - * @uses Joomla\Console\Command\HelpCommand - * @uses Joomla\Console\Command\ListCommand - * @uses Joomla\Console\Descriptor\ApplicationDescription - * @uses Joomla\Console\Descriptor\TextDescriptor - * @uses Joomla\Console\Helper\DescriptorHelper - */ public function testTheApplicationIsExecutedWithTheDefaultCommand() { $input = new ArrayInput([]); @@ -79,15 +90,6 @@ public function testTheApplicationIsExecutedWithTheDefaultCommand() $this->assertNotEmpty($output->fetch()); } - /** - * @covers Joomla\Console\Application - * @uses Joomla\Console\Command\AbstractCommand - * @uses Joomla\Console\Command\HelpCommand - * @uses Joomla\Console\Command\ListCommand - * @uses Joomla\Console\Descriptor\ApplicationDescription - * @uses Joomla\Console\Descriptor\TextDescriptor - * @uses Joomla\Console\Helper\DescriptorHelper - */ public function testTheApplicationIsExecutedWithTheRequestedCommand() { $input = new ArrayInput( @@ -104,15 +106,6 @@ public function testTheApplicationIsExecutedWithTheRequestedCommand() $this->assertNotEmpty($output->fetch()); } - /** - * @covers Joomla\Console\Application - * @uses Joomla\Console\Command\AbstractCommand - * @uses Joomla\Console\Command\HelpCommand - * @uses Joomla\Console\Command\ListCommand - * @uses Joomla\Console\Descriptor\ApplicationDescription - * @uses Joomla\Console\Descriptor\TextDescriptor - * @uses Joomla\Console\Helper\DescriptorHelper - */ public function testTheApplicationPrintsTheVersionInformation() { $input = new ArrayInput( @@ -131,18 +124,12 @@ public function testTheApplicationPrintsTheVersionInformation() $this->assertSame('Console Tester 1.0.0', trim($output->fetch())); } - /** - * @covers Joomla\Console\Application - */ public function testSetGetName() { $this->object->setName('Console Application'); $this->assertSame('Console Application', $this->object->getName()); } - /** - * @covers Joomla\Console\Application - */ public function testSetGetVersion() { $this->object->setVersion('1.0.0'); @@ -169,10 +156,6 @@ public static function dataGetLongVersionProvider(): array * @param string $name Application name * @param string $version Application version * @param string $expected Expected return - * - * @covers Joomla\Console\Application - * - * @dataProvider dataGetLongVersion */ #[DataProvider('dataGetLongVersionProvider')] public function testGetLongVersion(string $name, string $version, string $expected) @@ -182,12 +165,6 @@ public function testGetLongVersion(string $name, string $version, string $expect $this->assertSame($expected, $this->object->getLongVersion()); } - /** - * @covers Joomla\Console\Application - * @uses Joomla\Console\Command\AbstractCommand - * @uses Joomla\Console\Command\HelpCommand - * @uses Joomla\Console\Command\ListCommand - */ public function testGetAllCommands() { $commands = $this->object->getAllCommands(); @@ -199,13 +176,6 @@ public function testGetAllCommands() $this->assertCount(1, $commands); } - /** - * @covers Joomla\Console\Application - * @uses Joomla\Console\Command\AbstractCommand - * @uses Joomla\Console\Command\HelpCommand - * @uses Joomla\Console\Command\ListCommand - * @uses Joomla\Console\Loader\ContainerLoader - */ public function testGetAllCommandsWithCommandLoader() { $commands = $this->object->getAllCommands(); @@ -231,12 +201,6 @@ function (ContainerInterface $container) { $this->assertCount(2, $commands); } - /** - * @covers Joomla\Console\Application - * @uses Joomla\Console\Command\AbstractCommand - * @uses Joomla\Console\Command\HelpCommand - * @uses Joomla\Console\Command\ListCommand - */ public function testAddHasCommand() { $this->object->addCommand(new NamespacedCommand()); @@ -246,12 +210,6 @@ public function testAddHasCommand() $this->assertFalse($this->object->hasCommand('test:disabled')); } - /** - * @covers Joomla\Console\Application - * @uses Joomla\Console\Command\AbstractCommand - * @uses Joomla\Console\Command\HelpCommand - * @uses Joomla\Console\Command\ListCommand - */ public function testAddCommandWithBrokenConstructor() { $this->expectException(LogicException::class); @@ -260,12 +218,6 @@ public function testAddCommandWithBrokenConstructor() $this->object->addCommand(new SkipConfigurationCommand()); } - /** - * @covers Joomla\Console\Application - * @uses Joomla\Console\Command\AbstractCommand - * @uses Joomla\Console\Command\HelpCommand - * @uses Joomla\Console\Command\ListCommand - */ public function testAddCommandWithNoName() { $this->expectException(LogicException::class); @@ -274,12 +226,6 @@ public function testAddCommandWithNoName() $this->object->addCommand(new AnonymousCommand()); } - /** - * @covers Joomla\Console\Application - * @uses Joomla\Console\Command\AbstractCommand - * @uses Joomla\Console\Command\HelpCommand - * @uses Joomla\Console\Command\ListCommand - */ public function testHasGetCommand() { $this->assertTrue($this->object->hasCommand('list')); @@ -291,10 +237,7 @@ public function testHasGetCommand() $this->assertSame($command, $this->object->getCommand('test:namespaced')); // Simulates passing the --help option - $r = new \ReflectionObject($this->object); - $p = $r->getProperty('wantsHelp'); - $p->setAccessible(true); - $p->setValue($this->object, true); + TestHelper::setValue($this->object, 'wantsHelp', true); /** @var HelpCommand $helpCommand */ $helpCommand = $this->object->getCommand('test:namespaced'); @@ -306,13 +249,6 @@ public function testHasGetCommand() ); } - /** - * @covers Joomla\Console\Application - * @uses Joomla\Console\Command\AbstractCommand - * @uses Joomla\Console\Command\HelpCommand - * @uses Joomla\Console\Command\ListCommand - * @uses Joomla\Console\Loader\ContainerLoader - */ public function testHasGetCommandWithCommandLoader() { $this->assertTrue($this->object->hasCommand('list')); @@ -333,12 +269,6 @@ function (ContainerInterface $container) { $this->assertInstanceOf(NamespacedCommand::class, $this->object->getCommand('test:namespaced')); } - /** - * @covers Joomla\Console\Application - * @uses Joomla\Console\Command\AbstractCommand - * @uses Joomla\Console\Command\HelpCommand - * @uses Joomla\Console\Command\ListCommand - */ public function testGetCommandForUnknownCommand() { $this->expectException(CommandNotFoundException::class); @@ -347,46 +277,28 @@ public function testGetCommandForUnknownCommand() $this->object->getCommand('test'); } - /** - * @covers Joomla\Console\Application - * @uses Joomla\Console\Command\AbstractCommand - * @uses Joomla\Console\Command\HelpCommand - * @uses Joomla\Console\Command\ListCommand - */ public function testGetNamespaces() { $this->object->addCommand(new NamespacedCommand()); $this->object->addCommand(new AliasedCommand()); - $this->assertEquals(['test'], $this->object->getNamespaces()); + $this->assertSame(['test'], $this->object->getNamespaces()); } - /** - * @covers Joomla\Console\Application - * @uses Joomla\Console\Command\AbstractCommand - * @uses Joomla\Console\Command\HelpCommand - * @uses Joomla\Console\Command\ListCommand - */ public function testFindNamespace() { $this->object->addCommand(new NamespacedCommand()); - $this->assertEquals('test', $this->object->findNamespace('test')); - $this->assertEquals( + $this->assertSame('test', $this->object->findNamespace('test')); + $this->assertSame( 'test', $this->object->findNamespace('t'), 'If an abbreviated namespace is given and is not ambiguous, the full namespace is returned' ); $this->object->addCommand(new AliasedCommand()); - $this->assertEquals('test', $this->object->findNamespace('test')); + $this->assertSame('test', $this->object->findNamespace('test')); } - /** - * @covers Joomla\Console\Application - * @uses Joomla\Console\Command\AbstractCommand - * @uses Joomla\Console\Command\HelpCommand - * @uses Joomla\Console\Command\ListCommand - */ public function testFindAmbiguousNamespace() { $this->expectException(NamespaceNotFoundException::class); @@ -398,12 +310,6 @@ public function testFindAmbiguousNamespace() $this->object->findNamespace('t'); } - /** - * @covers Joomla\Console\Application - * @uses Joomla\Console\Command\AbstractCommand - * @uses Joomla\Console\Command\HelpCommand - * @uses Joomla\Console\Command\ListCommand - */ public function testFindUnknownNamespace() { $this->expectException(NamespaceNotFoundException::class); @@ -412,14 +318,6 @@ public function testFindUnknownNamespace() $this->object->findNamespace('test'); } - /** - * @covers Joomla\Console\Application - * @uses Joomla\Console\Command\AbstractCommand - * @uses Joomla\Console\Command\HelpCommand - * @uses Joomla\Console\Command\ListCommand - * @uses Joomla\Console\Descriptor\TextDescriptor - * @uses Joomla\Console\Helper\DescriptorHelper - */ public function testNoOutputWhenHelpRequestedWithQuietFlag() { $input = new ArrayInput( @@ -437,15 +335,6 @@ public function testNoOutputWhenHelpRequestedWithQuietFlag() $this->assertEmpty($output->fetch()); } - /** - * @covers Joomla\Console\Application - * @uses Joomla\Console\Command\AbstractCommand - * @uses Joomla\Console\Command\HelpCommand - * @uses Joomla\Console\Command\ListCommand - * @uses Joomla\Console\Event\ApplicationErrorEvent - * @uses Joomla\Console\Event\CommandErrorEvent - * @uses Joomla\Console\Event\ConsoleEvent - */ public function testHandlingThrowables() { $input = new ArrayInput( @@ -471,19 +360,10 @@ public function testHandlingThrowables() $this->fail('The Throwable from the application should have been caught'); } catch (\Throwable $exception) { $this->assertInstanceOf(CommandNotFoundException::class, $exception); - $this->assertEquals('The command "foo" does not exist.', $exception->getMessage()); + $this->assertSame('The command "foo" does not exist.', $exception->getMessage()); } } - /** - * @covers Joomla\Console\Application - * @uses Joomla\Console\Command\AbstractCommand - * @uses Joomla\Console\Command\HelpCommand - * @uses Joomla\Console\Command\ListCommand - * @uses Joomla\Console\Descriptor\ApplicationDescription - * @uses Joomla\Console\Descriptor\TextDescriptor - * @uses Joomla\Console\Helper\DescriptorHelper - */ public function testAppIsClosedWhenAutoExitIsEnabled() { $input = new ArrayInput( @@ -501,15 +381,6 @@ public function testAppIsClosedWhenAutoExitIsEnabled() $this->assertTrue($app->wasClosed()); } - /** - * @covers Joomla\Console\Application - * @uses Joomla\Console\Command\AbstractCommand - * @uses Joomla\Console\Command\HelpCommand - * @uses Joomla\Console\Command\ListCommand - * @uses Joomla\Console\Event\ApplicationErrorEvent - * @uses Joomla\Console\Event\CommandErrorEvent - * @uses Joomla\Console\Event\ConsoleEvent - */ public function testExitCodeIsSetByEventListener() { $dispatcher = new Dispatcher(); @@ -536,14 +407,6 @@ function (ApplicationErrorEvent $event) { $this->assertSame(119, $app->getExitCode()); } - /** - * @covers Joomla\Console\Application - * @uses Joomla\Console\Command\AbstractCommand - * @uses Joomla\Console\Command\HelpCommand - * @uses Joomla\Console\Command\ListCommand - * @uses Joomla\Console\Event\CommandErrorEvent - * @uses Joomla\Console\Event\ConsoleEvent - */ public function testCommandNotFoundHasSuccessExitIfEventListenerSpecifiesSo() { $dispatcher = new Dispatcher(); @@ -570,14 +433,6 @@ function (CommandErrorEvent $event) { $this->assertSame(0, $app->getExitCode()); } - /** - * @covers Joomla\Console\Application - * @uses Joomla\Console\Command\AbstractCommand - * @uses Joomla\Console\Command\HelpCommand - * @uses Joomla\Console\Command\ListCommand - * @uses Joomla\Console\Event\ApplicationErrorEvent - * @uses Joomla\Console\Event\ConsoleEvent - */ public function testCommandErrorHasExitCodeOneIfExceptionHasCodeZero() { $command = new class () extends AbstractCommand { @@ -605,15 +460,6 @@ protected function doExecute(InputInterface $input, OutputInterface $output): in $this->assertSame(1, $app->getExitCode()); } - /** - * @covers Joomla\Console\Application - * @uses Joomla\Console\Command\AbstractCommand - * @uses Joomla\Console\Command\HelpCommand - * @uses Joomla\Console\Command\ListCommand - * @uses Joomla\Console\Event\BeforeCommandExecuteEvent - * @uses Joomla\Console\Event\ConsoleEvent - * @uses Joomla\Console\Event\TerminateEvent - */ public function testCommandIsNotExecutedIfEventSkipsCommand() { $command = new class () extends AbstractCommand { diff --git a/tests/Command/AbstractCommandTest.php b/tests/Command/AbstractCommandTest.php index d1d8ed8b..ba96433d 100644 --- a/tests/Command/AbstractCommandTest.php +++ b/tests/Command/AbstractCommandTest.php @@ -9,6 +9,8 @@ use Joomla\Console\Application; use Joomla\Console\Command\AbstractCommand; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\UsesClass; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputDefinition; @@ -19,11 +21,10 @@ /** * Test class for \Joomla\Console\Command\AbstractCommand */ +#[CoversClass(AbstractCommand::class)] +#[UsesClass(Application::class)] class AbstractCommandTest extends TestCase { - /** - * @covers Joomla\Console\Command\AbstractCommand - */ public function testTheCommandIsExecutedWithoutAnApplication() { $command = new class () extends AbstractCommand { @@ -33,16 +34,12 @@ protected function doExecute(InputInterface $input, OutputInterface $output): in } }; - $input = $this->createMock(InputInterface::class); - $output = $this->createMock(OutputInterface::class); + $input = $this->createStub(InputInterface::class); + $output = $this->createStub(OutputInterface::class); $this->assertSame(0, $command->execute($input, $output)); } - /** - * @covers Joomla\Console\Command\AbstractCommand - * @uses Joomla\Console\Application - */ public function testTheCommandIsExecutedWithAnApplication() { $command = new class () extends AbstractCommand { @@ -52,8 +49,8 @@ protected function doExecute(InputInterface $input, OutputInterface $output): in } }; - $input = $this->createMock(InputInterface::class); - $output = $this->createMock(OutputInterface::class); + $input = $this->createStub(InputInterface::class); + $output = $this->createStub(OutputInterface::class); $application = new Application($input, $output); @@ -62,9 +59,6 @@ protected function doExecute(InputInterface $input, OutputInterface $output): in $this->assertSame(0, $command->execute($input, $output)); } - /** - * @covers Joomla\Console\Command\AbstractCommand - */ public function testArgumentsAreAddedToTheDefinition() { $command = new class () extends AbstractCommand { @@ -78,9 +72,6 @@ protected function doExecute(InputInterface $input, OutputInterface $output): in $this->assertTrue($command->getDefinition()->hasArgument('test')); } - /** - * @covers Joomla\Console\Command\AbstractCommand - */ public function testOptionsAreAddedToTheDefinition() { $command = new class () extends AbstractCommand { @@ -94,9 +85,6 @@ protected function doExecute(InputInterface $input, OutputInterface $output): in $this->assertTrue($command->getDefinition()->hasOption('test')); } - /** - * @covers Joomla\Console\Command\AbstractCommand - */ public function testTheDefaultCommandNameIsRetrieved() { $command = new class () extends AbstractCommand { @@ -111,9 +99,6 @@ protected function doExecute(InputInterface $input, OutputInterface $output): in $this->assertSame('test:command', $command::getDefaultName()); } - /** - * @covers Joomla\Console\Command\AbstractCommand - */ public function testTheCommandHelpIsProcessed() { $command = new class () extends AbstractCommand { @@ -134,9 +119,6 @@ public function getHelp(): string $this->assertStringNotContainsString('%command.full_name%', $command->getProcessedHelp(), 'getProcessedHelp() replaces %command.full_name%'); } - /** - * @covers Joomla\Console\Command\AbstractCommand - */ public function testTheCommandSynopsisIsProcessed() { $command = new class () extends AbstractCommand { @@ -151,13 +133,9 @@ protected function doExecute(InputInterface $input, OutputInterface $output): in $command->addOption('foo'); $command->addArgument('bar'); - $this->assertEquals('test:command [--foo] [--] []', $command->getSynopsis()); + $this->assertSame('test:command [--foo] [--] []', $command->getSynopsis()); } - /** - * @covers Joomla\Console\Command\AbstractCommand - * @uses Joomla\Console\Application - */ public function testTheApplicationInputDefinitionIsMergedWithTheCommand() { $command = new class () extends AbstractCommand { @@ -167,8 +145,8 @@ protected function doExecute(InputInterface $input, OutputInterface $output): in } }; - $input = $this->createMock(InputInterface::class); - $output = $this->createMock(OutputInterface::class); + $input = $this->createStub(InputInterface::class); + $output = $this->createStub(OutputInterface::class); $application = new Application($input, $output); @@ -187,17 +165,13 @@ protected function doExecute(InputInterface $input, OutputInterface $output): in $command->mergeApplicationDefinition(); - $this->assertEquals( + $this->assertSame( 3, $command->getDefinition()->getArgumentCount(), 'mergeApplicationDefinition() does not try to merge the application arguments and options multiple times' ); } - /** - * @covers Joomla\Console\Command\AbstractCommand - * @uses Joomla\Console\Application - */ public function testTheArgumentsOfTheApplicationInputDefinitionAreNotMergedWithTheCommandUntilInstructed() { $command = new class () extends AbstractCommand { @@ -207,8 +181,8 @@ protected function doExecute(InputInterface $input, OutputInterface $output): in } }; - $input = $this->createMock(InputInterface::class); - $output = $this->createMock(OutputInterface::class); + $input = $this->createStub(InputInterface::class); + $output = $this->createStub(OutputInterface::class); $application = new Application($input, $output); @@ -230,10 +204,6 @@ protected function doExecute(InputInterface $input, OutputInterface $output): in $this->assertTrue($command->getDefinition()->hasArgument('foo')); } - /** - * @covers Joomla\Console\Command\AbstractCommand - * @uses Joomla\Console\Application - */ public function testTheApplicationHelperSetIsMergedToTheCommand() { $command = new class () extends AbstractCommand { @@ -243,8 +213,8 @@ protected function doExecute(InputInterface $input, OutputInterface $output): in } }; - $input = $this->createMock(InputInterface::class); - $output = $this->createMock(OutputInterface::class); + $input = $this->createStub(InputInterface::class); + $output = $this->createStub(OutputInterface::class); $application = new Application($input, $output); diff --git a/tests/Command/HelpCommandTest.php b/tests/Command/HelpCommandTest.php index 2695dba6..e1c28814 100644 --- a/tests/Command/HelpCommandTest.php +++ b/tests/Command/HelpCommandTest.php @@ -8,8 +8,13 @@ namespace Joomla\Console\Tests\Command; use Joomla\Console\Application; +use Joomla\Console\Command\AbstractCommand; use Joomla\Console\Command\HelpCommand; use Joomla\Console\Command\ListCommand; +use Joomla\Console\Descriptor\TextDescriptor; +use Joomla\Console\Helper\DescriptorHelper; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\UsesClass; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Output\BufferedOutput; @@ -17,16 +22,14 @@ /** * Test class for \Joomla\Console\Command\HelpCommand */ +#[CoversClass(HelpCommand::class)] +#[UsesClass(Application::class)] +#[UsesClass(AbstractCommand::class)] +#[UsesClass(ListCommand::class)] +#[UsesClass(TextDescriptor::class)] +#[UsesClass(DescriptorHelper::class)] class HelpCommandTest extends TestCase { - /** - * @covers Joomla\Console\Command\HelpCommand - * @uses Joomla\Console\Application - * @uses Joomla\Console\Command\AbstractCommand - * @uses Joomla\Console\Command\ListCommand - * @uses Joomla\Console\Descriptor\TextDescriptor - * @uses Joomla\Console\Helper\DescriptorHelper - */ public function testTheCommandIsExecutedWithACommandName() { $input = new ArrayInput( @@ -48,14 +51,6 @@ public function testTheCommandIsExecutedWithACommandName() $this->assertStringContainsString('list []', $screenOutput); } - /** - * @covers Joomla\Console\Command\HelpCommand - * @uses Joomla\Console\Application - * @uses Joomla\Console\Command\AbstractCommand - * @uses Joomla\Console\Command\ListCommand - * @uses Joomla\Console\Descriptor\TextDescriptor - * @uses Joomla\Console\Helper\DescriptorHelper - */ public function testTheCommandIsExecutedWithACommandClass() { $input = new ArrayInput( diff --git a/tests/Command/ListCommandTest.php b/tests/Command/ListCommandTest.php index 43c1f78a..a14bd470 100644 --- a/tests/Command/ListCommandTest.php +++ b/tests/Command/ListCommandTest.php @@ -8,8 +8,15 @@ namespace Joomla\Console\Tests\Command; use Joomla\Console\Application; +use Joomla\Console\Command\AbstractCommand; +use Joomla\Console\Command\HelpCommand; use Joomla\Console\Command\ListCommand; +use Joomla\Console\Descriptor\ApplicationDescription; +use Joomla\Console\Descriptor\TextDescriptor; +use Joomla\Console\Helper\DescriptorHelper; use Joomla\Console\Tests\Fixtures\Command\NamespacedCommand; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\UsesClass; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Output\BufferedOutput; @@ -17,17 +24,15 @@ /** * Test class for \Joomla\Console\Command\ListCommand */ +#[CoversClass(ListCommand::class)] +#[UsesClass(Application::class)] +#[UsesClass(AbstractCommand::class)] +#[UsesClass(HelpCommand::class)] +#[UsesClass(ApplicationDescription::class)] +#[UsesClass(TextDescriptor::class)] +#[UsesClass(DescriptorHelper::class)] class ListCommandTest extends TestCase { - /** - * @covers Joomla\Console\Command\ListCommand - * @uses Joomla\Console\Application - * @uses Joomla\Console\Command\AbstractCommand - * @uses Joomla\Console\Command\HelpCommand - * @uses Joomla\Console\Descriptor\ApplicationDescription - * @uses Joomla\Console\Descriptor\TextDescriptor - * @uses Joomla\Console\Helper\DescriptorHelper - */ public function testTheCommandIsExecuted() { $input = new ArrayInput( @@ -46,22 +51,9 @@ public function testTheCommandIsExecuted() $screenOutput = $output->fetch(); - if (method_exists($this, 'assertMatchesRegularExpression')) { - $this->assertMatchesRegularExpression('/help\s{2,}Show the help for a command/', $screenOutput); - } else { - $this->assertRegExp('/help\s{2,}Show the help for a command/', $screenOutput); - } + $this->assertMatchesRegularExpression('/help\s{2,}Show the help for a command/', $screenOutput); } - /** - * @covers Joomla\Console\Command\ListCommand - * @uses Joomla\Console\Application - * @uses Joomla\Console\Command\AbstractCommand - * @uses Joomla\Console\Command\HelpCommand - * @uses Joomla\Console\Descriptor\ApplicationDescription - * @uses Joomla\Console\Descriptor\TextDescriptor - * @uses Joomla\Console\Helper\DescriptorHelper - */ public function testTheCommandIsExecutedForANamespace() { $input = new ArrayInput( @@ -85,10 +77,6 @@ public function testTheCommandIsExecutedForANamespace() $screenOutput = $output->fetch(); - if (method_exists($this, 'assertMatchesRegularExpression')) { - $this->assertMatchesRegularExpression('/test:namespaced\s{2,}A testing command/', $screenOutput); - } else { - $this->assertRegExp('/test:namespaced\s{2,}A testing command/', $screenOutput); - } + $this->assertMatchesRegularExpression('/test:namespaced\s{2,}A testing command/', $screenOutput); } } diff --git a/tests/Loader/ContainerLoaderTest.php b/tests/Loader/ContainerLoaderTest.php index 656e7fed..ddca4e65 100644 --- a/tests/Loader/ContainerLoaderTest.php +++ b/tests/Loader/ContainerLoaderTest.php @@ -7,8 +7,11 @@ namespace Joomla\Console\Tests\Loader; +use Joomla\Console\Command\AbstractCommand; use Joomla\Console\Loader\ContainerLoader; use Joomla\Console\Tests\Fixtures\Command\NamespacedCommand; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\UsesClass; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Psr\Container\ContainerInterface; @@ -17,6 +20,8 @@ /** * Test class for \Joomla\Console\Loader\ContainerLoader */ +#[CoversClass(ContainerLoader::class)] +#[UsesClass(AbstractCommand::class)] class ContainerLoaderTest extends TestCase { /** @@ -35,10 +40,6 @@ protected function setUp(): void $this->container = $this->createMock(ContainerInterface::class); } - /** - * @covers Joomla\Console\Loader\ContainerLoader - * @uses Joomla\Console\Command\AbstractCommand - */ public function testTheLoaderRetrievesACommand() { $command = new NamespacedCommand(); @@ -62,9 +63,6 @@ public function testTheLoaderRetrievesACommand() ); } - /** - * @covers Joomla\Console\Loader\ContainerLoader - */ public function testTheLoaderDoesNotRetrieveAnUnknownCommand() { $this->expectException(CommandNotFoundException::class); @@ -83,9 +81,6 @@ public function testTheLoaderDoesNotRetrieveAnUnknownCommand() (new ContainerLoader($this->container, [$commandName => $serviceId]))->get($commandName); } - /** - * @covers Joomla\Console\Loader\ContainerLoader - */ public function testTheLoaderHasACommand() { $commandName = 'test:loader';