Skip to content

Commit

Permalink
Merge d8bf9bb into 1dc49c2
Browse files Browse the repository at this point in the history
  • Loading branch information
craue committed Jun 25, 2015
2 parents 1dc49c2 + d8bf9bb commit 834c2c5
Show file tree
Hide file tree
Showing 19 changed files with 98 additions and 173 deletions.
6 changes: 0 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@ matrix:
include:
- php: 5.3.3
env: USE_DEPS="lowest"
- php: 5.5
env: SYMFONY_VERSION="2.3.*"
- php: 5.5
env: SYMFONY_VERSION="2.4.*"
- php: 5.5
env: SYMFONY_VERSION="2.5.*"
- php: 5.5
env: SYMFONY_VERSION="2.6.*"
- php: 5.5
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- [#145]: bumped Symfony dependency to 2.3
- [#148]: restructured data storage
- [#180]: renamed step config option `type` to `form_type`
- [#184]: made the bundle Symfony 3 compatible, bumped Symfony dependency to 2.6
- removed the step field template
- renamed property `step` to `stepNumber` and method `getStep` to `getStepNumber` within event classes
- [#98]+[#143]: add a validation error to the current form if a form of a previous step became invalid
Expand Down Expand Up @@ -41,6 +42,7 @@
[#175]: https://github.com/craue/CraueFormFlowBundle/issues/175
[#178]: https://github.com/craue/CraueFormFlowBundle/issues/178
[#180]: https://github.com/craue/CraueFormFlowBundle/issues/180
[#184]: https://github.com/craue/CraueFormFlowBundle/issues/184

## 2.1.8 (2015-06-11)

Expand Down
11 changes: 2 additions & 9 deletions Form/Extension/FormFlowFormExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Symfony\Component\Form\AbstractTypeExtension;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

Expand All @@ -27,18 +26,12 @@ public function getExtendedType() {
* {@inheritDoc}
*/
public function configureOptions(OptionsResolver $resolver) {
$optionNames = array(
$resolver->setDefined(array(
'flow_instance',
'flow_instance_key',
'flow_step',
'flow_step_key',
);

if (Kernel::VERSION_ID < 20600) {
$resolver->setOptional($optionNames);
} else {
$resolver->setDefined($optionNames);
}
));
}

/**
Expand Down
11 changes: 2 additions & 9 deletions Form/Extension/FormFlowHiddenFieldExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Symfony\Component\Form\AbstractTypeExtension;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

Expand All @@ -28,16 +27,10 @@ public function getExtendedType() {
* {@inheritDoc}
*/
public function configureOptions(OptionsResolver $resolver) {
$optionNames = array(
$resolver->setDefined(array(
'flow_instance_key',
'flow_step_key',
);

if (Kernel::VERSION_ID < 20600) {
$resolver->setOptional($optionNames);
} else {
$resolver->setDefined($optionNames);
}
));
}

/**
Expand Down
15 changes: 9 additions & 6 deletions Form/FormFlow.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;

/**
* @author Christian Raue <christian.raue@gmail.com>
Expand Down Expand Up @@ -85,9 +86,9 @@ abstract class FormFlow implements FormFlowInterface {
protected $dynamicStepNavigationStepParameter = 'step';

/**
* @var Request|null
* @var RequestStack
*/
private $request = null;
private $requestStack;

/**
* @var string|null Is only null if not yet initialized.
Expand Down Expand Up @@ -165,20 +166,22 @@ public function setFormFactory(FormFactoryInterface $formFactory) {
/**
* {@inheritDoc}
*/
public function setRequest(Request $request = null) {
$this->request = $request;
public function setRequestStack(RequestStack $requestStack) {
$this->requestStack = $requestStack;
}

/**
* @return Request
* @throws \RuntimeException If the request is not available.
*/
public function getRequest() {
if ($this->request === null) {
$currentRequest = $this->requestStack->getCurrentRequest();

if ($currentRequest === null) {
throw new \RuntimeException('The request is not available.');
}

return $this->request;
return $currentRequest;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions Form/FormFlowInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;

/**
* @author Christian Raue <christian.raue@gmail.com>
Expand All @@ -27,9 +27,9 @@ function getName();
function setFormFactory(FormFactoryInterface $formFactory);

/**
* @param Request|null $request
* @param RequestStack $requestStack
*/
function setRequest(Request $request = null);
function setRequestStack(RequestStack $requestStack);

/**
* @param DataManagerInterface $dataManager
Expand Down
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,7 @@ XML

<service id="myCompany.form.flow.createVehicle"
class="MyCompany\MyBundle\Form\CreateVehicleFlow"
parent="craue.form.flow"
scope="request">
parent="craue.form.flow">
<call method="setFormType">
<argument type="service" id="myCompany.form.createVehicle" />
</call>
Expand All @@ -163,7 +162,6 @@ services:
myCompany.form.flow.createVehicle:
class: MyCompany\MyBundle\Form\CreateVehicleFlow
parent: craue.form.flow
scope: request
calls:
- [ setFormType, [ "@myCompany.form.createVehicle" ] ]
```
Expand Down Expand Up @@ -258,8 +256,7 @@ XML
<services>
<service id="myCompany.form.flow.createVehicle"
class="MyCompany\MyBundle\Form\CreateVehicleFlow"
parent="craue.form.flow"
scope="request">
parent="craue.form.flow">
</service>
</services>
```
Expand All @@ -270,7 +267,6 @@ services:
myCompany.form.flow.createVehicle:
class: MyCompany\MyBundle\Form\CreateVehicleFlow
parent: craue.form.flow
scope: request
```

## Create a form template
Expand Down
14 changes: 7 additions & 7 deletions Resources/config/form_flow.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,27 @@
</parameters>

<services>
<service id="craue.form.flow.storage_default" class="%craue.form.flow.storage.class%" scope="request" public="false">
<service id="craue.form.flow.storage_default" class="%craue.form.flow.storage.class%" public="false">
<argument type="service" id="session" />
</service>

<service id="craue.form.flow.storage" alias="craue.form.flow.storage_default" scope="request" />
<service id="craue.form.flow.storage" alias="craue.form.flow.storage_default" />

<service id="craue.form.flow.data_manager_default" class="Craue\FormFlowBundle\Storage\DataManager" scope="request" public="false">
<service id="craue.form.flow.data_manager_default" class="Craue\FormFlowBundle\Storage\DataManager" public="false">
<argument type="service" id="craue.form.flow.storage" />
</service>

<service id="craue.form.flow.data_manager" alias="craue.form.flow.data_manager_default" scope="request" />
<service id="craue.form.flow.data_manager" alias="craue.form.flow.data_manager_default" />

<service id="craue.form.flow" class="%craue.form.flow.class%" scope="request">
<service id="craue.form.flow" class="%craue.form.flow.class%">
<call method="setDataManager">
<argument type="service" id="craue.form.flow.data_manager" />
</call>
<call method="setFormFactory">
<argument type="service" id="form.factory" />
</call>
<call method="setRequest">
<argument type="service" id="request" />
<call method="setRequestStack">
<argument type="service" id="request_stack" />
</call>
<call method="setEventDispatcher">
<argument type="service" id="event_dispatcher" on-invalid="ignore" />
Expand Down
41 changes: 8 additions & 33 deletions Tests/CreateVehicleFlowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Craue\FormFlowBundle\Tests;

use Craue\FormFlowBundle\Tests\IntegrationTestCase;
use Symfony\Component\HttpKernel\Kernel;

/**
* @group integration
Expand Down Expand Up @@ -214,22 +213,10 @@ public function testCreateVehicle_submitInvalidValues() {

// invalid number of wheels -> step 1 again
$form = $crawler->selectButton('next')->form();
if (Kernel::VERSION_ID >= 20400) {
$form->disableValidation();
$crawler = $this->client->submit($form, array(
'createVehicle[numberOfWheels]' => 99,
));
} else {
// impossible to send invalid values with DomCrawler, see https://github.com/symfony/symfony/issues/7672
// TODO remove as soon as Symfony >= 2.4 is required
$crawler = $this->client->request($form->getMethod(), $form->getUri(), array(
'flow_createVehicle_instance' => $form->get('flow_createVehicle_instance')->getValue(),
'flow_createVehicle_step' => 1,
'createVehicle' => array(
'numberOfWheels' => 99,
),
));
}
$form->disableValidation();
$crawler = $this->client->submit($form, array(
'createVehicle[numberOfWheels]' => 99,
));
$this->assertCurrentStepNumber(1, $crawler);
$this->assertContainsFormError('This value is not valid.', $crawler);

Expand All @@ -242,22 +229,10 @@ public function testCreateVehicle_submitInvalidValues() {

// invalid engine -> step 2 again
$form = $crawler->selectButton('next')->form();
if (Kernel::VERSION_ID >= 20400) {
$form->disableValidation();
$crawler = $this->client->submit($form, array(
'createVehicle[engine]' => 'magic',
));
} else {
// impossible to send invalid values with DomCrawler, see https://github.com/symfony/symfony/issues/7672
// TODO remove as soon as Symfony >= 2.4 is required
$crawler = $this->client->request($form->getMethod(), $form->getUri(), array(
'flow_createVehicle_instance' => $form->get('flow_createVehicle_instance')->getValue(),
'flow_createVehicle_step' => 2,
'createVehicle' => array(
'engine' => 'magic',
),
));
}
$form->disableValidation();
$crawler = $this->client->submit($form, array(
'createVehicle[engine]' => 'magic',
));
$this->assertCurrentStepNumber(2, $crawler);
$this->assertContainsFormError('This value is not valid.', $crawler);
}
Expand Down
3 changes: 0 additions & 3 deletions Tests/Demo1FlowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ public function testDemo1_events() {

protected function getCalledEvents() {
$container = static::$kernel->getContainer();
$container->enterScope('request');
$container->set('request', $this->client->getRequest(), 'request');

$flow = $container->get('integrationTestBundle.form.flow.demo1');
$storage = $container->get('craue.form.flow.storage');

Expand Down
25 changes: 15 additions & 10 deletions Tests/Form/FormFlowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Symfony\Component\Form\Forms;
use Symfony\Component\Form\FormBuilder;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;

/**
* @group unit
Expand Down Expand Up @@ -317,15 +318,27 @@ public function dataIsValid() {
);
}

public function testSetGetRequest() {
public function testSetGetRequestStack() {
$flow = $this->getMockedFlow();

$request = Request::create('');
$flow->setRequest($request);
$requestStack = new RequestStack();
$requestStack->push($request);
$flow->setRequestStack($requestStack);

$this->assertSame($request, $flow->getRequest());
}

/**
* @expectedException \RuntimeException
* @expectedExceptionMessage The request is not available.
*/
public function testGetRequestStack_notAvailable() {
$flow = $this->getMockedFlow();
$flow->setRequestStack(new RequestStack());
$flow->getRequest();
}

public function testSetGetDataManager() {
$flow = $this->getMockedFlow();

Expand Down Expand Up @@ -470,14 +483,6 @@ public function testSetGetDynamicStepNavigationStepParameter() {
$this->assertEquals($dynamicStepNavigationStepParameter, $flow->getDynamicStepNavigationStepParameter());
}

/**
* @expectedException \RuntimeException
* @expectedExceptionMessage The request is not available.
*/
public function testGetRequest_notAvailable() {
$this->getMockedFlow()->getRequest();
}

/**
* @expectedException \RuntimeException
* @expectedExceptionMessage Form data has not been evaluated yet and thus cannot be accessed.
Expand Down
13 changes: 1 addition & 12 deletions Tests/IntegrationTestBundle/Controller/FormFlowController.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ protected function processFlow($formData, FormFlow $flow, $template = 'Integrati
}

if ($flow->redirectAfterSubmit($submittedForm)) {
$request = $this->getCurrentRequest();
$request = $this->get('request_stack')->getCurrentRequest();
$params = $this->get('craue_formflow_util')->addRouteParameters(array_merge($request->query->all(),
$request->attributes->get('_route_params')), $flow);

Expand All @@ -147,15 +147,4 @@ protected function processFlow($formData, FormFlow $flow, $template = 'Integrati
));
}

protected function getCurrentRequest() {
if ($this->has('request_stack')) {
return $this->get('request_stack')->getCurrentRequest();
}

// TODO remove as soon as Symfony >= 2.4 is required
if ($this->has('request')) {
return $this->get('request');
}
}

}
Loading

0 comments on commit 834c2c5

Please sign in to comment.