Skip to content

Commit ab63243

Browse files
committed
Instantiate helper in-class
- Do not rely on helper being defined "outside" of the phpcr context.
1 parent 7c64366 commit ab63243

File tree

4 files changed

+32
-9
lines changed

4 files changed

+32
-9
lines changed

src/PHPCR/Util/Console/Command/BaseCommand.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
use Symfony\Component\Console\Input\InputOption;
99
use Symfony\Component\Console\Output\OutputInterface;
1010
use PHPCR\Util\Console\Helper\PhpcrCliHelper;
11+
use PHPCR\Util\Console\Helper\PhpcrConsoleDumperHelper;
1112

1213
abstract class BaseCommand extends Command
1314
{
1415
protected $phpcrCliHelper;
16+
protected $phpcrConsoleDumperHelper;
1517

1618
/**
1719
* @return SessionInterface
@@ -33,6 +35,23 @@ protected function getPhpcrCliHelper()
3335
return $this->phpcrCliHelper;
3436
}
3537

38+
/**
39+
* @return PhpcrConsoleDumperHelper
40+
*/
41+
protected function getPhpcrConsoleDumperHelper()
42+
{
43+
if (!$this->phpcrConsoleDumperHelper) {
44+
$this->phpcrConsoleDumperHelper = new PhpcrConsoleDumperHelper();
45+
}
46+
47+
return $this->phpcrConsoleDumperHelper;
48+
}
49+
50+
public function setPhpcrConsoleDumperHelper($consoleDumperHelper)
51+
{
52+
$this->phpcrConsoleDumperHelper = $consoleDumperHelper;
53+
}
54+
3655
/**
3756
* Hack to enable overriding for unit tests.
3857
*/

src/PHPCR/Util/Console/Command/NodeDumpCommand.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ protected function configure()
7676
protected function execute(InputInterface $input, OutputInterface $output)
7777
{
7878
$session = $this->getPhpcrSession();
79-
/** @var $dumperHelper PhpcrConsoleDumperHelper */
80-
$dumperHelper = $this->getHelper('phpcr_console_dumper');
79+
$dumperHelper = $this->getPhpcrConsoleDumperHelper();
8180

8281
// node to dump
8382
$identifier = $input->getArgument('identifier');

tests/PHPCR/Tests/Util/Console/Command/BaseCommandTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ public function setUp()
8282

8383
$this->helperSet = new HelperSet(array(
8484
'session' => new PhpcrHelper($this->session),
85-
'phpcr_console_dumper' => $this->dumperHelper,
8685
));
8786

8887
$this->phpcrCliHelper = $this->getMockBuilder('PHPCR\Util\Console\Helper\PhpcrCliHelper')

tests/PHPCR/Tests/Util/Console/Command/NodeDumpCommandTest.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ public function setUp()
2222
)->disableOriginalConstructor()->getMock();
2323
}
2424

25+
protected function addCommand()
26+
{
27+
$ndCommand = new NodeDumpCommand();
28+
$ndCommand->setPhpcrConsoleDumperHelper($this->dumperHelper);
29+
$this->application->add($ndCommand);
30+
}
31+
2532
public function testCommand()
2633
{
2734
$this->dumperHelper
@@ -41,8 +48,7 @@ public function testCommand()
4148
->with($this->node1)
4249
;
4350

44-
$this->application->add(new NodeDumpCommand());
45-
51+
$this->addCommand();
4652
$this->executeCommand('phpcr:node:dump', array());
4753
}
4854

@@ -67,14 +73,13 @@ public function testCommandIdentifier()
6773
->with($this->node1)
6874
;
6975

70-
$this->application->add(new NodeDumpCommand());
71-
76+
$this->addCommand();
7277
$this->executeCommand('phpcr:node:dump', array('identifier' => $uuid));
7378
}
7479

7580
public function testInvalidRefFormat()
7681
{
77-
$this->application->add(new NodeDumpCommand());
82+
$this->addCommand();
7883

7984
try {
8085
$this->executeCommand('phpcr:node:dump', array('--ref-format' => 'xy'));
@@ -93,7 +98,8 @@ public function testNotFound()
9398
->will($this->throwException(new ItemNotFoundException()))
9499
;
95100

96-
$this->application->add(new NodeDumpCommand());
101+
102+
$this->addCommand();
97103

98104
$ct = $this->executeCommand('phpcr:node:dump', array(), 1);
99105
$this->assertContains('does not exist', $ct->getDisplay());

0 commit comments

Comments
 (0)