Skip to content

Commit daea02d

Browse files
ISSUE-104: Updated Add-on Pack for Symfony 3.0
1 parent 0ba6ddf commit daea02d

File tree

8 files changed

+52
-45
lines changed

8 files changed

+52
-45
lines changed

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
{"name": "Raymond Schouten"}
1010
],
1111
"require": {
12-
"darkwebdesign/symfony-addon-transformers": "2.8.*",
12+
"darkwebdesign/symfony-addon-transformers": "3.0.*",
1313
"doctrine/common": "^2.4",
14-
"php": ">=5.3.9",
15-
"symfony/form": "2.8.*"
14+
"php": ">=5.5.9",
15+
"symfony/form": "3.0.*"
1616
},
1717
"require-dev": {
1818
"codeclimate/php-test-reporter": "^0.3.2",

src/BirthdayType.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
namespace DarkWebDesign\SymfonyAddon\FormType;
2222

2323
use Symfony\Component\Form\AbstractType;
24+
use Symfony\Component\Form\Extension\Core\Type\DateType;
2425
use Symfony\Component\OptionsResolver\OptionsResolver;
2526

2627
/**
@@ -51,6 +52,6 @@ public function configureOptions(OptionsResolver $resolver)
5152
*/
5253
public function getParent()
5354
{
54-
return 'Symfony\Component\Form\Extension\Core\Type\DateType';
55+
return DateType::class;
5556
}
5657
}

src/BooleanType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
use DarkWebDesign\SymfonyAddon\Transformer\BooleanToValueTransformer;
2424
use Symfony\Component\Form\AbstractType;
25+
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
2526
use Symfony\Component\Form\FormBuilderInterface;
2627
use Symfony\Component\OptionsResolver\Options;
2728
use Symfony\Component\OptionsResolver\OptionsResolver;
@@ -93,7 +94,6 @@ public function configureOptions(OptionsResolver $resolver)
9394
$resolver->setNormalizer('label_true', $labelTrueNormalizer);
9495
$resolver->setNormalizer('label_false', $labelFalseNormalizer);
9596
$resolver->setNormalizer('choices', $choicesNormalizer);
96-
$resolver->setNormalizer('choices_as_values', $choicesAsValuesNormalizer);
9797
$resolver->setNormalizer('expanded', $expandedNormalizer);
9898
$resolver->setNormalizer('multiple', $multipleNormalizer);
9999

@@ -112,7 +112,7 @@ public function configureOptions(OptionsResolver $resolver)
112112
*/
113113
public function getParent()
114114
{
115-
return 'Symfony\Component\Form\Extension\Core\Type\ChoiceType';
115+
return ChoiceType::class;
116116
}
117117

