Skip to content

Commit 4707a3a

Browse files
committed
Merge branch '2.7' into 2.8
* 2.7: fix some risky tests bumped Symfony version to 2.7.27 updated VERSION for 2.7.26 update CONTRIBUTORS for 2.7.26 updated CHANGELOG for 2.7.26
2 parents 4bb9470 + c4b0de7 commit 4707a3a

12 files changed

+97
-79
lines changed

Tests/CompoundFormTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,8 @@ public function testRemoveThrowsExceptionIfAlreadySubmitted()
299299
public function testRemoveIgnoresUnknownName()
300300
{
301301
$this->form->remove('notexisting');
302+
303+
$this->assertCount(0, $this->form);
302304
}
303305

304306
public function testArrayAccess()

Tests/Extension/Core/Type/ChoiceTypeTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,9 @@ public function testChoiceLoaderOptionExpectsChoiceLoaderInterface()
135135

136136
public function testChoiceListAndChoicesCanBeEmpty()
137137
{
138-
$this->factory->create(static::TESTED_TYPE, null, array(
138+
$this->assertInstanceOf('Symfony\Component\Form\FormInterface', $this->factory->create(static::TESTED_TYPE, null, array(
139139
'choices_as_values' => true,
140-
));
140+
)));
141141
}
142142

143143
public function testExpandedChoicesOptionsTurnIntoChildren()
@@ -2260,10 +2260,10 @@ public function testAdjustFullNameForMultipleNonExpanded()
22602260
// https://github.com/symfony/symfony/issues/3298
22612261
public function testInitializeWithEmptyChoices()
22622262
{
2263-
$this->factory->createNamed('name', static::TESTED_TYPE, null, array(
2263+
$this->assertInstanceOf('Symfony\Component\Form\FormInterface', $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
22642264
'choices' => array(),
22652265
'choices_as_values' => true,
2266-
));
2266+
)));
22672267
}
22682268

22692269
public function testInitializeWithDefaultObjectChoice()

Tests/Extension/Core/Type/CountryTypeTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,13 @@ public function testUnknownCountryIsNotIncluded()
5353
$choices = $this->factory->create(static::TESTED_TYPE, 'country')
5454
->createView()->vars['choices'];
5555

56+
$countryCodes = array();
57+
5658
foreach ($choices as $choice) {
57-
if ('ZZ' === $choice->value) {
58-
$this->fail('Should not contain choice "ZZ"');
59-
}
59+
$countryCodes[] = $choice->value;
6060
}
61+
62+
$this->assertNotContains('ZZ', $countryCodes);
6163
}
6264

6365
public function testSubmitNull($expected = null, $norm = null, $view = null)

Tests/Extension/Core/Type/DateTimeTypeTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ public function testInitializeWithDateTime()
283283
{
284284
// Throws an exception if "data_class" option is not explicitly set
285285
// to null in the type
286-
$this->factory->create(static::TESTED_TYPE, new \DateTime());
286+
$this->assertInstanceOf('Symfony\Component\Form\FormInterface', $this->factory->create(static::TESTED_TYPE, new \DateTime()));
287287
}
288288

289289
public function testSingleTextWidgetShouldUseTheRightInputType()

Tests/Extension/Core/Type/DateTypeTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ public function testInitializeWithDateTime()
721721
{
722722
// Throws an exception if "data_class" option is not explicitly set
723723
// to null in the type
724-
$this->factory->create(static::TESTED_TYPE, new \DateTime());
724+
$this->assertInstanceOf('Symfony\Component\Form\FormInterface', $this->factory->create(static::TESTED_TYPE, new \DateTime()));
725725
}
726726

727727
public function testSingleTextWidgetShouldUseTheRightInputType()

Tests/Extension/Core/Type/FormTypeTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -198,23 +198,23 @@ public function testPassMaxLengthBCToView()
198198

199199
public function testDataClassMayBeNull()
200200
{
201-
$this->factory->createBuilder(static::TESTED_TYPE, null, array(
201+
$this->assertInstanceOf('Symfony\Component\Form\FormBuilderInterface', $this->factory->createBuilder(static::TESTED_TYPE, null, array(
202202
'data_class' => null,
203-
));
203+
)));
204204
}
205205

206206
public function testDataClassMayBeAbstractClass()
207207
{
208-
$this->factory->createBuilder(static::TESTED_TYPE, null, array(
208+
$this->assertInstanceOf('Symfony\Component\Form\FormBuilderInterface', $this->factory->createBuilder(static::TESTED_TYPE, null, array(
209209
'data_class' => 'Symfony\Component\Form\Tests\Fixtures\AbstractAuthor',
210-
));
210+
)));
211211
}
212212

