Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 597d06c

Browse files
committed
Merge branch '3.0'
* 3.0: [3.0] [Tests] minor fix following #17787 [2.8] [Form] minor fix some tests with placeholder in AbstractLayout [DependencyInjection] fix tests Validate XLIFF translation files [DependencyInjection] replace alias in factories replace alias in factory services
2 parents 1b85799 + 2e22c39 commit 597d06c

File tree

8 files changed

+133
-6
lines changed

8 files changed

+133
-6
lines changed

src/Symfony/Component/DependencyInjection/Compiler/ReplaceAliasByActualDefinitionPass.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ private function updateReferences($container, $currentId, $newId)
9595
$definition->setProperties(
9696
$this->updateArgumentReferences($definition->getProperties(), $currentId, $newId)
9797
);
98+
99+
$definition->setFactoryService($this->updateFactoryServiceReference($definition->getFactoryService(false), $currentId, $newId), false);
100+
$definition->setFactory($this->updateFactoryReference($definition->getFactory(), $currentId, $newId));
98101
}
99102
}
100103

@@ -122,4 +125,26 @@ private function updateArgumentReferences(array $arguments, $currentId, $newId)
122125

123126
return $arguments;
124127
}
128+
129+
private function updateFactoryServiceReference($factoryService, $currentId, $newId)
130+
{
131+
if (null === $factoryService) {
132+
return;
133+
}
134+
135+
return $currentId === $factoryService ? $newId : $currentId;
136+
}
137+
138+
private function updateFactoryReference($factory, $currentId, $newId)
139+
{
140+
if (null === $factory || !is_array($factory) || !$factory[0] instanceof Reference) {
141+
return $factory;
142+
}
143+
144+
if ($currentId === (string) $factory[0]) {
145+
$factory[0] = new Reference($newId, $factory[0]->getInvalidBehavior());
146+
}
147+
148+
return $factory;
149+
}
125150
}

src/Symfony/Component/DependencyInjection/Tests/Compiler/ReplaceAliasByActualDefinitionPassTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,18 @@
1414
use Symfony\Component\DependencyInjection\Compiler\ReplaceAliasByActualDefinitionPass;
1515
use Symfony\Component\DependencyInjection\ContainerBuilder;
1616
use Symfony\Component\DependencyInjection\Definition;
17+
use Symfony\Component\DependencyInjection\Reference;
1718

1819
class ReplaceAliasByActualDefinitionPassTest extends \PHPUnit_Framework_TestCase
1920
{
2021
public function testProcess()
2122
{
2223
$container = new ContainerBuilder();
2324

24-
$container->register('a', '\stdClass');
25+
$aDefinition = $container->register('a', '\stdClass');
26+
$aDefinition->setFactoryService('b', false);
27+
28+
$aDefinition->setFactory(array(new Reference('b'), 'createA'));
2529

2630
$bDefinition = new Definition('\stdClass');
2731
$bDefinition->setPublic(false);
@@ -39,6 +43,11 @@ public function testProcess()
3943
$container->has('b_alias') && !$container->hasAlias('b_alias'),
4044
'->process() replaces alias to actual.'
4145
);
46+
47+
$this->assertSame('b_alias', $aDefinition->getFactoryService(false));
48+
49+
$resolvedFactory = $aDefinition->getFactory(false);
50+
$this->assertSame('b_alias', (string) $resolvedFactory[0]);
4251
}
4352

4453
/**

src/Symfony/Component/Form/Tests/AbstractBootstrap3LayoutTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,6 @@ public function testSelectWithSizeBiggerThanOneCanBeRequired()
235235
{
236236
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
237237
'choices' => array('a', 'b'),
238-
'choices_as_values' => true,
239238
'multiple' => false,
240239
'expanded' => false,
241240
'attr' => array('size' => 2),
@@ -818,7 +817,8 @@ public function testSingleChoiceExpandedWithPlaceholderWithoutTranslation()
818817
'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
819818
'multiple' => false,
820819
'expanded' => true,
821-
'translation_domain' => false,
820+
'required' => false,
821+
'choice_translation_domain' => false,
822822
'placeholder' => 'Placeholder&Not&Translated',
823823
));
824824

src/Symfony/Component/Form/Tests/AbstractLayoutTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,6 @@ public function testSelectWithSizeBiggerThanOneCanBeRequired()
521521
{
522522
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
523523
'choices' => array('a', 'b'),
524-
'choices_as_values' => true,
525524
'multiple' => false,
526525
'expanded' => false,
527526
'attr' => array('size' => 2),
@@ -963,6 +962,7 @@ public function testSingleChoiceExpandedWithoutTranslation()
963962
'multiple' => false,
964963
'expanded' => true,
965964
'choice_translation_domain' => false,
965+
'placeholder' => 'Placeholder&Not&Translated',
966966
));
967967

968968
$this->assertWidgetMatchesXpath($form->createView(), array(),
@@ -1034,7 +1034,8 @@ public function testSingleChoiceExpandedWithPlaceholderWithoutTranslation()
10341034
'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
10351035
'multiple' => false,
10361036
'expanded' => true,
1037-
'translation_domain' => false,
1037+
'required' => false,
1038+
'choice_translation_domain' => false,
10381039
'placeholder' => 'Placeholder&Not&Translated',
10391040
));
10401041

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1306,7 +1306,6 @@ public function testDontPassPlaceholderIfContainedInChoices($multiple, $expanded
13061306
'required' => $required,
13071307
'placeholder' => $placeholder,
13081308
'choices' => array('Empty' => '', 'A' => 'a'),
1309-
'choices_as_values' => true,
13101309
));
13111310
$view = $form->createView();
13121311

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
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\Form\Tests\Resources;
13+
14+
class TranslationFilesTest extends \PHPUnit_Framework_TestCase
15+
{
16+
/**
17+
* @dataProvider provideTranslationFiles
18+
*/
19+
public function testTranslationFileIsValid($filePath)
20+
{
21+
\PHPUnit_Util_XML::loadfile($filePath, false, false, true);
22+
}
23+
24+
public function provideTranslationFiles()
25+
{
26+
return array_map(
27+
function ($filePath) { return (array) $filePath; },
28+
glob(dirname(dirname(__DIR__)).'/Resources/translations/*.xlf')
29+
);
30+
}
31+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
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\Security\Tests\Resources;
13+
14+
class TranslationFilesTest extends \PHPUnit_Framework_TestCase
15+
{
16+
/**
17+
* @dataProvider provideTranslationFiles
18+
*/
19+
public function testTranslationFileIsValid($filePath)
20+
{
21+
\PHPUnit_Util_XML::loadfile($filePath, false, false, true);
22+
}
23+
24+
public function provideTranslationFiles()
25+
{
26+
return array_map(
27+
function ($filePath) { return (array) $filePath; },
28+
glob(dirname(dirname(__DIR__)).'/Resources/translations/*.xlf')
29+
);
30+
}
31+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
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\Validator\Tests\Resources;
13+
14+
class TranslationFilesTest extends \PHPUnit_Framework_TestCase
15+
{
16+
/**
17+
* @dataProvider provideTranslationFiles
18+
*/
19+
public function testTranslationFileIsValid($filePath)
20+
{
21+
\PHPUnit_Util_XML::loadfile($filePath, false, false, true);
22+
}
23+
24+
public function provideTranslationFiles()
25+
{
26+
return array_map(
27+
function ($filePath) { return (array) $filePath; },
28+
glob(dirname(dirname(__DIR__)).'/Resources/translations/*.xlf')
29+
);
30+
}
31+
}

0 commit comments

Comments
 (0)