Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4edf29d

Browse files
bamarnifabpot
authored andcommitted
added helperSet to console event objects
1 parent f224102 commit 4edf29d

File tree

4 files changed

+40
-38
lines changed

4 files changed

+40
-38
lines changed

src/Symfony/Bundle/FrameworkBundle/Command/ContainerAwareCommand.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,16 @@ abstract class ContainerAwareCommand extends Command implements ContainerAwareIn
3838
public function run(InputInterface $input, OutputInterface $output)
3939
{
4040
$dispatcher = $this->getContainer()->get('event_dispatcher');
41+
$helperSet = $this->getHelperSet();
4142

4243
$initEvent = new ConsoleEvent($input, $output);
44+
$initEvent->setHelperSet($helperSet);
4345
$dispatcher->dispatch(ConsoleEvents::INIT, $initEvent);
4446

4547
$exitCode = parent::run($input, $output);
4648

4749
$terminateEvent = new ConsoleTerminateEvent($input, $output, $exitCode);
50+
$terminateEvent->setHelperSet($helperSet);
4851
$dispatcher->dispatch(ConsoleEvents::TERMINATE, $terminateEvent);
4952

5053
return $exitCode;

src/Symfony/Bundle/FrameworkBundle/Event/ConsoleEvent.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Event;
1313

14+
use Symfony\Component\Console\Helper\HelperSet;
1415
use Symfony\Component\Console\Input\InputInterface;
1516
use Symfony\Component\Console\Output\OutputInterface;
1617
use Symfony\Component\EventDispatcher\Event;
@@ -26,12 +27,34 @@ class ConsoleEvent extends Event
2627

2728
private $output;
2829

30+
private $helperSet;
31+
2932
public function __construct(InputInterface $input, OutputInterface $output)
3033
{
3134
$this->input = $input;
3235
$this->output = $output;
3336
}
3437

38+
/**
39+
* Sets the helper set.
40+
*
41+
* @param HelperSet $helperSet A HelperSet instance
42+
*/
43+
public function setHelperSet(HelperSet $helperSet)
44+
{
45+
$this->helperSet = $helperSet;
46+
}
47+
48+
/**
49+
* Gets the helper set.
50+
*
51+
* @return HelperSet A HelperSet instance
52+
*/
53+
public function getHelperSet()
54+
{
55+
return $this->helperSet;
56+
}
57+
3558
/**
3659
* Returns the input object
3760
*

src/Symfony/Bundle/FrameworkBundle/Tests/Console/ApplicationTest.php

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313

1414
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
1515
use Symfony\Bundle\FrameworkBundle\Tests\Console\Fixtures\FooCommand;
16-
use Symfony\Bundle\FrameworkBundle\Tests\Console\Fixtures\SilentCommand;
1716
use Symfony\Bundle\FrameworkBundle\Console\Application;
17+
use Symfony\Bundle\FrameworkBundle\Console\ConsoleEvents;
1818
use Symfony\Component\Console\Input\ArrayInput;
1919
use Symfony\Component\Console\Output\NullOutput;
2020

@@ -51,16 +51,6 @@ public function testCommandDispatchEvents()
5151
$application->doRun(new ArrayInput(array('foo')), new NullOutput());
5252
}
5353

54-
public function testSilentCommand()
55-
{
56-
$kernel = $this->getKernel(array(), $this->never());
57-
58-
$application = new Application($kernel);
59-
$application->add(new SilentCommand('chut'));
60-
61-
$application->doRun(new ArrayInput(array('chut')), new NullOutput());
62-
}
63-
6454
private function getKernel(array $bundles, $dispatcherExpected = null)
6555
{
6656
$kernel = $this->getMock("Symfony\Component\HttpKernel\KernelInterface");
@@ -80,8 +70,19 @@ private function getKernel(array $bundles, $dispatcherExpected = null)
8070
} else {
8171
$eventDispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
8272
$eventDispatcher
83-
->expects($this->atLeastOnce())
84-
->method('dispatch');
73+
->expects($this->at(0))
74+
->method('dispatch')
75+
->with(
76+
$this->equalTo(ConsoleEvents::INIT),
77+
$this->isInstanceOf('Symfony\Bundle\FrameworkBundle\Event\ConsoleEvent')
78+
);
79+
$eventDispatcher
80+
->expects($this->at(1))
81+
->method('dispatch')
82+
->with(
83+
$this->equalTo(ConsoleEvents::TERMINATE),
84+
$this->isInstanceOf('Symfony\Bundle\FrameworkBundle\Event\ConsoleTerminateEvent')
85+
);
8586
$container
8687
->expects($dispatcherExpected)
8788
->method('get')

src/Symfony/Bundle/FrameworkBundle/Tests/Console/Fixtures/SilentCommand.php

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)