Skip to content

Commit

Permalink
merged branch 2.1.x into master
Browse files Browse the repository at this point in the history
  • Loading branch information
craue committed Jun 24, 2015
2 parents 6f1de29 + 2127447 commit a5554b6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 36 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() {
$flow
->expects($this->once())
->method('getCurrentStepNumber')
->will($this->returnValue(1))
;

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

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

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

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

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

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

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

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

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

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

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

public function testBcMethodDelegation_hasSkipStep() {
$flow = $this->getFlowWithMockedMethods(array('getName', 'isStepSkipped'));

$stepNumber = 1;

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

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

Expand Down
32 changes: 10 additions & 22 deletions Tests/IntegrationTestBundle/Controller/FormFlowController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,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 @@ -23,15 +22,13 @@ class FormFlowController extends Controller {

/**
* @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-topic-redirect-after-submit/", name="_FormFlow_createTopic_redirectAfterSubmit")
* @Template("IntegrationTestBundle::layout_flow.html.twig")
*/
public function createTopicRedirectAfterSubmitAction() {
$flow = $this->get('integrationTestBundle.form.flow.createTopic');
Expand All @@ -43,23 +40,20 @@ public function createTopicRedirectAfterSubmitAction() {

/**
* @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 @@ -68,15 +62,13 @@ 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("/issue149/", name="_FormFlow_issue149")
* @Template("IntegrationTestBundle::layout_flow.html.twig")
*/
public function issue149Action() {
return $this->processFlow(new Issue149Data(), $this->get('integrationTestBundle.form.flow.issue149'));
Expand All @@ -85,7 +77,6 @@ public function issue149Action() {
/**
* @Route("/revalidatePreviousSteps/enabled/", defaults={"enabled"=true}, name="_FormFlow_revalidatePreviousSteps_enabled")
* @Route("/revalidatePreviousSteps/disabled/", defaults={"enabled"=false}, name="_FormFlow_revalidatePreviousSteps_disabled")
* @Template("IntegrationTestBundle::layout_flow.html.twig")
*/
public function revalidatePreviousStepsAction($enabled) {
$flow = $this->get('integrationTestBundle.form.flow.revalidatePreviousSteps');
Expand All @@ -96,37 +87,34 @@ public function revalidatePreviousStepsAction($enabled) {

/**
* @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'));
}

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

/**
* @Route("/photoUpload/", name="_FormFlow_photoUpload")
* @Template("IntegrationTestBundle:FormFlow:photoUpload.html.twig")
*/
public function photoUploadAction() {
return $this->processFlow(new PhotoUpload(), $this->get('integrationTestBundle.form.flow.photoUpload'));
return $this->processFlow(new PhotoUpload(), $this->get('integrationTestBundle.form.flow.photoUpload'),
'IntegrationTestBundle:FormFlow:photoUpload.html.twig');
}

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

$form = $submittedForm = $flow->createForm();
Expand All @@ -152,11 +140,11 @@ protected function processFlow($formData, FormFlow $flow) {
return $this->redirect($this->generateUrl($request->attributes->get('_route'), $params));
}

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

protected function getCurrentRequest() {
Expand Down

0 comments on commit a5554b6

Please sign in to comment.