Skip to content

Commit

Permalink
cleaned up code of some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
craue committed Aug 19, 2014
1 parent f5f16be commit 1b5a46f
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 119 deletions.
56 changes: 29 additions & 27 deletions Tests/Form/FormFlowBcMethodsTest.php
Expand Up @@ -2,6 +2,8 @@

namespace Craue\FormFlowBundle\Tests\Form;

use Craue\FormFlowBundle\Form\FormFlow;

/**
* Ensure that the methods for BC do what they should.
*
Expand All @@ -14,104 +16,104 @@
class FormFlowBcMethodsTest extends \PHPUnit_Framework_TestCase {

public function testBcMethodDelegation_getCurrentStep() {
$flowStub = $this->getFlowWithMockedDeprecationTriggerMethod('getCurrentStep', 'getCurrentStepNumber');
$flow = $this->getFlowWithMockedDeprecationTriggerMethod('getCurrentStep', 'getCurrentStepNumber');

$flowStub
$flow
->expects($this->once())
->method('getCurrentStepNumber')
->will($this->returnValue(1))
;

$this->assertSame(1, $flowStub->getCurrentStep());
$this->assertSame(1, $flow->getCurrentStep());
}

public function testBcMethodDelegation_getCurrentStepDescription() {
$flowStub = $this->getFlowWithMockedDeprecationTriggerMethod('getCurrentStepDescription', 'getCurrentStepLabel');
$flow = $this->getFlowWithMockedDeprecationTriggerMethod('getCurrentStepDescription', 'getCurrentStepLabel');

$flowStub
$flow
->expects($this->once())
->method('getCurrentStepLabel')
->will($this->returnValue('summary'))
;

$this->assertSame('summary', $flowStub->getCurrentStepDescription());
$this->assertSame('summary', $flow->getCurrentStepDescription());
}

public function testBcMethodDelegation_getMaxSteps() {
$flowStub = $this->getFlowWithMockedDeprecationTriggerMethod('getMaxSteps', 'getStepCount');
$flow = $this->getFlowWithMockedDeprecationTriggerMethod('getMaxSteps', 'getStepCount');

$flowStub
$flow
->expects($this->once())
->method('getStepCount')
->will($this->returnValue(3))
;

$this->assertSame(3, $flowStub->getMaxSteps());
$this->assertSame(3, $flow->getMaxSteps());
}

public function testBcMethodDelegation_getStepDescriptions() {
$flowStub = $this->getFlowWithMockedDeprecationTriggerMethod('getStepDescriptions', 'getStepLabels');
$flow = $this->getFlowWithMockedDeprecationTriggerMethod('getStepDescriptions', 'getStepLabels');

$flowStub
$flow
->expects($this->once())
->method('getStepLabels')
->will($this->returnValue(array('step1', 'step2')))
;

$this->assertSame(array('step1', 'step2'), $flowStub->getStepDescriptions());
$this->assertSame(array('step1', 'step2'), $flow->getStepDescriptions());
}

public function testBcMethodDelegation_getFirstStep() {
$flowStub = $this->getFlowWithMockedDeprecationTriggerMethod('getFirstStep', 'getFirstStepNumber');
$flow = $this->getFlowWithMockedDeprecationTriggerMethod('getFirstStep', 'getFirstStepNumber');

$flowStub
$flow
->expects($this->once())
->method('getFirstStepNumber')
->will($this->returnValue(2))
;

$this->assertSame(2, $flowStub->getFirstStep());
$this->assertSame(2, $flow->getFirstStep());
}

public function testBcMethodDelegation_getLastStep() {
$flowStub = $this->getFlowWithMockedDeprecationTriggerMethod('getLastStep', 'getLastStepNumber');
$flow = $this->getFlowWithMockedDeprecationTriggerMethod('getLastStep', 'getLastStepNumber');

$flowStub
$flow
->expects($this->once())
->method('getLastStepNumber')
->will($this->returnValue(5))
;

$this->assertSame(5, $flowStub->getLastStep());
$this->assertSame(5, $flow->getLastStep());
}

public function testBcMethodDelegation_hasSkipStep() {
$flowStub = $this->getFlowWithMockedDeprecationTriggerMethod('hasSkipStep', 'isStepSkipped');
$flow = $this->getFlowWithMockedDeprecationTriggerMethod('hasSkipStep', 'isStepSkipped');

$flowStub
$flow
->expects($this->once())
->method('isStepSkipped')
->will($this->returnValueMap(array(array(1, true))))
;

$this->assertTrue($flowStub->hasSkipStep(1));
$this->assertTrue($flow->hasSkipStep(1));
}

/**
* @param string $bcMethodName Name of the method for BC.
* @param string $realMethodName Name of the new method actually being called.
* @return PHPUnit_Framework_MockObject_MockObject|\Craue\FormFlowBundle\Form\FormFlow
* @return PHPUnit_Framework_MockObject_MockObject|FormFlow
*/
protected function getFlowWithMockedDeprecationTriggerMethod($bcMethodName, $realMethodName) {
$flowStub = $this->getMock('\Craue\FormFlowBundle\Form\FormFlow', array('getName', 'triggerDeprecationError', $realMethodName));
$flow = $this->getMock('\Craue\FormFlowBundle\Form\FormFlow', array('getName', 'triggerDeprecationError', $realMethodName));

$class = new \ReflectionClass($flowStub);
$class = new \ReflectionClass($flow);
foreach ($class->getMethods() as $method) {
$methodName = $method->getName();

switch ($methodName) {
case 'triggerDeprecationError':
$flowStub
$flow
->expects($this->once())
->method($methodName)
->with(sprintf('%s() is deprecated since version 2.0. Use %s() instead.', $bcMethodName, $realMethodName))
Expand All @@ -121,15 +123,15 @@ protected function getFlowWithMockedDeprecationTriggerMethod($bcMethodName, $rea
break;
default:
// assert that no other methods (of the flow class) are called
$flowStub
$flow
->expects($this->never())
->method($methodName)
;
break;
}
}

return $flowStub;
return $flow;
}

}

0 comments on commit 1b5a46f

Please sign in to comment.