Skip to content

Commit 992c0e8

Browse files
Merge branch '2.7' into 2.8
* 2.7: Update to PHPUnit namespaces remove translation data collector when not usable
2 parents 3ab89da + 56b84d9 commit 992c0e8

30 files changed

+186
-27
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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\Bundle\FrameworkBundle\DependencyInjection\Compiler;
13+
14+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
15+
use Symfony\Component\DependencyInjection\ContainerBuilder;
16+
17+
/**
18+
* @author Christian Flothmann <[email protected]>
19+
*/
20+
class DataCollectorTranslatorPass implements CompilerPassInterface
21+
{
22+
public function process(ContainerBuilder $container)
23+
{
24+
if (!$container->has('translator')) {
25+
return;
26+
}
27+
28+
$translatorClass = $container->findDefinition('translator')->getClass();
29+
30+
if (!is_subclass_of($translatorClass, 'Symfony\Component\Translation\TranslatorBagInterface')) {
31+
$container->removeDefinition('translator.data_collector');
32+
$container->removeDefinition('data_collector.translation');
33+
}
34+
}
35+
}

FrameworkBundle.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddConsoleCommandPass;
1717
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\FormPass;
1818
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\PropertyInfoPass;
19+
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\DataCollectorTranslatorPass;
1920
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TemplatingPass;
2021
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\RoutingResolverPass;
2122
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ProfilerPass;
@@ -92,6 +93,7 @@ public function build(ContainerBuilder $container)
9293
$container->addCompilerPass(new FragmentRendererPass(), PassConfig::TYPE_AFTER_REMOVING);
9394
$container->addCompilerPass(new SerializerPass());
9495
$container->addCompilerPass(new PropertyInfoPass());
96+
$container->addCompilerPass(new DataCollectorTranslatorPass());
9597

