Skip to content

Commit 9b90e54

Browse files
author
Harrison Heck
committed
Updated compatibility to Symfony 3.2.
1 parent cf0d3d8 commit 9b90e54

File tree

5 files changed

+30
-22
lines changed

5 files changed

+30
-22
lines changed

Form/FormFactory.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Linio\DynamicFormBundle\Exception\NonExistentFormException;
88
use Linio\DynamicFormBundle\Exception\NotExistentDataProviderException;
99
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
10+
use Symfony\Component\Form\Extension\Core\Type\FormType;
1011
use Symfony\Component\Form\FormBuilderInterface;
1112
use Symfony\Component\Form\FormFactory as SymfonyFormFactory;
1213
use Symfony\Component\Form\FormInterface;
@@ -117,7 +118,7 @@ public function createBuilder($key, $data = [], $options = [], $name = null)
117118
throw new NonExistentFormException(sprintf('The form "%s" was not found.', $key));
118119
}
119120

120-
$formBuilder = $this->formFactory->createNamedBuilder($name ?: $key, 'form', $data, $options);
121+
$formBuilder = $this->formFactory->createNamedBuilder($name ?: $key, FormType::class, $data, $options);
121122

122123
if (isset($this->eventSubscribers[$key])) {
123124
foreach ($this->eventSubscribers[$key] as $eventSubscriber) {

Resources/config/services.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,4 @@ services:
108108
form.type_extension.help_message:
109109
class: Linio\DynamicFormBundle\Form\Extension\HelpMessageTypeExtension
110110
tags:
111-
- {name: form.type_extension, alias: Symfony\Component\Form\Extension\Core\Type\FormType}
111+
- {name: form.type_extension, extended_type: Symfony\Component\Form\Extension\Core\Type\FormType}

Tests/Form/FormFactoryTest.php

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@
22

33
namespace Linio\DynamicFormBundle\Tests\Form\FormFactoryTest;
44

5+
use Linio\DynamicFormBundle\Exception\NonExistentFormException;
56
use Linio\DynamicFormBundle\Form\FormFactory;
7+
use Linio\DynamicFormBundle\HelpMessageProvider;
68
use Prophecy\Prophecy\ObjectProphecy;
79
use Symfony\Component\Form\DataTransformerInterface;
10+
use Symfony\Component\Form\Extension\Core\Type\FormType;
11+
use Symfony\Component\Form\FormBuilder;
12+
use Symfony\Component\Form\FormFactory as SymfonyFormFactory;
813
use Symfony\Component\Validator\Constraints\IsTrue;
914

1015
class FormFactoryTest extends \PHPUnit_Framework_TestCase
@@ -49,7 +54,7 @@ public function testIsCreatingASimpleForm()
4954
],
5055
];
5156

52-
$this->formFactoryMock->createNamedBuilder('foo', 'form', ['foo_form_data'], ['foo_form_options'])
57+
$this->formFactoryMock->createNamedBuilder('foo', FormType::class, ['foo_form_data'], ['foo_form_options'])
5358
->willReturn($this->formBuilderMock->reveal());
5459

5560
$this->formBuilderMock->create('field1', 'field1_type', ['field1_options'])
@@ -91,7 +96,7 @@ public function testIsCreatingFormWithValidators()
9196
],
9297
];
9398

94-
$this->formFactoryMock->createNamedBuilder('foo', 'form', [], [])
99+
$this->formFactoryMock->createNamedBuilder('foo', FormType::class, [], [])
95100
->willReturn($this->formBuilderMock->reveal());
96101

97102
$this->formBuilderMock->create('field1', 'field1_type', $expectedFieldOptions)
@@ -113,15 +118,15 @@ public function testIsCreatingFormWithValidators()
113118

