forked from andres-montanez/Magallanes
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request andres-montanez#197 from edpauto/command-tests
Add commands tests
- Loading branch information
Showing
13 changed files
with
854 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace MageTest\Command; | ||
|
||
use Mage\Command\AbstractCommand; | ||
use MageTest\TestHelper\BaseTest; | ||
use PHPUnit_Framework_MockObject_MockObject; | ||
|
||
/** | ||
* Class AbstractCommandTest | ||
* @package MageTest\Command | ||
* @author Jakub Turek <ja@kubaturek.pl> | ||
* @coversDefaultClass Mage\Command\AbstractCommand | ||
*/ | ||
class AbstractCommandTest extends BaseTest | ||
{ | ||
/** | ||
* @var AbstractCommand|PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $abstractCommand; | ||
|
||
/** | ||
* @before | ||
*/ | ||
public function before() | ||
{ | ||
$this->abstractCommand = $this->getMockForAbstractClass('Mage\Command\AbstractCommand'); | ||
} | ||
|
||
/** | ||
* @covers ::setConfig | ||
*/ | ||
public function testSetConfig() | ||
{ | ||
$configMock = $this->getMock('Mage\Config'); | ||
$this->doTestSetter($this->abstractCommand, 'config', $configMock); | ||
} | ||
|
||
/** | ||
* @covers ::getConfig | ||
*/ | ||
public function testGetConfig() | ||
{ | ||
$configMock = $this->getMock('Mage\Config'); | ||
$this->doTestGetter($this->abstractCommand, 'config', $configMock); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
<?php | ||
|
||
namespace MageTest\Command\BuiltIn; | ||
|
||
use Mage\Command\BuiltIn\CompileCommand; | ||
use MageTest\TestHelper\BaseTest; | ||
use malkusch\phpmock\FixedValueFunction; | ||
use malkusch\phpmock\MockBuilder; | ||
|
||
/** | ||
* Class CompileCommandTest | ||
* @package MageTest\Command\BuiltIn | ||
* @coversDefaultClass Mage\Command\BuiltIn\CompileCommand | ||
* @uses malkusch\phpmock\FixedValueFunction | ||
* @uses malkusch\phpmock\Mock | ||
* @uses malkusch\phpmock\MockBuilder | ||
* @uses Mage\Console | ||
* @uses Mage\Console\Colors | ||
*/ | ||
class CompileCommandTest extends BaseTest | ||
{ | ||
/** | ||
* @var FixedValueFunction | ||
*/ | ||
private $iniGetValue; | ||
|
||
/** | ||
* @before | ||
*/ | ||
public function before() | ||
{ | ||
$this->iniGetValue = new FixedValueFunction(); | ||
$mockBuilder = new MockBuilder(); | ||
$iniGetMock = $mockBuilder->setNamespace('Mage\Command\BuiltIn') | ||
->setName("ini_get") | ||
->setCallableProvider($this->iniGetValue) | ||
->build(); | ||
$iniGetMock->disable(); | ||
$iniGetMock->enable(); | ||
|
||
$this->setUpConsoleStatics(); | ||
} | ||
|
||
/** | ||
* @covers ::__construct | ||
*/ | ||
public function testConstruct() | ||
{ | ||
$compilerMock = $this->getMock('Mage\Compiler'); | ||
$compileCommand = new CompileCommand($compilerMock); | ||
|
||
$compilerProperty = $this->getPropertyValue($compileCommand, 'compiler'); | ||
|
||
$this->assertInstanceOf('Mage\Compiler', $compilerProperty); | ||
$this->assertSame($compilerMock, $compilerProperty); | ||
} | ||
|
||
/** | ||
* @covers ::__construct | ||
*/ | ||
public function testConstructWithNoParams() | ||
{ | ||
$compileCommand = new CompileCommand(); | ||
$compilerProperty = $this->getPropertyValue($compileCommand, 'compiler'); | ||
|
||
$this->assertInstanceOf('Mage\Compiler', $compilerProperty); | ||
} | ||
|
||
/** | ||
* @covers ::__construct | ||
* @covers ::run | ||
*/ | ||
public function testRun() | ||
{ | ||
$expectedOutput = "mage.phar compiled successfully\n\n"; | ||
$expectedExitCode = 0; | ||
$this->expectOutputString($expectedOutput); | ||
|
||
$this->iniGetValue->setValue(false); | ||
|
||
$compilerMock = $this->getMock('Mage\Compiler'); | ||
$compilerMock->expects($this->once()) | ||
->method('compile'); | ||
$compileCommand = new CompileCommand($compilerMock); | ||
|
||
$actualExitCode = $compileCommand->run(); | ||
|
||
$this->assertEquals($expectedExitCode, $actualExitCode); | ||
} | ||
|
||
/** | ||
* @covers ::__construct | ||
* @covers ::run | ||
*/ | ||
public function testRunWhenPharReadonlyEnabled() | ||
{ | ||
$expectedOutput = "\tThe php.ini variable phar.readonly must be Off.\n\n"; | ||
$expectedExitCode = 200; | ||
$this->expectOutputString($expectedOutput); | ||
$this->iniGetValue->setValue(true); | ||
|
||
$compilerMock = $this->getMock('Mage\Compiler'); | ||
$compileCommand = new CompileCommand($compilerMock); | ||
$actualExitCode = $compileCommand->run(); | ||
|
||
$this->assertEquals($expectedExitCode, $actualExitCode); | ||
} | ||
} |
Oops, something went wrong.