Browse Source

Remove setter from CompileCommand

Also, let the Compiler be constructed with DI or by itself
1.0
Jakub Turek 10 years ago
parent
commit
3b326227ae
  1. 7
      Mage/Command/BuiltIn/CompileCommand.php
  2. 42
      tests/MageTest/Command/BuiltIn/CompileCommandTest.php

7
Mage/Command/BuiltIn/CompileCommand.php

@ -26,13 +26,12 @@ class CompileCommand extends AbstractCommand
*/ */
private $compiler; private $compiler;
public function __construct() public function __construct(Compiler $compiler = null)
{ {
$this->setCompiler(new Compiler()); if ($compiler === null) {
$compiler = new Compiler();
} }
public function setCompiler(Compiler $compiler)
{
$this->compiler = $compiler; $this->compiler = $compiler;
} }

42
tests/MageTest/Command/BuiltIn/CompileCommandTest.php

@ -5,14 +5,12 @@ namespace MageTest\Command\BuiltIn;
use Mage\Command\BuiltIn\CompileCommand; use Mage\Command\BuiltIn\CompileCommand;
use MageTest\TestHelper\BaseTest; use MageTest\TestHelper\BaseTest;
use malkusch\phpmock\FixedValueFunction; use malkusch\phpmock\FixedValueFunction;
use malkusch\phpmock\Mock;
use malkusch\phpmock\MockBuilder; use malkusch\phpmock\MockBuilder;
/** /**
* Class CompileCommandTest * Class CompileCommandTest
* @package MageTest\Command\BuiltIn * @package MageTest\Command\BuiltIn
* @coversDefaultClass Mage\Command\BuiltIn\CompileCommand * @coversDefaultClass Mage\Command\BuiltIn\CompileCommand
* @uses Mage\Compiler
* @uses malkusch\phpmock\FixedValueFunction * @uses malkusch\phpmock\FixedValueFunction
* @uses malkusch\phpmock\Mock * @uses malkusch\phpmock\Mock
* @uses malkusch\phpmock\MockBuilder * @uses malkusch\phpmock\MockBuilder
@ -21,11 +19,6 @@ use malkusch\phpmock\MockBuilder;
*/ */
class CompileCommandTest extends BaseTest class CompileCommandTest extends BaseTest
{ {
/**
* @var CompileCommand
*/
private $compileCommand;
/** /**
* @var FixedValueFunction * @var FixedValueFunction
*/ */
@ -36,8 +29,6 @@ class CompileCommandTest extends BaseTest
*/ */
public function before() public function before()
{ {
$this->compileCommand = new CompileCommand();
$this->iniGetValue = new FixedValueFunction(); $this->iniGetValue = new FixedValueFunction();
$mockBuilder = new MockBuilder(); $mockBuilder = new MockBuilder();
$iniGetMock = $mockBuilder->setNamespace('Mage\Command\BuiltIn') $iniGetMock = $mockBuilder->setNamespace('Mage\Command\BuiltIn')
@ -52,30 +43,28 @@ class CompileCommandTest extends BaseTest
/** /**
* @covers ::__construct * @covers ::__construct
* @covers ::setCompiler
*/ */
public function testConstruct() public function testConstruct()
{ {
$compilerProperty = $this->getPropertyValue($this->compileCommand, 'compiler'); $compileCommand = $this->getRawCompileCommand();
$compilerProperty = $this->getPropertyValue($compileCommand, 'compiler');
$this->assertInstanceOf('Mage\Compiler', $compilerProperty); $this->assertInstanceOf('Mage\Compiler', $compilerProperty);
} }
/** /**
* @covers ::__construct * @covers ::__construct
* @covers ::setCompiler
*/ */
public function testSetCompiler() public function testConstructWithNoParams()
{ {
$compilerMock = $this->getMock('Mage\Compiler'); $compileCommand = new CompileCommand();
$this->compileCommand->setCompiler($compilerMock); $compilerProperty = $this->getPropertyValue($compileCommand, 'compiler');
$compilerProperty = $this->getPropertyValue($this->compileCommand, 'compiler'); $this->assertInstanceOf('Mage\Compiler', $compilerProperty);
$this->assertEquals($compilerMock, $compilerProperty);
} }
/** /**
* @covers ::__construct * @covers ::__construct
* @covers ::setCompiler
* @covers ::run * @covers ::run
*/ */
public function testRun() public function testRun()
@ -84,20 +73,20 @@ class CompileCommandTest extends BaseTest
$expectedExitCode = 0; $expectedExitCode = 0;
$this->expectOutputString($expectedOutput); $this->expectOutputString($expectedOutput);
$this->iniGetValue->setValue(false);
$compilerMock = $this->getMock('Mage\Compiler'); $compilerMock = $this->getMock('Mage\Compiler');
$compilerMock->expects($this->once()) $compilerMock->expects($this->once())
->method('compile'); ->method('compile');
$compileCommand = new CompileCommand($compilerMock);
$this->iniGetValue->setValue(false); $actualExitCode = $compileCommand->run();
$this->compileCommand->setCompiler($compilerMock);
$actualExitCode = $this->compileCommand->run();
$this->assertEquals($expectedExitCode, $actualExitCode); $this->assertEquals($expectedExitCode, $actualExitCode);
} }
/** /**
* @covers ::__construct * @covers ::__construct
* @covers ::setCompiler
* @covers ::run * @covers ::run
*/ */
public function testRunWhenPharReadonlyEnabled() public function testRunWhenPharReadonlyEnabled()
@ -107,8 +96,15 @@ class CompileCommandTest extends BaseTest
$this->expectOutputString($expectedOutput); $this->expectOutputString($expectedOutput);
$this->iniGetValue->setValue(true); $this->iniGetValue->setValue(true);
$actualExitCode = $this->compileCommand->run(); $compileCommand = $this->getRawCompileCommand();
$actualExitCode = $compileCommand->run();
$this->assertEquals($expectedExitCode, $actualExitCode); $this->assertEquals($expectedExitCode, $actualExitCode);
} }
private function getRawCompileCommand()
{
$compilerMock = $this->getMock('Mage\Compiler');
return new CompileCommand($compilerMock);
}
} }

Loading…
Cancel
Save