mirror of https://github.com/hauke68/Magallanes
Kuba Turek
10 years ago
13 changed files with 854 additions and 16 deletions
@ -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); |
||||
} |
||||
} |
@ -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); |
||||
} |
||||
} |
@ -0,0 +1,141 @@
|
||||
<?php |
||||
|
||||
namespace MageTest\Command\BuiltIn; |
||||
|
||||
use Mage\Command\BuiltIn\ListCommand; |
||||
use MageTest\TestHelper\BaseTest; |
||||
use malkusch\phpmock\FixedValueFunction; |
||||
use malkusch\phpmock\Mock; |
||||
use malkusch\phpmock\MockBuilder; |
||||
|
||||
/** |
||||
* Class ListCommandTest |
||||
* @package MageTest\Command\BuiltIn |
||||
* @coversDefaultClass Mage\Command\BuiltIn\ListCommand |
||||
* @uses malkusch\phpmock\Mock |
||||
* @uses malkusch\phpmock\MockBuilder |
||||
* @uses malkusch\phpmock\FixedValueFunction |
||||
* @uses Mage\Console\Colors |
||||
* @uses Mage\Console |
||||
* @uses Mage\Command\AbstractCommand |
||||
*/ |
||||
class ListCommandTest extends BaseTest |
||||
{ |
||||
/** |
||||
* @var ListCommand |
||||
*/ |
||||
private $listCommand; |
||||
|
||||
/** |
||||
* @var FixedValueFunction |
||||
*/ |
||||
private $scandirValueObj; |
||||
|
||||
/** |
||||
* @before |
||||
*/ |
||||
public function before() |
||||
{ |
||||
$this->listCommand = new ListCommand(); |
||||
|
||||
$this->scandirValueObj = new FixedValueFunction(); |
||||
$mockBuilder = new MockBuilder(); |
||||
$scandirMock = $mockBuilder->setNamespace('Mage\Command\BuiltIn') |
||||
->setName("scandir") |
||||
->setCallableProvider($this->scandirValueObj) |
||||
->build(); |
||||
$scandirMock->disable(); |
||||
$scandirMock->enable(); |
||||
|
||||
$this->setUpConsoleStatics(); |
||||
} |
||||
|
||||
public function listEnvironmentsProvider() |
||||
{ |
||||
return array( |
||||
'normal' => array( |
||||
'environmentFiles' => array( |
||||
'rc.yml', |
||||
'production.yml', |
||||
'local.yml' |
||||
), |
||||
'expectedOutput' => "\tThese are your configured environments:\n" |
||||
. "\t\t* local\n" |
||||
. "\t\t* production\n" |
||||
. "\t\t* rc\n" |
||||
. "\t\n", |
||||
'expectedExitCode' => 0 |
||||
), |
||||
'with_missing_yml_files' => array( |
||||
'environmentFiles' => array( |
||||
'rc', |
||||
'production.yml' |
||||
), |
||||
'expectedOutput' => "\tThese are your configured environments:\n" |
||||
. "\t\t* production\n" |
||||
. "\t\n", |
||||
'expectedExitCode' => 0 |
||||
), |
||||
'with_no_yml_configs' => array( |
||||
'environmentFiles' => array( |
||||
'rc.ini', |
||||
'production.txt' |
||||
), |
||||
'expectedOutput' => "\tYou don't have any environment configured.\n\n", |
||||
'expectedExitCode' => 220 |
||||
), |
||||
'with_no_configs' => array( |
||||
'environmentFiles' => array(), |
||||
'expectedOutput' => "\tYou don't have any environment configured.\n\n", |
||||
'expectedExitCode' => 220 |
||||
) |
||||
); |
||||
} |
||||
|
||||
/** |
||||
* @covers ::run |
||||
* @covers ::listEnvironments |
||||
* @dataProvider listEnvironmentsProvider |
||||
*/ |
||||
public function testListEnvironment($environmentFiles, $expectedOutput, $expectedExitCode) |
||||
{ |
||||
$this->expectOutputString($expectedOutput); |
||||
|
||||
$this->scandirValueObj->setValue($environmentFiles); |
||||
$this->mockInputArgument('environments'); |
||||
|
||||
$actualExitCode = $this->listCommand->run(); |
||||
$this->assertEquals($expectedExitCode, $actualExitCode); |
||||
} |
||||
|
||||
/** |
||||
* @covers ::run |
||||
*/ |
||||
public function testRunWithInvalidCommand() |
||||
{ |
||||
$expectedOutput = "\tThe Type of Elements to List is needed.\n\n"; |
||||
$this->expectOutputString($expectedOutput); |
||||
|
||||
$this->mockInputArgument('abc'); |
||||
|
||||
$expectedExitCode = 221; |
||||
$actualExitCode = $this->listCommand->run(); |
||||
$this->assertEquals($expectedExitCode, $actualExitCode); |
||||
} |
||||
|
||||
/** |
||||
* Stub Config::getArgument to return desired value |
||||
* |
||||
* @param String $argumentValue Input argument |
||||
*/ |
||||
private function mockInputArgument($argumentValue) |
||||
{ |
||||
$configMock = $this->getMock('Mage\Config'); |
||||
$configMock->expects($this->once()) |
||||
->method('getArgument') |
||||
->with(1) |
||||
->willReturn($argumentValue); |
||||
|
||||
$this->listCommand->setConfig($configMock); |
||||
} |
||||
} |
@ -0,0 +1,205 @@
|
||||
<?php |
||||
|
||||
namespace MageTest\Command\BuiltIn; |
||||
|
||||
use Mage\Command\BuiltIn\LockCommand; |
||||
use MageTest\TestHelper\BaseTest; |
||||
use malkusch\phpmock\FixedValueFunction; |
||||
use malkusch\phpmock\MockBuilder; |
||||
|
||||
/** |
||||
* Class LockCommandTest |
||||
* @package MageTest\Command\BuiltIn |
||||
* @coversDefaultClass Mage\Command\BuiltIn\LockCommand |
||||
* @uses malkusch\phpmock\MockBuilder |
||||
* @uses malkusch\phpmock\FixedValueFunction |
||||
* @uses malkusch\phpmock\Mock |
||||
* @uses Mage\Console\Colors |
||||
* @uses Mage\Console |
||||
* @uses Mage\Command\AbstractCommand |
||||
*/ |
||||
class LockCommandTest extends BaseTest |
||||
{ |
||||
public static $fgetsCount; |
||||
public static $mockName; |
||||
public static $mockEmail; |
||||
public static $mockDesc; |
||||
public static $filePutContentsResult; |
||||
public static $filePutContentsFile; |
||||
|
||||
/** |
||||
* @var LockCommand |
||||
*/ |
||||
private $lockCommand; |
||||
|
||||
/** |
||||
* @var FixedValueFunction |
||||
*/ |
||||
private $fgetsValue; |
||||
|
||||
/** |
||||
* @before |
||||
*/ |
||||
public function before() |
||||
{ |
||||
self::$fgetsCount = 0; |
||||
self::$mockName = ''; |
||||
self::$mockEmail = ''; |
||||
self::$mockDesc = ''; |
||||
self::$filePutContentsResult = ''; |
||||
self::$filePutContentsFile = ''; |
||||
|
||||
$this->lockCommand = new LockCommand(); |
||||
|
||||
$mockBuilder = new MockBuilder(); |
||||
$fopenMock = $mockBuilder |
||||
->setName('fopen') |
||||
->setNamespace('Mage') |
||||
->setFunction(function () { |
||||
return 'a'; |
||||
}) |
||||
->build(); |
||||
|
||||
$this->fgetsValue = new FixedValueFunction(); |
||||
$fgetsMock = $mockBuilder |
||||
->setNamespace('Mage') |
||||
->setName('fgets') |
||||
->setFunction( |
||||
function () { |
||||
switch (LockCommandTest::$fgetsCount) { |
||||
case 0: |
||||
LockCommandTest::$fgetsCount++; |
||||
return LockCommandTest::$mockName; |
||||
case 1: |
||||
LockCommandTest::$fgetsCount++; |
||||
return LockCommandTest::$mockEmail; |
||||
case 2: |
||||
LockCommandTest::$fgetsCount++; |
||||
return LockCommandTest::$mockDesc; |
||||
default: |
||||
throw new \Exception('"fgets" count limit exceed'); |
||||
} |
||||
} |
||||
) |
||||
->build(); |
||||
$getCwdMock = $mockBuilder |
||||
->setNamespace('Mage\Command\Builtin') |
||||
->setName('getcwd') |
||||
->setFunction( |
||||
function () { |
||||
return ''; |
||||
} |
||||
) |
||||
->build(); |
||||
$fileGetContentsMock = $mockBuilder |
||||
->setNamespace('Mage\Command\Builtin') |
||||
->setName('file_put_contents') |
||||
->setFunction( |
||||
function ($file, $contents) { |
||||
LockCommandTest::$filePutContentsFile = $file; |
||||
LockCommandTest::$filePutContentsResult = $contents; |
||||
} |
||||
) |
||||
->build(); |
||||
|
||||
$dateMock = $mockBuilder |
||||
->setNamespace('Mage\Command\BuiltIn') |
||||
->setName('date') |
||||
->setFunction( |
||||
function () { |
||||
return '2015-01-01 12:00:00'; |
||||
} |
||||
) |
||||
->build(); |
||||
|
||||
$fopenMock->disable(); |
||||
$fgetsMock->disable(); |
||||
$getCwdMock->disable(); |
||||
$fileGetContentsMock->disable(); |
||||
$dateMock->disable(); |
||||
|
||||
$fopenMock->enable(); |
||||
$fgetsMock->enable(); |
||||
$getCwdMock->enable(); |
||||
$fileGetContentsMock->enable(); |
||||
$dateMock->enable(); |
||||
|
||||
$this->setUpConsoleStatics(); |
||||
} |
||||
|
||||
public function lockCommandProvider() |
||||
{ |
||||
return array( |
||||
'normal' => array( |
||||
'name' => 'John Smith', |
||||
'email' => 'john.smith@example.com', |
||||
'description' => "There's a critical bug here!", |
||||
'expectedLockFileContents' => "Locked environment at date: 2015-01-01 12:00:00\n" |
||||
. "Locked by John Smith (john.smith@example.com)\n" |
||||
. "There's a critical bug here!\n", |
||||
), |
||||
'with_no_name' => array( |
||||
'name' => '', |
||||
'email' => 'john.smith@example.com', |
||||
'description' => "There's a critical bug here!", |
||||
'expectedLockFileContents' => "Locked environment at date: 2015-01-01 12:00:00\n" |
||||
. "(john.smith@example.com)\n" |
||||
. "There's a critical bug here!\n", |
||||
), |
||||
'with_no_email' => array( |
||||
'name' => 'John Smith', |
||||
'email' => '', |
||||
'description' => "There's a critical bug here!", |
||||
'expectedLockFileContents' => "Locked environment at date: 2015-01-01 12:00:00\n" |
||||
. "Locked by John Smith \n" |
||||
. "There's a critical bug here!\n", |
||||
), |
||||
'with_no_name_nor_email' => array( |
||||
'name' => '', |
||||
'email' => '', |
||||
'description' => "There's a critical bug here!", |
||||
'expectedLockFileContents' => "Locked environment at date: 2015-01-01 12:00:00\n" |
||||
. "\n" |
||||
. "There's a critical bug here!\n", |
||||
), |
||||
'with_no_desciption' => array( |
||||
'name' => 'John Smith', |
||||
'email' => 'john.smith@example.com', |
||||
'description' => '', |
||||
'expectedLockFileContents' => "Locked environment at date: 2015-01-01 12:00:00\n" |
||||
. "Locked by John Smith (john.smith@example.com)" |
||||
), |
||||
); |
||||
} |
||||
|
||||
/** |
||||
* @covers ::run |
||||
* @dataProvider lockCommandProvider |
||||
*/ |
||||
public function testRun($name, $email, $description, $expectedLockFileContents) |
||||
{ |
||||
$expectedOutput = "Your name (enter to leave blank): " |
||||
. "Your email (enter to leave blank): " |
||||
. "Reason of lock (enter to leave blank): " |
||||
. "\tLocked deployment to production environment\n\n"; |
||||
$this->expectOutputString($expectedOutput); |
||||
$expectedLockFilePath = '/.mage/production.lock'; |
||||
$expectedExitCode = 0; |
||||
|
||||
self::$mockName = $name; |
||||
self::$mockEmail = $email; |
||||
self::$mockDesc = $description; |
||||
|
||||
$configMock = $this->getMock('Mage\Config'); |
||||
$configMock->expects($this->atLeastOnce()) |
||||
->method('getEnvironment') |
||||
->willReturn('production'); |
||||
$this->lockCommand->setConfig($configMock); |
||||
|
||||
$actualExitCode = $this->lockCommand->run(); |
||||
|
||||
$this->assertEquals($expectedExitCode, $actualExitCode); |
||||
$this->assertEquals($expectedLockFileContents, self::$filePutContentsResult); |
||||
$this->assertEquals($expectedLockFilePath, self::$filePutContentsFile); |
||||
} |
||||
} |
@ -0,0 +1,119 @@
|
||||
<?php |
||||
|
||||
namespace MageTest\Command\BuiltIn; |
||||
|
||||
use Mage\Command\BuiltIn\UnlockCommand; |
||||
use MageTest\TestHelper\BaseTest; |
||||
use malkusch\phpmock\MockBuilder; |
||||
|
||||
/** |
||||
* Class UnlockCommandTest |
||||
* @package MageTest\Command\BuiltIn |
||||
* @coversDefaultClass Mage\Command\BuiltIn\UnlockCommand |
||||
* @uses malkusch\phpmock\MockBuilder |
||||
* @uses malkusch\phpmock\Mock |
||||
* @uses Mage\Command\AbstractCommand |
||||
* @uses Mage\Console |
||||
* @uses Mage\Console\Colors |
||||
*/ |
||||
class UnlockCommandTest extends BaseTest |
||||
{ |
||||
/** |
||||
* @var UnlockCommand |
||||
*/ |
||||
private $unlockCommand; |
||||
|
||||
public static $isUnlinkCalled; |
||||
public static $fileExistsResult; |
||||
public static $isFileExists; |
||||
|
||||
public function runProvider() |
||||
{ |
||||
return array( |
||||
'happy_path' => array( |
||||
'file_exists' => true, |
||||
), |
||||
'file_not_exists' => array( |
||||
'file_exsits' => false |
||||
) |
||||
); |
||||
} |
||||
|
||||
/** |
||||
* @before |
||||
*/ |
||||
public function before() |
||||
{ |
||||
$this->unlockCommand = new UnlockCommand(); |
||||
|
||||
self::$isUnlinkCalled = false; |
||||
self::$fileExistsResult = false; |
||||
self::$isFileExists = false; |
||||
|
||||
$mockBuilder = new MockBuilder(); |
||||
$fileExistsMock = $mockBuilder |
||||
->setName('file_exists') |
||||
->setNamespace('Mage\Command\BuiltIn') |
||||
->setFunction( |
||||
function ($filePath) { |
||||
UnlockCommandTest::$fileExistsResult = $filePath; |
||||
return UnlockCommandTest::$isFileExists; |
||||
} |
||||
) |
||||
->build(); |
||||
$unlinkMock = $mockBuilder |
||||
->setName('unlink') |
||||
->setNamespace('Mage\Command\BuiltIn') |
||||
->setFunction( |
||||
function () { |
||||
UnlockCommandTest::$isUnlinkCalled = true; |
||||
} |
||||
) |
||||
->build(); |
||||
$getCwdMock = $mockBuilder |
||||
->setNamespace('Mage\Command\BuiltIn') |
||||
->setName('getcwd') |
||||
->setFunction( |
||||
function () { |
||||
return ''; |
||||
} |
||||
) |
||||
->build(); |
||||
|
||||
$fileExistsMock->disable(); |
||||
$unlinkMock->disable(); |
||||
$getCwdMock->disable(); |
||||
|
||||
$fileExistsMock->enable(); |
||||
$unlinkMock->enable(); |
||||
$getCwdMock->enable(); |
||||
|
||||
$configMock = $this->getMock('Mage\Config'); |
||||
$configMock->expects($this->atLeastOnce()) |
||||
->method('getEnvironment') |
||||
->willReturn('production'); |
||||
$this->unlockCommand->setConfig($configMock); |
||||
|
||||
$this->setUpConsoleStatics(); |
||||
} |
||||
|
||||
/** |
||||
* @covers ::run |
||||
* @dataProvider runProvider |
||||
*/ |
||||
public function testRun($fileExists) |
||||
{ |
||||
$expectedOutput = "\tUnlocked deployment to production environment\n\n"; |
||||
$this->expectOutputString($expectedOutput); |
||||
$expectedLockFilePath = '/.mage/production.lock'; |
||||
|
||||
self::$isFileExists = $fileExists; |
||||
|
||||
$actualExitCode = $this->unlockCommand->run(); |
||||
$expectedExitCode = 0; |
||||
|
||||
$this->assertEquals(self::$isUnlinkCalled, $fileExists); |
||||
$this->assertEquals($expectedExitCode, $actualExitCode); |
||||
$this->assertEquals($expectedLockFilePath, self::$fileExistsResult); |
||||
} |
||||
} |
@ -0,0 +1,123 @@
|
||||
<?php |
||||
|
||||
namespace MageTest\TestHelper; |
||||
|
||||
/** |
||||
* Class BaseTest |
||||
* |
||||
* Class containing common methods useful for unit testing. |
||||
* Since Magallanes keeps compatibility with PHP 5.3, those methods can't be moved to a trait. |
||||
* This class extends \PHPUnit_Framework_TestCase so it can be used with any test class. |
||||
* |
||||
* @package MageTest\TestHelper |
||||
* @author Jakub Turek <ja@kubaturek.pl> |
||||
*/ |
||||
abstract class BaseTest extends \PHPUnit_Framework_TestCase |
||||
{ |
||||
/** |
||||
* Returns value of non-public property from given class |
||||
* |
||||
* @param string|object $object Object instance or class name |
||||
* @param string $propertyName Class' or object's property name |
||||
* @return mixed |
||||
*/ |
||||
final protected function getPropertyValue($object, $propertyName) |
||||
{ |
||||
$configProperty = new \ReflectionProperty($object, $propertyName); |
||||
$configProperty->setAccessible(true); |
||||
|
||||
return $configProperty->getValue($object); |
||||
} |
||||
|
||||
/** |
||||
* Sets value to given property and given object |
||||
* |
||||
* @param object $object Object instance |
||||
* @param string $propertyName Property name |
||||
* @param mixed $value Value to set |
||||
*/ |
||||
final protected function setPropertyValue($object, $propertyName, $value) |
||||
{ |
||||
$configProperty = new \ReflectionProperty($object, $propertyName); |
||||
$configProperty->setAccessible(true); |
||||
$configProperty->setValue($object, $value); |
||||
} |
||||
|
||||
/** |
||||
* Disable logging to log file and turn off colors |
||||
* |
||||
* @before |
||||
*/ |
||||
protected function setUpConsoleStatics() |
||||
{ |
||||
$consoleReflection = new \ReflectionClass('Mage\Console'); |
||||
$logEnableProperty = $consoleReflection->getProperty('logEnabled'); |
||||
$logEnableProperty->setAccessible(true); |
||||
$logEnableProperty->setValue(false); |
||||
|
||||
$configMock = $this->getMock('Mage\Config'); |
||||
$configMock->expects($this->any()) |
||||
->method('getParameter') |
||||
->with('no-color') |
||||
->willReturn(true); |
||||
|
||||
$configProperty = $consoleReflection->getProperty('config'); |
||||
$configProperty->setAccessible(true); |
||||
$configProperty->setValue($configMock); |
||||
} |
||||
|
||||
/** |
||||
* Tests getter of given object for given property name and example value |
||||
* |
||||
* @param object $object Object instance |
||||
* @param string $propertyName Property name |
||||
* @param mixed $propertyValue Value to set |
||||
*/ |
||||
final protected function doTestGetter($object, $propertyName, $propertyValue) |
||||
{ |
||||
$this->setPropertyValue($object, $propertyName, $propertyValue); |
||||
$getterName = $this->getGetterName($propertyName); |
||||
|
||||
$actual = $object->$getterName(); |
||||
|
||||
$this->assertSame($propertyValue, $actual); |
||||
} |
||||
|
||||
/** |
||||
* Tests setter of given object for given property name and example value |
||||
* |
||||
* @param object $object Object instance |
||||
* @param string $propertyName Property name |
||||
* @param mixed $propertyValue Value to set |
||||
*/ |
||||
final protected function doTestSetter($object, $propertyName, $propertyValue) |
||||
{ |
||||
$setterName = $this->getSetterName($propertyName); |
||||
$object->$setterName($propertyValue); |
||||
|
||||
$actual = $this->getPropertyValue($object, $propertyName); |
||||
$this->assertSame($propertyValue, $actual); |
||||
} |
||||
|
||||
/** |
||||
* Returns the conventional getter name for given property name |
||||
* |
||||
* @param string $propertyName Property name |
||||
* @return string Getter method name |
||||
*/ |
||||
private function getGetterName($propertyName) |
||||
{ |
||||
return 'get' . ucfirst($propertyName); |
||||
} |
||||
|
||||
/** |
||||
* Returns the conventional setter name for given property name |
||||
* |
||||
* @param string $propertyName Property name |
||||
* @return string Getter method name |
||||
*/ |
||||
private function getSetterName($propertyName) |
||||
{ |
||||
return 'set' . ucfirst($propertyName); |
||||
} |
||||
} |
Loading…
Reference in new issue