118118
/**

src/EntityType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public function configureOptions(OptionsResolver $resolver)
108108
$resolver->setAllowedTypes('entity_manager', array(
109109
'null',
110110
'string',
111-
'Doctrine\Common\Persistence\ObjectManager',
111+
ObjectManager::class,
112112
));
113113
}
114114
}

tests/BirthdayTypeTest.php

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,9 @@
2525

2626
class BirthdayTypeTest extends TypeTestCase
2727
{
28-
/** @var \DarkWebDesign\SymfonyAddon\FormType\BirthdayType */
29-
private $type;
30-
31-
protected function setUp()
32-
{
33-
parent::setUp();
34-
35-
$this->type = new BirthdayType();
36-
}
37-
3828
public function test()
3929
{
40-
$form = $this->factory->create($this->type);
30+
$form = $this->factory->create(BirthdayType::class);
4131

4232
$choices = $form->get('year')->getConfig()->getOption('choices');
4333

tests/BooleanTypeTest.php

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,6 @@
2525

2626
class BooleanTypeTest extends TypeTestCase
2727
{
28-
/** @var \DarkWebDesign\SymfonyAddon\FormType\BooleanType */
29-
private $type;
30-
31-
protected function setUp()
32-
{
33-
parent::setUp();
34-
35-
$this->type = new BooleanType();
36-
}
37-
3828
/**
3929
* @param string $valueTrue
4030
* @param string $valueFalse
@@ -48,13 +38,13 @@ public function test($valueTrue, $valueFalse)
4838
'value_false' => $valueFalse,
4939
);
5040

51-
$form = $this->factory->create($this->type, null, $options);
41+
$form = $this->factory->create(BooleanType::class, null, $options);
5242
$form->submit($valueTrue);
5343

5444
$this->assertTrue($form->isSynchronized());
5545
$this->assertTrue($form->getData());
5646

57-
$form = $this->factory->create($this->type, null, $options);
47+
$form = $this->factory->create(BooleanType::class, null, $options);
5848
$form->submit($valueFalse);
5949

6050
$this->assertTrue($form->isSynchronized());
@@ -74,7 +64,7 @@ public function testInvalidValue($valueTrue, $valueFalse)
7464
'value_false' => $valueFalse,
7565
);
7666

77-
$form = $this->factory->create($this->type, null, $options);
67+
$form = $this->factory->create(BooleanType::class, null, $options);
7868
$form->submit('foo');
7969

8070
$this->assertFalse($form->isSynchronized());
@@ -93,7 +83,7 @@ public function testWidget($widget, $expanded)
9383
'widget' => $widget,
9484
);
9585

96-
$form = $this->factory->create($this->type, null, $options);
86+
$form = $this->factory->create(BooleanType::class, null, $options);
9787
$view = $form->createView();
9888

9989
$this->assertSame($expanded, $view->vars['expanded']);
@@ -107,7 +97,7 @@ public function testHumanize()
10797
'value_false' => 'aCamel Cased Label',
10898
);
10999

110-
$form = $this->factory->create($this->type, null, $options);
100+
$form = $this->factory->create(BooleanType::class, null, $options);
111101
$view = $form->createView();
112102

113103
$this->assertCount(2, $view->vars['choices']);

tests/EntityTypeTest.php

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
use DarkWebDesign\SymfonyAddon\FormType\EntityType;
2424
use DarkWebDesign\SymfonyAddon\FormType\Tests\Models\City;
25+
use Symfony\Component\Form\PreloadedExtension;
2526
use Symfony\Component\Form\Test\TypeTestCase;
2627

2728
class EntityTypeTest extends TypeTestCase
@@ -47,13 +48,8 @@ class EntityTypeTest extends TypeTestCase
4748
/** @var \Doctrine\Common\Persistence\Mapping\ClassMetadata */
4849
private $metadata;
4950

50-
/** @var \DarkWebDesign\SymfonyAddon\FormType\EntityType */
51-
private $type;
52-
5351
protected function setUp()
5452
{
55-
parent::setUp();
56-
5753
$this->entity = new City();
5854
$this->entity->setId(123);
5955

@@ -72,8 +68,20 @@ protected function setUp()
7268
$this->metadata->method('getIdentifierValues')->willReturn(array('id' => $this->identifier));
7369

7470
$this->metadata->isIdentifierComposite = false;
75-
76-
$this->type = new EntityType($this->registry);
71+
72+
parent::setUp();
73+
}
74+
75+
/**
76+
* @return array
77+
*/
78+
protected function getExtensions()
79+
{
80+
$type = new EntityType($this->registry);
81+
82+
return array(
83+
new PreloadedExtension(array($type), array()),
84+
);
7785
}
7886

7987
public function test()
@@ -86,7 +94,7 @@ public function test()
8694
'class' => $this->className,
8795
);
8896

89-
$form = $this->factory->create($this->type, null, $options);
97+
$form = $this->factory->create(EntityType::class, null, $options);
9098
$form->submit($this->identifier);
9199

92100
$this->assertTrue($form->isSynchronized());
@@ -103,7 +111,7 @@ public function testEntityNotFound()
103111
'class' => $this->className,
104112
);
105113

106-
$form = $this->factory->create($this->type, null, $options);
114+
$form = $this->factory->create(EntityType::class, null, $options);
107115
$form->submit($this->identifier);
108116

109117
$this->assertFalse($form->isSynchronized());
@@ -119,7 +127,7 @@ public function testEntityManagerObject()
119127
'entity_manager' => $this->entityManager,
120128
);
121129

122-
$form = $this->factory->create($this->type, null, $options);
130+
$form = $this->factory->create(EntityType::class, null, $options);
123131
$form->submit($this->identifier);
124132

125133
$this->assertTrue($form->isSynchronized());
@@ -137,7 +145,7 @@ public function testEntityManagerString()
137145
'entity_manager' => 'Doctrine\ORM\EntityManager',
138146
);
139147

140-
$form = $this->factory->create($this->type, null, $options);
148+
$form = $this->factory->create(EntityType::class, null, $options);
141149
$form->submit($this->identifier);
142150

143151
$this->assertTrue($form->isSynchronized());
@@ -159,7 +167,7 @@ public function testNoEntityManager()
159167
'class' => $this->className,
160168
);
161169

162-
$form = $this->factory->create($this->type, null, $options);
170+
$form = $this->factory->create(EntityType::class, null, $options);
163171
$form->submit($this->identifier);
164172

165173
$this->assertTrue($form->isSynchronized());

tests/Models/City.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,22 @@
11
<?php
2+
/**
3+
* Copyright (c) 2018 DarkWeb Design
4+
*
5+
* Permission is hereby granted, free of charge, to any person obtaining a copy
6+
* of this software and associated documentation files (the "Software"), to deal
7+
* in the Software without restriction, including without limitation the rights
8+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
* copies of the Software, and to permit persons to whom the Software is
10+
* furnished to do so, subject to the following conditions:
11+
*
12+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
18+
* SOFTWARE.
19+
*/
220

321
namespace DarkWebDesign\SymfonyAddon\FormType\Tests\Models;
422

0 commit comments

Comments
 (0)