diff --git a/Mage/Command/AbstractCommand.php b/Mage/Command/AbstractCommand.php index 3ed5a9d..f69b0ef 100644 --- a/Mage/Command/AbstractCommand.php +++ b/Mage/Command/AbstractCommand.php @@ -31,7 +31,7 @@ abstract class AbstractCommand * @return integer exit code * @throws \Exception */ - public abstract function run(); + abstract public function run(); /** * Sets the Loaded Configuration. diff --git a/tests/MageTest/Command/AbstractCommandTest.php b/tests/MageTest/Command/AbstractCommandTest.php index 28021d7..fed7df5 100644 --- a/tests/MageTest/Command/AbstractCommandTest.php +++ b/tests/MageTest/Command/AbstractCommandTest.php @@ -33,10 +33,7 @@ class AbstractCommandTest extends BaseTest public function testSetConfig() { $configMock = $this->getMock('Mage\Config'); - $this->abstractCommand->setConfig($configMock); - - $actual = $this->getPropertyValue($this->abstractCommand, 'config'); - $this->assertSame($configMock, $actual); + $this->doTestSetter($this->abstractCommand, 'config', $configMock); } /** @@ -45,9 +42,6 @@ class AbstractCommandTest extends BaseTest public function testGetConfig() { $configMock = $this->getMock('Mage\Config'); - $this->setPropertyValue($this->abstractCommand, 'config', $configMock); - - $actual = $this->abstractCommand->getConfig(); - $this->assertSame($configMock, $actual); + $this->doTestGetter($this->abstractCommand, 'config', $configMock); } } diff --git a/tests/MageTest/TestHelper/BaseTest.php b/tests/MageTest/TestHelper/BaseTest.php index 52dd372..de7bc17 100644 --- a/tests/MageTest/TestHelper/BaseTest.php +++ b/tests/MageTest/TestHelper/BaseTest.php @@ -65,4 +65,59 @@ abstract class BaseTest extends \PHPUnit_Framework_TestCase $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 + */ + final protected 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 + */ + final protected function getSetterName($propertyName) + { + return 'set' . ucfirst($propertyName); + } }