Browse Source

Move testing setters and getters to BaseTest

1.0
Jakub Turek 10 years ago
parent
commit
e7c0b87ccd
  1. 2
      Mage/Command/AbstractCommand.php
  2. 10
      tests/MageTest/Command/AbstractCommandTest.php
  3. 55
      tests/MageTest/TestHelper/BaseTest.php

2
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.

10
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);
}
}

55
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);
}
}

Loading…
Cancel
Save