Skip to content

Commit

Permalink
Merge pull request #849 from driehle/symfony-console
Browse files Browse the repository at this point in the history
Dropped symfony/console 5.x, allow symfony/console 7.x
  • Loading branch information
driehle authored Dec 29, 2024
2 parents e1639cb + 3ced02b commit 13e2e3d
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 1 deletion.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"laminas/laminas-stdlib": "^3.13.0",
"laminas/laminas-validator": "^2.25.0",
"psr/container": "^1.1.2",
"symfony/console": "^5.4.16 || ^6.2.1"
"symfony/console": "^6.2.1 || ^7.0.0"
},
"require-dev": {
"doctrine/coding-standard": "^12.0.0",
Expand Down
58 changes: 58 additions & 0 deletions tests/Service/CliFactoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

declare(strict_types=1);

namespace DoctrineModuleTest\Service;

use DoctrineModule\Service\CliFactory;
use DoctrineModuleTest\Service\TestAsset\DummyCliCommand;
use Laminas\EventManager\EventInterface;
use Laminas\EventManager\EventManager;
use Laminas\ServiceManager\ServiceManager;
use PHPUnit\Framework\TestCase as BaseTestCase;
use Symfony\Component\Console\Application;

/**
* Base test case for the setup of Doctrine CLI
*/
class CliFactoryTest extends BaseTestCase
{
public function testSetupOfDoctrineCli(): void
{
$serviceManager = new ServiceManager();
$serviceManager->setService('config', []);
$serviceManager->setService('EventManager', new EventManager());

$factory = new CliFactory();
$app = $factory->__invoke($serviceManager, 'doctrine.cli');

$this->assertInstanceOf(Application::class, $app);
}

public function testRegistrationOfCustomCliCommand(): void
{
$serviceManager = new ServiceManager();
$eventManager = new EventManager();

$eventManager->attach(
'loadCli.post',
static function (EventInterface $event): void {
$target = $event->getTarget();
if (! ($target instanceof Application)) {
return;
}

$target->add(new DummyCliCommand());
},
);

$serviceManager->setService('config', []);
$serviceManager->setService('EventManager', $eventManager);

$factory = new CliFactory();
$app = $factory->__invoke($serviceManager, 'doctrine.cli');

$this->assertInstanceOf(Application::class, $app);
$this->assertTrue($app->has('app:dummy-command'));
}
}
30 changes: 30 additions & 0 deletions tests/Service/TestAsset/DummyCliCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace DoctrineModuleTest\Service\TestAsset;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class DummyCliCommand extends Command
{
protected function configure(): void
{
$this
->setName('app:dummy-command')
->setDescription('A dummy command for testing purposes.');
}

public function execute(InputInterface $input, OutputInterface $output): int
{
$output->writeln([
'Dummy Command',
'=============',
'',
]);

return Command::SUCCESS;
}
}

0 comments on commit 13e2e3d

Please sign in to comment.