-
-
Notifications
You must be signed in to change notification settings - Fork 268
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #849 from driehle/symfony-console
Dropped symfony/console 5.x, allow symfony/console 7.x
- Loading branch information
Showing
3 changed files
with
89 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |