From 6ebd6e18d063a966a201a4e2a03f9b9d530e7dcc Mon Sep 17 00:00:00 2001 From: Jose Lorenzo Rodriguez Date: Wed, 17 Jun 2015 13:12:27 +0200 Subject: [PATCH] Making HelperRegistry accept a ConsoleIO in a setter Passing it in the contructor was problematic as both classes depend on each other. --- src/Console/ConsoleIo.php | 3 ++- src/Console/HelperRegistry.php | 4 ++-- tests/TestCase/Console/HelperRegistryTest.php | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Console/ConsoleIo.php b/src/Console/ConsoleIo.php index 0d60d9d66c1..136aaab2978 100644 --- a/src/Console/ConsoleIo.php +++ b/src/Console/ConsoleIo.php @@ -107,7 +107,8 @@ public function __construct(ConsoleOutput $out = null, ConsoleOutput $err = null $this->_out = $out ? $out : new ConsoleOutput('php://stdout'); $this->_err = $err ? $err : new ConsoleOutput('php://stderr'); $this->_in = $in ? $in : new ConsoleInput('php://stdin'); - $this->_helpers = $helpers ? $helpers : new HelperRegistry($this); + $this->_helpers = $helpers ? $helpers : new HelperRegistry(); + $this->_helpers->setIo($this); } /** diff --git a/src/Console/HelperRegistry.php b/src/Console/HelperRegistry.php index 2ef854a1855..2b8aa75c7dc 100644 --- a/src/Console/HelperRegistry.php +++ b/src/Console/HelperRegistry.php @@ -34,11 +34,11 @@ class HelperRegistry extends ObjectRegistry protected $_io; /** - * Constructor + * Sets The IO instance that should be passed to the shell helpers * * @param \Cake\Console\ConsoleIo $io An io instance. */ - public function __construct(ConsoleIo $io) + public function setIo(ConsoleIo $io) { $this->_io = $io; } diff --git a/tests/TestCase/Console/HelperRegistryTest.php b/tests/TestCase/Console/HelperRegistryTest.php index b55c6cb6a4f..16044bb4544 100644 --- a/tests/TestCase/Console/HelperRegistryTest.php +++ b/tests/TestCase/Console/HelperRegistryTest.php @@ -35,7 +35,8 @@ public function setUp() parent::setUp(); Configure::write('App.namespace', 'TestApp'); $io = $this->getMock('Cake\Console\ConsoleIo', [], [], '', false); - $this->helpers = new HelperRegistry($io); + $this->helpers = new HelperRegistry(); + $this->helpers->setIo($io); } /**