114119
public function testIsCreatingFormWithTransformers()
115120
{
116-
$fieldOneMock = $this->prophesize('Symfony\Component\Form\FormBuilder');
121+
$fieldOneMock = $this->prophesize(FormBuilder::class);
117122

118123
$formConfiguration = [
119124
'foo' => [
120125
'field1' => [
121126
'enabled' => true,
122127
'type' => 'field1_type',
123128
'transformer' => [
124-
'class' => 'Linio\DynamicFormBundle\Tests\Form\FormFactoryTest\MockTransformer',
129+
'class' => MockTransformer::class,
125130
'calls' => [
126131
['setUserFormat', ['d/m/Y']],
127132
['setInputFormat', ['Y-m-d']],
@@ -137,7 +142,7 @@ public function testIsCreatingFormWithTransformers()
137142

138143
$expectedFieldOptions = [];
139144

140-
$this->formFactoryMock->createNamedBuilder('foo', 'form', [], [])
145+
$this->formFactoryMock->createNamedBuilder('foo', FormType::class, [], [])
141146
->willReturn($this->formBuilderMock->reveal());
142147

143148
$this->formBuilderMock->create('field1', 'field1_type', $expectedFieldOptions)
@@ -175,13 +180,13 @@ public function testIsCreatingFormWithHelpMessages()
175180
],
176181
];
177182

178-
$helpMessageProviderMock = $this->prophesize('Linio\DynamicFormBundle\HelpMessageProvider');
183+
$helpMessageProviderMock = $this->prophesize(HelpMessageProvider::class);
179184

180185
$helpMessageProviderMock->getHelpMessage('cms:message')
181186
->shouldBeCalled()
182187
->willReturn('message');
183188

184-
$this->formFactoryMock->createNamedBuilder('foo', 'form', ['foo_form_data'], $formConfiguration)
189+
$this->formFactoryMock->createNamedBuilder('foo', FormType::class, ['foo_form_data'], $formConfiguration)
185190
->shouldBeCalled()
186191
->willReturn($this->formBuilderMock->reveal());
187192

@@ -251,9 +256,6 @@ public function testIsHandlingNullName()
251256
$this->assertEquals($configuration, $actual);
252257
}
253258

254-
/**
255-
* @expectedException \Linio\DynamicFormBundle\Exception\NonExistentFormException
256-
*/
257259
public function testIsHandlingNotExistenFormException()
258260
{
259261
$configuration = [
@@ -271,6 +273,8 @@ public function testIsHandlingNotExistenFormException()
271273

272274
$this->formFactory->setConfiguration($configuration);
273275

276+
$this->expectException(NonExistentFormException::class);
277+
274278
$this->formFactory->getConfiguration('bar');
275279
}
276280

@@ -303,8 +307,8 @@ public function testIsCreatingValidator()
303307

304308
public function setup()
305309
{
306-
$this->formBuilderMock = $this->prophesize('Symfony\Component\Form\FormBuilder');
307-
$this->formFactoryMock = $this->prophesize('Symfony\Component\Form\FormFactory');
310+
$this->formBuilderMock = $this->prophesize(FormBuilder::class);
311+
$this->formFactoryMock = $this->prophesize(SymfonyFormFactory::class);
308312

309313
$this->formFactory = new FormFactory();
310314
}

Tests/FormlyMapper/FormlyMapperTest.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
namespace Linio\DynamicFormBundle\Tests\FormlyMapper;
44

5+
use Linio\DynamicFormBundle\Exception\NonExistentFormException;
6+
use Linio\DynamicFormBundle\Form\FormFactory;
7+
use Linio\DynamicFormBundle\FormlyMapper\FormlyField;
8+
use Linio\DynamicFormBundle\FormlyMapper\FormlyField\FormlyFieldFactory;
59
use Linio\DynamicFormBundle\FormlyMapper\FormlyMapper;
610
use Prophecy\Prophecy\ObjectProphecy;
711
use Symfony\Component\Security\Csrf\CsrfToken;
@@ -115,7 +119,7 @@ public function testIsThrowingNonExistentFormException()
115119
$formName = 'foo';
116120

117121
$this->formFactoryMock->getConfiguration($formName)
118-
->willThrow('Linio\DynamicFormBundle\Exception\NonExistentFormException');
122+
->willThrow(NonExistentFormException::class);
119123

120124
$this->formlyMapper->setFormFactory($this->formFactoryMock->reveal());
121125

@@ -126,9 +130,9 @@ public function setup()
126130
{
127131
$this->csrfToken = new CsrfToken('foo', 'bar');
128132
$this->csrfTokenManagerMock = $this->prophesize('Symfony\Component\Security\Csrf\CsrfTokenManagerInterface');
129-
$this->formFactoryMock = $this->prophesize('Linio\DynamicFormBundle\Form\FormFactory');
130-
$this->formlyFieldFactoryMock = $this->prophesize('Linio\DynamicFormBundle\FormlyMapper\FormlyField\FormlyFieldFactory');
131-
$this->formlyFieldMock = $this->prophesize('Linio\DynamicFormBundle\FormlyMapper\FormlyField');
133+
$this->formFactoryMock = $this->prophesize(FormFactory::class);
134+
$this->formlyFieldFactoryMock = $this->prophesize(FormlyFieldFactory::class);
135+
$this->formlyFieldMock = $this->prophesize(FormlyField::class);
132136

133137
$this->formlyMapper = new FormlyMapper();
134138
}

composer.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@
66
"license": "BSD-3-Clause",
77
"require": {
88
"php": ">=7.1",
9-
"symfony/framework-bundle": "^3.2",
10-
"symfony/form": "^3.2"
9+
"symfony/form": "^2.8|^3.0"
1110
},
1211
"require-dev": {
1312
"phpunit/phpunit": "^5.7",
14-
"symfony/validator": "^3.2",
13+
"symfony/validator": "^2.8|^3.0",
1514
"friendsofphp/php-cs-fixer": "^2.0",
16-
"symfony/security": "^3.2"
15+
"symfony/security": "^2.8|^3.0"
1716
},
1817
"autoload": {
1918
"psr-4": {

0 commit comments

Comments
 (0)