mirror of
				https://github.com/hauke68/Magallanes.git
				synced 2025-11-04 00:50:18 +01: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
 | 
			
		||||
     * @throws \Exception
 | 
			
		||||
     */
 | 
			
		||||
    public abstract function run();
 | 
			
		||||
    abstract public function run();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Sets the Loaded Configuration.
 | 
			
		||||
 | 
			
		||||
@ -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);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -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…
	
		Reference in New Issue
	
	Block a user