8000 minor #22267 fix some more risky tests (xabbuh) · symfony/symfony@a2cd63c · GitHub
[go: up one dir, main page]

Skip to content

Commit a2cd63c

Browse files
committed
minor #22267 fix some more risky tests (xabbuh)
This PR was merged into the 2.7 branch. Discussion ---------- fix some more risky tests | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | Continuation of #22066 fixing the tests for the following components: * Config * Form * HttpFoundation * Security Commits ------- fffcd24 fix some risky tests
2 parents e580c68 + fffcd24 commit a2cd63c

27 files changed

+222
-150
lines changed

src/Symfony/Component/Config/Tests/Definition/Builder/ArrayNodeDefinitionTest.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,16 @@ public function providePrototypedArrayNodeDefaults()
145145

146146
public function testNestedPrototypedArrayNodes()
147147
{
148-
$node = new ArrayNodeDefinition('root');
149-
$node
148+
$nodeDefinition = new ArrayNodeDefinition('root');
149+
$nodeDefinition
150150
->addDefaultChildrenIfNoneSet()
151151
->prototype('array')
152152
->prototype('array')
153153
;
154-
$node->getNode();
154+
$node = $nodeDefinition->getNode();
155+
156+
$this->assertInstanceOf('Symfony\Component\Config\Definition\PrototypedArrayNode', $node);
157+
$this->assertInstanceOf('Symfony\Component\Config\Definition\PrototypedArrayNode', $node->getPrototype());
155158
}
156159

157160
public function testEnabledNodeDefaults()

src/Symfony/Component/Config/Tests/Definition/Builder/TreeBuilderTest.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ public function testPrototypedArrayNodeUseTheCustomNodeBuilder()
7171
$root = $builder->root('override', 'array', new CustomNodeBuilder());
7272

7373
$root->prototype('bar')->end();
74+
75+
$this->assertInstanceOf('Symfony\Component\Config\Tests\Fixtures\BarNode', $root->getNode(true)->getPrototype());
7476
}
7577

7678
public function testAnExtendedNodeBuilderGetsPropagatedToTheChildren()
@@ -79,7 +81,7 @@ public function testAnExtendedNodeBuilderGetsPropagatedToTheChildren()
7981

8082
$builder->root('propagation')
8183
->children()
82-
->setNodeClass('extended', 'Symfony\Component\Config\Tests\Definition\Builder\VariableNodeDefinition')
84+
->setNodeClass('extended', 'Symfony\Component\Config\Definition\Builder\BooleanNodeDefinition')
8385
->node('foo', 'extended')->end()
8486
->arrayNode('child')
8587
->children()
@@ -88,6 +90,15 @@ public function testAnExtendedNodeBuilderGetsPropagatedToTheChildren()
8890
->end()
8991
->end()
9092
->end();
93+
94+
$node = $builder->buildTree();
95+
$children = $node->getChildren();
96+
97+
$this->assertInstanceOf('Symfony\Component\Config\Definition\BooleanNode', $children['foo']);
98+
99+
$childChildren = $children['child']->getChildren();
100+
101+
$this->assertInstanceOf('Symfony\Component\Config\Definition\BooleanNode', $childChildren['foo']);
91102
}
92103

93104
public function testDefinitionInfoGetsTransferredToNode()
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Config\Tests\Fixtures;
13+
14+
use Symfony\Component\Config\Definition\ArrayNode;
15+
16+
class BarNode extends ArrayNode
17+
{
18+
}

src/Symfony/Component/Config/Tests/Fixtures/Builder/BarNodeDefinition.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212
namespace Symfony\Component\Config\Tests\Definition\Builder;
1313

1414
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
15+
use Symfony\Component\Config\Tests\Fixtures\BarNode;
1516

1617
class BarNodeDefinition extends NodeDefinition
1718
{
1819
protected function createNode()
1920
{
21+
return new BarNode($this->name);
2022
}
2123
}

src/Symfony/Component/Form/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()

src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php

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

127127
public function testChoiceListAndChoicesCanBeEmpty()
128128
{
129-
$this->factory->create(static::TESTED_TYPE, null, array(
129+
$this->assertInstanceOf('Symfony\Component\Form\FormInterface', $this->factory->create(static::TESTED_TYPE, null, array(
130130
'choices_as_values' => true,
131-
));
131+
)));
132132
}
133133

