mirror of
https://github.com/andres-montanez/Magallanes
synced 2024-06-16 04:25:06 +02:00
Move testing setters and getters to BaseTest
This commit is contained in:
parent
c6e0d6762c
commit
e7c0b87ccd
|
@ -31,7 +31,7 @@ abstract class AbstractCommand
|
||||||
* @return integer exit code
|
* @return integer exit code
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public abstract function run();
|
abstract public function run();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the Loaded Configuration.
|
* Sets the Loaded Configuration.
|
||||||
|
|
|
@ -33,10 +33,7 @@ class AbstractCommandTest extends BaseTest
|
||||||
public function testSetConfig()
|
public function testSetConfig()
|
||||||
{
|
{
|
||||||
$configMock = $this->getMock('Mage\Config');
|
$configMock = $this->getMock('Mage\Config');
|
||||||
$this->abstractCommand->setConfig($configMock);
|
$this->doTestSetter($this->abstractCommand, 'config', $configMock);
|
||||||
|
|
||||||
$actual = $this->getPropertyValue($this->abstractCommand, 'config');
|
|
||||||
$this->assertSame($configMock, $actual);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -45,9 +42,6 @@ class AbstractCommandTest extends BaseTest
|
||||||
public function testGetConfig()
|
public function testGetConfig()
|
||||||
{
|
{
|
||||||
$configMock = $this->getMock('Mage\Config');
|
$configMock = $this->getMock('Mage\Config');
|
||||||
$this->setPropertyValue($this->abstractCommand, 'config', $configMock);
|
$this->doTestGetter($this->abstractCommand, 'config', $configMock);
|
||||||
|
|
||||||
$actual = $this->abstractCommand->getConfig();
|
|
||||||
$this->assertSame($configMock, $actual);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,4 +65,59 @@ abstract class BaseTest extends \PHPUnit_Framework_TestCase
|
||||||
$configProperty->setAccessible(true);
|
$configProperty->setAccessible(true);
|
||||||
$configProperty->setValue($configMock);
|
$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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue