From d58e89c41db1c2cd38a3bad973c3f9fa9d7581e7 Mon Sep 17 00:00:00 2001 From: Jakub Turek Date: Sat, 21 Feb 2015 16:36:09 +0100 Subject: [PATCH] Set compiler by setter for better testability --- Mage/Command/BuiltIn/CompileCommand.php | 15 ++++++ .../Command/BuiltIn/CompileCommandTest.php | 51 +++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 tests/MageTest/Command/BuiltIn/CompileCommandTest.php diff --git a/Mage/Command/BuiltIn/CompileCommand.php b/Mage/Command/BuiltIn/CompileCommand.php index 9cd94b6..e7db44b 100644 --- a/Mage/Command/BuiltIn/CompileCommand.php +++ b/Mage/Command/BuiltIn/CompileCommand.php @@ -21,6 +21,21 @@ use Mage\Compiler; */ class CompileCommand extends AbstractCommand { + /** + * @var Compiler + */ + private $compiler; + + public function __construct() + { + $this->compiler = new Compiler(); + } + + public function setCompiler(Compiler $compiler) + { + $this->compiler = $compiler; + } + /** * @see \Mage\Compile::compile() */ diff --git a/tests/MageTest/Command/BuiltIn/CompileCommandTest.php b/tests/MageTest/Command/BuiltIn/CompileCommandTest.php new file mode 100644 index 0000000..3780481 --- /dev/null +++ b/tests/MageTest/Command/BuiltIn/CompileCommandTest.php @@ -0,0 +1,51 @@ +compileCommand = new CompileCommand(); + } + + /** + * @covers ::__construct + */ + public function testConstruct() + { + $compileCommand = new CompileCommand(); + + $compilerProperty = $this->getPropertyValue($compileCommand, 'compiler'); + $this->assertInstanceOf('Mage\Compiler', $compilerProperty); + } + + /** + * @covers ::setCompiler + */ + public function testSetCompiler() + { + $compilerMock = $this->getMock('Mage\Compiler'); + $this->compileCommand->setCompiler($compilerMock); + + $compilerProperty = $this->getPropertyValue($this->compileCommand, 'compiler'); + $this->assertEquals($compilerMock, $compilerProperty); + } +}