Skip to content

Commit

Permalink
We must register the hook manager as a subscriber on the event dispat…
Browse files Browse the repository at this point in the history
…cher; otherwise, the command-event hooks will not be called.
  • Loading branch information
greg-1-anderson committed Sep 23, 2016
1 parent 6d27f03 commit 8d654a1
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 13 deletions.
22 changes: 11 additions & 11 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions src/Robo.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,12 @@ public static function configureContainer(ContainerInterface $container, Config
$container->share('resultPrinter', \Robo\Log\ResultPrinter::class);
$container->add('simulator', \Robo\Task\Simulator::class);
$container->share('globalOptionsEventListener', \Robo\GlobalOptionsEventListener::class);
$container->share('eventDispatcher', \Symfony\Component\EventDispatcher\EventDispatcher::class)
->withMethodCall('addSubscriber', ['globalOptionsEventListener']);
$container->share('collectionProcessHook', \Robo\Collection\CollectionProcessHook::class);
$container->share('hookManager', \Consolidation\AnnotatedCommand\Hooks\HookManager::class)
->withMethodCall('addResultProcessor', ['collectionProcessHook', '*']);
$container->share('eventDispatcher', \Symfony\Component\EventDispatcher\EventDispatcher::class)
->withMethodCall('addSubscriber', ['globalOptionsEventListener'])
->withMethodCall('addSubscriber', ['hookManager']);
$container->share('formatterManager', \Consolidation\OutputFormatters\FormatterManager::class);
$container->share('commandProcessor', \Consolidation\AnnotatedCommand\CommandProcessor::class)
->withArgument('hookManager')
Expand Down
21 changes: 21 additions & 0 deletions tests/src/RoboFileFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,27 @@ public function testSymfonyStyle()
$this->io()->text('Some text in section two.');
}

/**
* @hook command-event test:command-event
*/
public function hookCommandEvent()
{
$this->io()->text('This is the command-event hook for the test:command-event command.');
}

public function testCommandEvent()
{
$this->io()->text('This is the main method for the test:command-event command.');
}

/**
* @hook post-command test:command-event
*/
public function hookPostCommand()
{
$this->io()->text('This is the post-command hook for the test:command-event command.');
}

/**
* Demonstrate Robo error output and command failure.
*/
Expand Down
13 changes: 13 additions & 0 deletions tests/unit/RunnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,19 @@ public function testSymfonyStyle()
$this->guy->seeInOutput('Some text in section one.');
}

public function testCommandEventHook()
{
$argv = ['placeholder', 'test:command-event'];
$this->runner->execute($argv, null, null, $this->guy->capturedOutputStream());

$expected = <<<EOT
This is the command-event hook for the test:command-event command.
This is the main method for the test:command-event command.
This is the post-command hook for the test:command-event command.
EOT;
$this->guy->seeInOutput($expected);
}

public function testRoboStaticRunMethod()
{
$argv = ['placeholder', 'test:symfony-style'];
Expand Down

0 comments on commit 8d654a1

Please sign in to comment.