213213
public function testDataClassMayBeInterface()
214214
{
215-
$this->factory->createBuilder(static::TESTED_TYPE, null, array(
215+
$this->assertInstanceOf('Symfony\Component\Form\FormBuilderInterface', $this->factory->createBuilder(static::TESTED_TYPE, null, array(
216216
'data_class' => 'Symfony\Component\Form\Tests\Fixtures\AuthorInterface',
217-
));
217+
)));
218218
}
219219

220220
/**
@@ -701,7 +701,7 @@ public function testCanGetErrorsWhenButtonInForm()
701701
$form = $builder->getForm();
702702

703703
//This method should not throw a Fatal Error Exception.
704-
$form->getErrorsAsString();
704+
$this->assertInternalType('string', $form->getErrorsAsString());
705705
}
706706

707707
public function testSubmitNull($expected = null, $norm = null, $view = null)

Tests/Extension/Core/Type/TimeTypeTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ public function testInitializeWithDateTime()
498498
{
499499
// Throws an exception if "data_class" option is not explicitly set
500500
// to null in the type
501-
$this->factory->create(static::TESTED_TYPE, new \DateTime());
501+
$this->assertInstanceOf('Symfony\Component\Form\FormInterface', $this->factory->create(static::TESTED_TYPE, new \DateTime()));
502502
}
503503

504504
public function testSingleTextWidgetShouldUseTheRightInputType()

Tests/Extension/DependencyInjection/DependencyInjectionExtensionTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,21 +62,21 @@ public function testGetTypeExtensions()
6262
*/
6363
public function testThrowExceptionForInvalidExtendedType()
6464
{
65-
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
65+
$formTypeExtension = $this->createFormTypeExtensionMock('unmatched');
6666

67-
$typeExtension = $this->getMockBuilder('Symfony\Component\Form\FormTypeExtensionInterface')->getMock();
68-
$typeExtension->expects($this->any())
69-
->method('getExtendedType')
70-
->willReturn('unmatched');
67+
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
7168

7269
$container->expects($this->any())
7370
->method('get')
7471
->with('extension')
75-
->willReturn($typeExtension);
72+
->willReturn($formTypeExtension);
7673

7774
$extension = new DependencyInjectionExtension($container, array(), array('test' => array('extension')), array());
7875

79-
$extension->getTypeExtensions('test');
76+
$extensions = $extension->getTypeExtensions('test');
77+
78+
$this->assertCount(1, $extensions);
79+
$this->assertSame($formTypeExtension, $extensions[0]);
8080
}
8181

8282
public function testGetTypeGuesser()

Tests/FormBuilderTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ public function testAddButton()
161161
{
162162
$this->builder->add(new ButtonBuilder('reset'));
163163
$this->builder->add(new SubmitButtonBuilder('submit'));
164+
165+
$this->assertCount(2, $this->builder->all());
164166
}
165167

166168
public function testGetUnknown()

Tests/FormConfigTest.php

Lines changed: 54 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212
namespace Symfony\Component\Form\Tests;
1313

1414
use PHPUnit\Framework\TestCase;
15-
use Symfony\Component\Form\Exception\UnexpectedTypeException;
1615
use Symfony\Component\Form\FormConfigBuilder;
17-
use Symfony\Component\Form\Exception\InvalidArgumentException;
1816

