Skip to content

Commit

Permalink
removed some useless code in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
craue committed Jun 24, 2015
1 parent ecaf86b commit 2127447
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 29 deletions.
24 changes: 10 additions & 14 deletions Tests/Form/FormFlowBcMethodsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ public function testBcMethodDelegation_getCurrentStep() {
$flowStub
->expects($this->once())
->method('getCurrentStepNumber')
->will($this->returnValue(1))
;

$this->assertSame(1, $flowStub->getCurrentStep());
$flowStub->getCurrentStep();
$this->assertEquals(array(sprintf($this->deprecatedMessage, 'getCurrentStep', 'getCurrentStepNumber')), $this->getDeprecationNotices());
}

Expand All @@ -38,10 +37,9 @@ public function testBcMethodDelegation_getCurrentStepDescription() {
$flowStub
->expects($this->once())
->method('getCurrentStepLabel')
->will($this->returnValue('summary'))
;

$this->assertSame('summary', $flowStub->getCurrentStepDescription());
$flowStub->getCurrentStepDescription();
$this->assertEquals(array(sprintf($this->deprecatedMessage, 'getCurrentStepDescription', 'getCurrentStepLabel')), $this->getDeprecationNotices());
}

Expand All @@ -51,10 +49,9 @@ public function testBcMethodDelegation_getMaxSteps() {
$flowStub
->expects($this->once())
->method('getStepCount')
->will($this->returnValue(3))
;

$this->assertSame(3, $flowStub->getMaxSteps());
$flowStub->getMaxSteps();
$this->assertEquals(array(sprintf($this->deprecatedMessage, 'getMaxSteps', 'getStepCount')), $this->getDeprecationNotices());
}

Expand All @@ -64,10 +61,9 @@ public function testBcMethodDelegation_getStepDescriptions() {
$flowStub
->expects($this->once())
->method('getStepLabels')
->will($this->returnValue(array('step1', 'step2')))
;

$this->assertSame(array('step1', 'step2'), $flowStub->getStepDescriptions());
$flowStub->getStepDescriptions();
$this->assertEquals(array(sprintf($this->deprecatedMessage, 'getStepDescriptions', 'getStepLabels')), $this->getDeprecationNotices());
}

Expand All @@ -77,10 +73,9 @@ public function testBcMethodDelegation_getFirstStep() {
$flowStub
->expects($this->once())
->method('getFirstStepNumber')
->will($this->returnValue(2))
;

$this->assertSame(2, $flowStub->getFirstStep());
$flowStub->getFirstStep();
$this->assertEquals(array(sprintf($this->deprecatedMessage, 'getFirstStep', 'getFirstStepNumber')), $this->getDeprecationNotices());
}

Expand All @@ -90,23 +85,24 @@ public function testBcMethodDelegation_getLastStep() {
$flowStub
->expects($this->once())
->method('getLastStepNumber')
->will($this->returnValue(5))
;

$this->assertSame(5, $flowStub->getLastStep());
$flowStub->getLastStep();
$this->assertEquals(array(sprintf($this->deprecatedMessage, 'getLastStep', 'getLastStepNumber')), $this->getDeprecationNotices());
}

public function testBcMethodDelegation_hasSkipStep() {
$flowStub = $this->getMock('\Craue\FormFlowBundle\Form\FormFlow', array('getName', 'isStepSkipped'));

$stepNumber = 1;

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

$this->assertTrue($flowStub->hasSkipStep(1));
$flowStub->hasSkipStep($stepNumber);
$this->assertEquals(array(sprintf($this->deprecatedMessage, 'hasSkipStep', 'isStepSkipped')), $this->getDeprecationNotices());
}

Expand Down
22 changes: 7 additions & 15 deletions Tests/IntegrationTestBundle/Controller/FormFlowController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Craue\FormFlowBundle\Tests\IntegrationTestBundle\Entity\Topic;
use Craue\FormFlowBundle\Tests\IntegrationTestBundle\Entity\Vehicle;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\JsonResponse;

Expand All @@ -30,31 +29,27 @@ public function createTopicStartAction() {

/**
* @Route("/create-topic/", name="_FormFlow_createTopic")
* @Template("IntegrationTestBundle::layout_flow.html.twig")
*/
public function createTopicAction() {
return $this->processFlow(new Topic(), $this->get('integrationTestBundle.form.flow.createTopic'));
}

/**
* @Route("/create-vehicle/", name="_FormFlow_createVehicle")
* @Template("IntegrationTestBundle::layout_flow.html.twig")
*/
public function createVehicleAction() {
return $this->processFlow(new Vehicle(), $this->get('integrationTestBundle.form.flow.createVehicle'));
}

/**
* @Route("/demo1/", name="_FormFlow_demo1")
* @Template("IntegrationTestBundle::layout_flow.html.twig")
*/
public function demo1Action() {
return $this->processFlow((object) array(), $this->get('integrationTestBundle.form.flow.demo1'));
return $this->processFlow(new \stdClass(), $this->get('integrationTestBundle.form.flow.demo1'));
}

/**
* @Route("/issue64/", name="_FormFlow_issue64")
* @Template("IntegrationTestBundle::layout_flow.html.twig")
*/
public function issue64Action() {
return $this->processFlow(new Issue64Data(), $this->get('integrationTestBundle.form.flow.issue64'));
Expand All @@ -63,29 +58,26 @@ public function issue64Action() {
/**
* No trailing slash here to add the step only when needed.
* @Route("/issue87/{step}", defaults={"step"=1}, name="_FormFlow_issue87")
* @Template("IntegrationTestBundle::layout_flow.html.twig")
*/
public function issue87Action() {
return $this->processFlow((object) array(), $this->get('integrationTestBundle.form.flow.issue87'));
return $this->processFlow(new \stdClass(), $this->get('integrationTestBundle.form.flow.issue87'));
}

/**
* @Route("/skipFirstStepUsingClosure/", name="_FormFlow_skipFirstStepUsingClosure")
* @Template("IntegrationTestBundle::layout_flow.html.twig")
*/
public function skipFirstStepUsingClosureAction() {
return $this->processFlow((object) array(), $this->get('integrationTestBundle.form.flow.skipFirstStepUsingClosure'));
return $this->processFlow(new \stdClass(), $this->get('integrationTestBundle.form.flow.skipFirstStepUsingClosure'));
}

/**
* @Route("/removeSecondStepSkipMarkOnReset/", name="_FormFlow_removeSecondStepSkipMarkOnReset")
* @Template("IntegrationTestBundle::layout_flow.html.twig")
*/
public function removeSecondStepSkipMarkOnResetAction() {
return $this->processFlow((object) array(), $this->get('integrationTestBundle.form.flow.removeSecondStepSkipMarkOnReset'));
return $this->processFlow(new \stdClass(), $this->get('integrationTestBundle.form.flow.removeSecondStepSkipMarkOnReset'));
}

protected function processFlow($formData, FormFlow $flow) {
protected function processFlow($formData, FormFlow $flow, $template = 'IntegrationTestBundle::layout_flow.html.twig') {
$flow->bind($formData);

$form = $flow->createForm();
Expand All @@ -103,11 +95,11 @@ protected function processFlow($formData, FormFlow $flow) {
}
}

return array(
return $this->render($template, array(
'form' => $form->createView(),
'flow' => $flow,
'formData' => $formData,
);
));
}

}

0 comments on commit 2127447

Please sign in to comment.