9698
if ($container->getParameter('kernel.debug')) {
9799
$container->addCompilerPass(new UnusedTagsPass(), PassConfig::TYPE_AFTER_REMOVING);

Test/KernelTestCase.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Test;
1313

14+
use PHPUnit\Framework\TestCase;
1415
use Symfony\Component\DependencyInjection\ResettableContainerInterface;
1516
use Symfony\Component\Finder\Finder;
1617
use Symfony\Component\HttpKernel\KernelInterface;
@@ -20,7 +21,7 @@
2021
*
2122
* @author Fabien Potencier <[email protected]>
2223
*/
23-
abstract class KernelTestCase extends \PHPUnit_Framework_TestCase
24+
abstract class KernelTestCase extends TestCase
2425
{
2526
protected static $class;
2627

Tests/Command/RouterDebugCommandTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Tests\Command;
1313

14+
use PHPUnit\Framework\TestCase;
1415
use Symfony\Component\Console\Application;
1516
use Symfony\Component\Console\Tester\CommandTester;
1617
use Symfony\Bundle\FrameworkBundle\Command\RouterDebugCommand;
1718
use Symfony\Component\Routing\Route;
1819
use Symfony\Component\Routing\RouteCollection;
1920

20-
class RouterDebugCommandTest extends \PHPUnit_Framework_TestCase
21+
class RouterDebugCommandTest extends TestCase
2122
{
2223
public function testDebugAllRoutes()
2324
{

Tests/Command/RouterMatchCommandTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Tests\Command;
1313

14+
use PHPUnit\Framework\TestCase;
1415
use Symfony\Component\Console\Application;
1516
use Symfony\Component\Console\Tester\CommandTester;
1617
use Symfony\Bundle\FrameworkBundle\Command\RouterMatchCommand;
@@ -19,7 +20,7 @@
1920
use Symfony\Component\Routing\RouteCollection;
2021
use Symfony\Component\Routing\RequestContext;
2122

22-
class RouterMatchCommandTest extends \PHPUnit_Framework_TestCase
23+
class RouterMatchCommandTest extends TestCase
2324
{
2425
public function testWithMatchPath()
2526
{

Tests/Command/TranslationDebugCommandTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Tests\Command;
1313

14+
use PHPUnit\Framework\TestCase;
1415
use Symfony\Component\Console\Application;
1516
use Symfony\Component\Console\Tester\CommandTester;
1617
use Symfony\Bundle\FrameworkBundle\Command\TranslationDebugCommand;
1718
use Symfony\Component\Filesystem\Filesystem;
1819

19-
class TranslationDebugCommandTest extends \PHPUnit_Framework_TestCase
20+
class TranslationDebugCommandTest extends TestCase
2021
{
2122
private $fs;
2223
private $translationDir;

Tests/Command/TranslationUpdateCommandTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Tests\Command;
1313

14+
use PHPUnit\Framework\TestCase;
1415
use Symfony\Component\Console\Application;
1516
use Symfony\Component\Console\Tester\CommandTester;
1617
use Symfony\Bundle\FrameworkBundle\Command\TranslationUpdateCommand;
1718
use Symfony\Component\Filesystem\Filesystem;
1819
use Symfony\Component\DependencyInjection;
1920
use Symfony\Component\HttpKernel;
2021

21-
class TranslationUpdateCommandTest extends \PHPUnit_Framework_TestCase
22+
class TranslationUpdateCommandTest extends TestCase
2223
{
2324
private $fs;
2425
private $translationDir;

Tests/Console/Descriptor/AbstractDescriptorTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Tests\Console\Descriptor;
1313

14+
use PHPUnit\Framework\TestCase;
1415
use Symfony\Component\Console\Input\ArrayInput;
1516
use Symfony\Component\Console\Output\BufferedOutput;
1617
use Symfony\Component\Console\Style\SymfonyStyle;
@@ -22,7 +23,7 @@
2223
use Symfony\Component\Routing\Route;
2324
use Symfony\Component\Routing\RouteCollection;
2425

25-
abstract class AbstractDescriptorTest extends \PHPUnit_Framework_TestCase
26+
abstract class AbstractDescriptorTest extends TestCase
2627
{
2728
/** @dataProvider getDescribeRouteCollectionTestData */
2829
public function testDescribeRouteCollection(RouteCollection $routes, $expectedDescription)

Tests/DependencyInjection/Compiler/AddCacheWarmerPassTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;
1313

14+
use PHPUnit\Framework\TestCase;
1415
use Symfony\Component\DependencyInjection\Reference;
1516
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddCacheWarmerPass;
1617

17-
class AddCacheWarmerPassTest extends \PHPUnit_Framework_TestCase
18+
class AddCacheWarmerPassTest extends TestCase
1819
{
1920
public function testThatCacheWarmersAreProcessedInPriorityOrder()
2021
{

Tests/DependencyInjection/Compiler/AddConsoleCommandPassTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;
1313

14+
use PHPUnit\Framework\TestCase;
1415
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddConsoleCommandPass;
1516
use Symfony\Component\Console\Command\Command;
1617
use Symfony\Component\DependencyInjection\ContainerBuilder;
1718
use Symfony\Component\DependencyInjection\Definition;
1819
use Symfony\Component\HttpKernel\Bundle\Bundle;
1920

20-
class AddConsoleCommandPassTest extends \PHPUnit_Framework_TestCase
21+
class AddConsoleCommandPassTest extends TestCase
2122
{
2223
public function testProcess()
2324
{

Tests/DependencyInjection/Compiler/AddConstraintValidatorsPassTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
* file that was distributed with this source code.
1010
*/
1111

12+
use PHPUnit\Framework\TestCase;
1213
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddConstraintValidatorsPass;
1314

14-
class AddConstraintValidatorsPassTest extends \PHPUnit_Framework_TestCase
15+
class AddConstraintValidatorsPassTest extends TestCase
1516
{
1617
public function testThatConstraintValidatorServicesAreProcessed()
1718
{

Tests/DependencyInjection/Compiler/AddExpressionLanguageProvidersPassTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;
1313

14+
use PHPUnit\Framework\TestCase;
1415
use Symfony\Component\DependencyInjection\ContainerBuilder;
1516
use Symfony\Component\DependencyInjection\Definition;
1617
use Symfony\Component\DependencyInjection\Reference;
1718
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddExpressionLanguageProvidersPass;
1819

19-
class AddExpressionLanguageProvidersPassTest extends \PHPUnit_Framework_TestCase
20+
class AddExpressionLanguageProvidersPassTest extends TestCase
2021
{
2122
public function testProcessForRouter()
2223
{
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;
13+
14+
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\DataCollectorTranslatorPass;
15+
use Symfony\Component\DependencyInjection\ContainerBuilder;
16+
use Symfony\Component\DependencyInjection\Reference;
17+
use Symfony\Component\Translation\TranslatorInterface;
18+
19+
class DataCollectorTranslatorPassTest extends \PHPUnit_Framework_TestCase
20+
{
21+
private $container;
22+
private $dataCollectorTranslatorPass;
23+
24+
protected function setUp()
25+
{
26+
$this->container = new ContainerBuilder();
27+
$this->dataCollectorTranslatorPass = new DataCollectorTranslatorPass();
28+
29+
$this->container->register('translator.data_collector', 'Symfony\Component\Translation\DataCollectorTranslator')
30+
->setPublic(false)
31+
->setDecoratedService('translator')
32+
->setArguments(array(new Reference('translator.data_collector.inner')))
33+
;
34+
35+
$this->container->register('data_collector.translation', 'Symfony\Component\Translation\DataCollector\TranslationDataCollector')
36+
->setArguments(array(new Reference('translator.data_collector')))
37+
;
38+
}
39+
40+
public function testProcessKeepsDataCollectorTranslatorIfItImplementsTranslatorBagInterface()
41+
{
42+
$this->container->register('translator', 'Symfony\Component\Translation\Translator');
43+
44+
$this->dataCollectorTranslatorPass->process($this->container);
45+
46+
$this->assertTrue($this->container->hasDefinition('translator.data_collector'));
47+
}
48+
49+
public function testProcessKeepsDataCollectorIfTranslatorImplementsTranslatorBagInterface()
50+
{
51+
$this->container->register('translator', 'Symfony\Component\Translation\Translator');
52+
53+
$this->dataCollectorTranslatorPass->process($this->container);
54+
55+
$this->assertTrue($this->container->hasDefinition('data_collector.translation'));
56+
}
57+
58+
public function testProcessRemovesDataCollectorTranslatorIfItDoesNotImplementTranslatorBagInterface()
59+
{
60+
$this->container->register('translator', 'Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler\TranslatorWithTranslatorBag');
61+
62+
$this->dataCollectorTranslatorPass->process($this->container);
63+
64+
$this->assertFalse($this->container->hasDefinition('translator.data_collector'));
65+
}
66+
67+
public function testProcessRemovesDataCollectorIfTranslatorDoesNotImplementTranslatorBagInterface()
68+
{
69+
$this->container->register('translator', 'Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler\TranslatorWithTranslatorBag');
70+
71+
$this->dataCollectorTranslatorPass->process($this->container);
72+
73+
$this->assertFalse($this->container->hasDefinition('data_collector.translation'));
74+
}
75+
}
76+
77+
class TranslatorWithTranslatorBag implements TranslatorInterface
78+
{
79+
public function trans($id, array $parameters = array(), $domain = null, $locale = null)
80+
{
81+
}
82+
83+
public function transChoice($id, $number, array $parameters = array(), $domain = null, $locale = null)
84+
{
85+
}
86+
87+
public function setLocale($locale)
88+
{
89+
}
90+
91+
public function getLocale()
92+
{
93+
}
94+
}

Tests/DependencyInjection/Compiler/LegacyFragmentRendererPassTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;
1313

14+
use PHPUnit\Framework\TestCase;
1415
use Symfony\Component\DependencyInjection\Reference;
1516
use Symfony\Component\HttpFoundation\Request;
1617
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\FragmentRendererPass;
1718

1819
/**
1920
* @group legacy
2021
*/
21-
class LegacyFragmentRendererPassTest extends \PHPUnit_Framework_TestCase
22+
class LegacyFragmentRendererPassTest extends TestCase
2223
{
2324
/**
2425
* Tests that content rendering not implementing FragmentRendererInterface

Tests/DependencyInjection/Compiler/LegacyTemplatingAssetHelperPassTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;
1313

14+
use PHPUnit\Framework\TestCase;
1415
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TemplatingAssetHelperPass;
1516
use Symfony\Component\DependencyInjection\ContainerBuilder;
1617
use Symfony\Component\DependencyInjection\Definition;
@@ -19,7 +20,7 @@
1920
/**
2021
* @group legacy
2122
*/
22-
class LegacyTemplatingAssetHelperPassTest extends \PHPUnit_Framework_TestCase
23+
class LegacyTemplatingAssetHelperPassTest extends TestCase
2324
{
2425
public function getScopesTests()
2526
{

Tests/DependencyInjection/Compiler/LoggingTranslatorPassTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;
1313

14+
use PHPUnit\Framework\TestCase;
1415
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\LoggingTranslatorPass;
1516

16-
class LoggingTranslatorPassTest extends \PHPUnit_Framework_TestCase
17+
class LoggingTranslatorPassTest extends TestCase
1718
{
1819
public function testProcess()
1920
{

Tests/DependencyInjection/Compiler/ProfilerPassTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;
1313

14+
use PHPUnit\Framework\TestCase;
1415
use Symfony\Component\DependencyInjection\Definition;
1516
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ProfilerPass;
1617

17-
class ProfilerPassTest extends \PHPUnit_Framework_TestCase
18+
class ProfilerPassTest extends TestCase
1819
{
1920
private $profilerDefinition;
2021

Tests/DependencyInjection/Compiler/SerializerPassTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;
1313

14+
use PHPUnit\Framework\TestCase;
1415
use Symfony\Component\DependencyInjection\Reference;
1516
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\SerializerPass;
1617

@@ -19,7 +20,7 @@
1920
*
2021
* @author Javier Lopez <[email protected]>
2122
*/
22-
class SerializerPassTest extends \PHPUnit_Framework_TestCase
23+
class SerializerPassTest extends TestCase
2324
{
2425
public function testThrowExceptionWhenNoNormalizers()
2526
{

Tests/DependencyInjection/Compiler/TranslatorPassTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;
1313

14+
use PHPUnit\Framework\TestCase;
1415
use Symfony\Component\DependencyInjection\Reference;
1516
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TranslatorPass;
1617

17-
class TranslatorPassTest extends \PHPUnit_Framework_TestCase
18+
class TranslatorPassTest extends TestCase
1819
{
1920
public function testValidCollector()
2021
{

0 commit comments

Comments
 (0)