1917
/**
2018
* @author Bernhard Schussek <[email protected]>
@@ -24,72 +22,65 @@ class FormConfigTest extends TestCase
2422
public function getHtml4Ids()
2523
{
2624
return array(
27-
array('z0', true),
28-
array('A0', true),
29-
array('A9', true),
30-
array('Z0', true),
31-
array('#', false),
32-
array('a#', false),
33-
array('a$', false),
34-
array('a%', false),
35-
array('a ', false),
36-
array("a\t", false),
37-
array("a\n", false),
38-
array('a-', true),
39-
array('a_', true),
40-
array('a:', true),
25+
array('z0'),
26+
array('A0'),
27+
array('A9'),
28+
array('Z0'),
29+
array('#', 'Symfony\Component\Form\Exception\InvalidArgumentException'),
30+
array('a#', 'Symfony\Component\Form\Exception\InvalidArgumentException'),
31+
array('a$', 'Symfony\Component\Form\Exception\InvalidArgumentException'),
32+
array('a%', 'Symfony\Component\Form\Exception\InvalidArgumentException'),
33+
array('a ', 'Symfony\Component\Form\Exception\InvalidArgumentException'),
34+
array("a\t", 'Symfony\Component\Form\Exception\InvalidArgumentException'),
35+
array("a\n", 'Symfony\Component\Form\Exception\InvalidArgumentException'),
36+
array('a-'),
37+
array('a_'),
38+
array('a:'),
4139
// Periods are allowed by the HTML4 spec, but disallowed by us
4240
// because they break the generated property paths
43-
array('a.', false),
41+
array('a.', 'Symfony\Component\Form\Exception\InvalidArgumentException'),
4442
// Contrary to the HTML4 spec, we allow names starting with a
4543
// number, otherwise naming fields by collection indices is not
4644
// possible.
4745
// For root forms, leading digits will be stripped from the
4846
// "id" attribute to produce valid HTML4.
49-
array('0', true),
50-
array('9', true),
47+
array('0'),
48+
array('9'),
5149
// Contrary to the HTML4 spec, we allow names starting with an
5250
// underscore, since this is already a widely used practice in
5351
// Symfony.
5452
// For root forms, leading underscores will be stripped from the
5553
// "id" attribute to produce valid HTML4.
56-
array('_', true),
54+
array('_'),
5755
// Integers are allowed
58-
array(0, true),
59-
array(123, true),
56+
array(0),
57+
array(123),
6058
// NULL is allowed
61-
array(null, true),
59+
array(null),
6260
// Other types are not
63-
array(1.23, false),
64-
array(5., false),
65-
array(true, false),
66-
array(new \stdClass(), false),
61+
array(1.23, 'Symfony\Component\Form\Exception\UnexpectedTypeException'),
62+
array(5., 'Symfony\Component\Form\Exception\UnexpectedTypeException'),
63+
array(true, 'Symfony\Component\Form\Exception\UnexpectedTypeException'),
64+
array(new \stdClass(), 'Symfony\Component\Form\Exception\UnexpectedTypeException'),
6765
);
6866
}
6967

7068
/**
7169
* @dataProvider getHtml4Ids
7270
*/
73-
public function testNameAcceptsOnlyNamesValidAsIdsInHtml4($name, $accepted)
71+
public function testNameAcceptsOnlyNamesValidAsIdsInHtml4($name, $expectedException = null)
7472
{
7573
$dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface')->getMock();
7674

77-
try {
78-
new FormConfigBuilder($name, null, $dispatcher);
79-
if (!$accepted) {
80-
$this->fail(sprintf('The value "%s" should not be accepted', $name));
81-
}
82-
} catch (UnexpectedTypeException $e) {
83-
// if the value was not accepted, but should be, rethrow exception
84-
if ($accepted) {
85-
throw $e;
86-
}
87-
} catch (InvalidArgumentException $e) {
88-
// if the value was not accepted, but should be, rethrow exception
89-
if ($accepted) {
90-
throw $e;
91-
}
75+
if (null !== $expectedException && method_exists($this, 'expectException')) {
76+
$this->expectException($expectedException);
77+
} elseif (null !== $expectedException) {
78+
$this->setExpectedException($expectedException);
9279
}
80+
81+
$formConfigBuilder = new FormConfigBuilder($name, null, $dispatcher);
82+
83+
$this->assertSame((string) $name, $formConfigBuilder->getName());
9384
}
9485

9586
public function testGetRequestHandlerCreatesNativeRequestHandlerIfNotSet()
@@ -109,27 +100,42 @@ public function testGetRequestHandlerReusesNativeRequestHandlerInstance()
109100

110101
public function testSetMethodAllowsGet()
111102
{
112-
$this->getConfigBuilder()->setMethod('GET');
103+
$formConfigBuilder = $this->getConfigBuilder();
104+
$formConfigBuilder->setMethod('GET');
105+
106+
self::assertSame('GET', $formConfigBuilder->getMethod());
113107
}
114108

115109
public function testSetMethodAllowsPost()
116110
{
117-
$this->getConfigBuilder()->setMethod('POST');
111+
$formConfigBuilder = $this->getConfigBuilder();
112+
$formConfigBuilder->setMethod('POST');
113+
114+
self::assertSame('POST', $formConfigBuilder->getMethod());
118115
}
119116

120117
public function testSetMethodAllowsPut()
121118
{
122-
$this->getConfigBuilder()->setMethod('PUT');
119+
$formConfigBuilder = $this->getConfigBuilder();
120+
$formConfigBuilder->setMethod('PUT');
121+
122+
self::assertSame('PUT', $formConfigBuilder->getMethod());
123123
}
124124

125125
public function testSetMethodAllowsDelete()
126126
{
127-
$this->getConfigBuilder()->setMethod('DELETE');
127+
$formConfigBuilder = $this->getConfigBuilder();
128+
$formConfigBuilder->setMethod('DELETE');
129+
130+
self::assertSame('DELETE', $formConfigBuilder->getMethod());
128131
}
129132

130133
public function testSetMethodAllowsPatch()
131134
{
132-
$this->getConfigBuilder()->setMethod('PATCH');
135+
$formConfigBuilder = $this->getConfigBuilder();
136+
$formConfigBuilder->setMethod('PATCH');
137+
138+
self::assertSame('PATCH', $formConfigBuilder->getMethod());
133139
}
134140

135141
/**

0 commit comments

Comments
 (0)