134134
public function testExpandedChoicesOptionsTurnIntoChildren()
@@ -2251,10 +2251,10 @@ public function testAdjustFullNameForMultipleNonExpanded()
22512251
// https://github.com/symfony/symfony/issues/3298
22522252
public function testInitializeWithEmptyChoices()
22532253
{
2254-
$this->factory->createNamed('name', static::TESTED_TYPE, null, array(
2254+
$this->assertInstanceOf('Symfony\Component\Form\FormInterface', $this->factory->createNamed('name', static::TESTED_TYPE, null, array(
22552255
'choices' => array(),
22562256
'choices_as_values' => true,
2257-
));
2257+
)));
22582258
}
22592259

22602260
public function testInitializeWithDefaultObjectChoice()

src/Symfony/Component/Form/Tests/Extension/Core/Type/CountryTypeTest.php

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

46+
$countryCodes = array();
47+
4648
foreach ($choices as $choice) {
47-
if ('ZZ' === $choice->value) {
48-
$this->fail('Should not contain choice "ZZ"');
49-
}
49+
$countryCodes[] = $choice->value;
5050
}
51+
52+
$this->assertNotContains('ZZ', $countryCodes);
5153
}
5254

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

src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTimeTypeTest.php

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

279279
public function testSingleTextWidgetShouldUseTheRightInputType()

src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php

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

717717
public function testSingleTextWidgetShouldUseTheRightInputType()

src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php

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

150150
public function testDataClassMayBeNull()
151151
{
152-
$this->factory->createBuilder(static::TESTED_TYPE, null, array(
152+
$this->assertInstanceOf('Symfony\Component\Form\FormBuilderInterface', $this->factory->createBuilder(static::TESTED_TYPE, null, array(
153153
'data_class' => null,
154-
));
154+
)));
155155
}
156156

157157
public function testDataClassMayBeAbstractClass()
158158
{
159-
$this->factory->createBuilder(static::TESTED_TYPE, null, array(
159+
$this->assertInstanceOf('Symfony\Component\Form\FormBuilderInterface', $this->factory->createBuilder(static::TESTED_TYPE, null, array(
160160
'data_class' => 'Symfony\Component\Form\Tests\Fixtures\AbstractAuthor',
161-
));
161+
)));
162162
}
163163

164164
public function testDataClassMayBeInterface()
165165
{
166-
$this->factory->createBuilder(static::TESTED_TYPE, null, array(
166+
$this->assertInstanceOf('Symfony\Component\Form\FormBuilderInterface', $this->factory->createBuilder(static::TESTED_TYPE, null, array(
167167
'data_class' => 'Symfony\Component\Form\Tests\Fixtures\AuthorInterface',
168-
));
168+
)));
169169
}
170170

171171
/**
@@ -652,7 +652,7 @@ public function testCanGetErrorsWhenButtonInForm()
652652
$form = $builder->getForm();
653653

654654
//This method should not throw a Fatal Error Exception.
655-
$form->getErrorsAsString();
655+
$this->assertInternalType('string', $form->getErrorsAsString());
656656
}
657657

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

src/Symfony/Component/Form/Tests/Extension/Core/Type/TimeTypeTest.php

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

494494
public function testSingleTextWidgetShouldUseTheRightInputType()

src/Symfony/Component/Form/Tests/Extension/DependencyInjection/DependencyInjectionExtensionTest.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,21 @@ public function testGetTypeExtensions()
4646

4747
public function testThrowExceptionForInvalidExtendedType()
4848
{
49+
$formTypeExtension = $this->createFormTypeExtensionMock('unmatched');
50+
4951
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
5052

5153
$container->expects($this->any())
5254
->method('get')
5355
->with('extension')
54-
->willReturn($this->createFormTypeExtensionMock('unmatched'));
56+
->willReturn($formTypeExtension);
5557

5658
$extension = new DependencyInjectionExtension($container, array(), array('test' => array('extension')), array());
5759

58-
$extension->getTypeExtensions('test');
60+
$extensions = $extension->getTypeExtensions('test');
61+
62+
$this->assertCount(1, $extensions);
63+
$this->assertSame($formTypeExtension, $extensions[0]);
5964
}
6065

6166
public function testGetTypeGuesser()

src/Symfony/Component/Form/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()

0 commit comments

Comments
 (0)
0