Skip to content

Commit fda1d6d

Browse files
committed
Merge branch '2.8' into 3.0
* 2.8: [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 6782cfa + dcd4d2e commit fda1d6d

File tree

7 files changed

+133
-3
lines changed

7 files changed

+133
-3
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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,8 @@ public function testSingleChoiceExpandedWithPlaceholderWithoutTranslation()
818818
'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
819819
'multiple' => false,
820820
'expanded' => true,
821-
'translation_domain' => false,
821+
'required' => false,
822+
'choice_translation_domain' => false,
822823
'placeholder' => 'Placeholder&Not&Translated',
823824
));
824825

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -963,6 +963,7 @@ public function testSingleChoiceExpandedWithoutTranslation()
963963
'multiple' => false,
964964
'expanded' => true,
965965
'choice_translation_domain' => false,
966+
'placeholder' => 'Placeholder&Not&Translated',
966967
));
967968

968969
$this->assertWidgetMatchesXpath($form->createView(), array(),
@@ -1034,7 +1035,8 @@ public function testSingleChoiceExpandedWithPlaceholderWithoutTranslation()
10341035
'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
10351036
'multiple' => false,
10361037
'expanded' => true,
1037-
'translation_domain' => false,
1038+
'required' => false,
1039+
'choice_translation_domain' => false,
10381040
'placeholder' => 'Placeholder&Not&Translated',
10391041
));
10401042

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 <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\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 <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\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 <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\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)