8000 Merge branch '3.4' into 4.0 · symfony/symfony@8faf29f · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8faf29f

Browse files
Merge branch '3.4' into 4.0
* 3.4: [Serializer] optims and cleanup do not mock the container builder in tests [PhpUnitBridge] Added support for PHPUnit 7 in Coverage Listener fix accessing request values Avoid running the remove command without any packages [Form] Add translations for Tagalog
2 parents bc21af2 + 4ccf8bc commit 8faf29f

File tree

33 files changed

+401
-482
lines changed

33 files changed

+401
-482
lines changed

src/Symfony/Bridge/PhpUnit/CoverageListener.php

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,10 @@
1111

1212
namespace Symfony\Bridge\PhpUnit;
1313

14-
use PHPUnit\Framework\BaseTestListener;
15-
use PHPUnit\Framework\Test;
16-
use Symfony\Bridge\PhpUnit\Legacy\CoverageListenerTrait;
17-
1814
if (class_exists('PHPUnit_Runner_Version') && version_compare(\PHPUnit_Runner_Version::id(), '6.0.0', '<')) {
19-
class_alias('Symfony\Bridge\PhpUnit\Legacy\CoverageListener', 'Symfony\Bridge\PhpUnit\CoverageListener');
20-
// Using an early return instead of a else does not work when using the PHPUnit
21-
// phar due to some weird PHP behavior (the class gets defined without executing
22-
// the code before it and so the definition is not properly conditional)
15+
class_alias('Symfony\Bridge\PhpUnit\Legacy\CoverageListenerForV5', 'Symfony\Bridge\PhpUnit\CoverageListener');
16+
} elseif (version_compare(\PHPUnit\Runner\Version::id(), '7.0.0', '<')) {
17+
class_alias('Symfony\Bridge\PhpUnit\Legacy\CoverageListenerForV6', 'Symfony\Bridge\PhpUnit\CoverageListener');
2318
} else {
24-
/**
25-
* CoverageListener adds `@covers <className>` on each test suite when possible
26-
* to make the code coverage more accurate.
27-
*
28-
* @author Grégoire Pineau <lyrixx@lyrixx.info>
29-
*/
30-
class CoverageListener extends BaseTestListener
31-
{
32-
private $trait;
33-
34-
public function __construct(callable $sutFqcnResolver = null, $warningOnSutNotFound = false)
35-
{
36-
$this->trait = new CoverageListenerTrait($sutFqcnResolver, $warningOnSutNotFound);
37-
}
38-
39-
public function startTest(Test $test)
40-
{
41-
$this->trait->startTest($test);
42-
}
43-
}
19+
class_alias('Symfony\Bridge\PhpUnit\Legacy\CoverageListenerForV7', 'Symfony\Bridge\PhpUnit\CoverageListener');
4420
}

src/Symfony/Bridge/PhpUnit/Legacy/CoverageListener.php renamed to src/Symfony/Bridge/PhpUnit/Legacy/CoverageListenerForV5.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*
2020
* @internal
2121
*/
22-
class CoverageListener extends \PHPUnit_Framework_BaseTestListener
22+
class CoverageListenerForV5 extends \PHPUnit_Framework_BaseTestListener
2323
{
2424
private $trait;
2525

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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\Bridge\PhpUnit\Legacy;
13+
14+
use PHPUnit\Framework\BaseTestListener;
15+
use PHPUnit\Framework\Test;
16+
17+
/**
18+
* CoverageListener adds `@covers <className>` on each test suite when possible
19+
* to make the code coverage more accurate.
20+
*
21+
* @author Grégoire Pineau <lyrixx@lyrixx.info>
22+
*
23+
* @internal
24+
*/
25+
class CoverageListenerForV6 extends BaseTestListener
26+
{
27+
private $trait;
28+
29+
public function __construct(callable $sutFqcnResolver = null, $warningOnSutNotFound = false)
30+
{
31+
$this->trait = new CoverageListenerTrait($sutFqcnResolver, $warningOnSutNotFound);
32+
}
33+
34+
public function startTest(Test $test)
35+
{
36+
$this->trait->startTest($test);
37+
}
38+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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\Bridge\PhpUnit\Legacy;
13+
14+
use PHPUnit\Framework\TestListener;
15+
use PHPUnit\Framework\TestListenerDefaultImplementation;
16+
use PHPUnit\Framework\TestSuite;
17+
18+
/**
19+
* CoverageListener adds `@covers <className>` on each test suite when possible
20+
* to make the code coverage more accurate.
21+
*
22+
* @author Grégoire Pineau <lyrixx@lyrixx.info>
23+
*
24+
* @internal
25+
*/
26+
class CoverageListenerForV7 implements TestListener
27+
{
28+
use TestListenerDefaultImplementation;
29+
30+
private $trait;
31+
32+
public function __construct(callable $sutFqcnResolver = null, $warningOnSutNotFound = false)
33+
{
34+
$this->trait = new CoverageListenerTrait($sutFqcnResolver, $warningOnSutNotFound);
35+
}
36+
37+
public function startTestSuite(TestSuite $suite): void
38+
{
39+
$this->trait->startTest($test);
40+
}
41+
}

src/Symfony/Bridge/PhpUnit/Tests/CoverageListenerTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ public function test()
1212
$this->markTestSkipped('This test cannot be run on Windows.');
1313
}
1414

15-
if (\PHP_VERSION_ID >= 70000) {
15+
exec('type phpdbg', $output, $returnCode);
16+
17+
if (\PHP_VERSION_ID >= 70000 && 0 === $returnCode) {
1618
$php = 'phpdbg -qrr';
1719
} else {
1820
exec('php --ri xdebug -d zend_extension=xdebug.so 2> /dev/null', $output, $returnCode);

src/Symfony/Bridge/PhpUnit/Tests/Fixtures/coverage/tests/bootstrap.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@
1313
require __DIR__.'/../src/FooCov.php';
1414

1515
require __DIR__.'/../../../../Legacy/CoverageListenerTrait.php';
16+
1617
if (class_exists('PHPUnit_Runner_Version') && version_compare(\PHPUnit_Runner_Version::id(), '6.0.0', '<')) {
17-
require __DIR__.'/../../../../Legacy/CoverageListener.php';
18+
require_once __DIR__.'/../../../../Legacy/CoverageListenerForV5.php';
19+
} elseif (version_compare(\PHPUnit\Runner\Version::id(), '7.0.0', '<')) {
20+
require_once __DIR__.'/../../../../Legacy/CoverageListenerForV6.php';
21+
} else {
22+
require_once __DIR__.'/../../../../Legacy/CoverageListenerForV7.php';
1823
}
24+
1925
require __DIR__.'/../../../../CoverageListener.php';

src/Symfony/Bridge/PhpUnit/bin/simple-phpunit

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ if (!file_exists("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit") || md5_file(__
7777
$zip->extractTo(getcwd());
7878
$zip->close();
7979
chdir("phpunit-$PHPUNIT_VERSION");
80-
passthru("$COMPOSER remove --no-update ".$SYMFONY_PHPUNIT_REMOVE);
80+
if ($SYMFONY_PHPUNIT_REMOVE) {
81+
passthru("$COMPOSER remove --no-update ".$SYMFONY_PHPUNIT_REMOVE);
82+
}
8183
if (5.1 <= $PHPUNIT_VERSION && $PHPUNIT_VERSION < 5.4) {
8284
passthru("$COMPOSER require --no-update phpunit/phpunit-mock-objects \"~3.1.0\"");
8385
}

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/CachePoolPrunerPassTest.php

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,27 +44,17 @@ public function testCompilerPassReplacesCommandArgument()
4444

4545
public function testCompilePassIsIgnoredIfCommandDoesNotExist()
4646
{
47-
$container = $this
48-
->getMockBuilder(ContainerBuilder::class)
49-
->setMethods(array('hasDefinition', 'getDefinition', 'findTaggedServiceIds'))
50-
->getMock();
51-
52-
$container
53-
->expects($this->atLeastOnce())
54-
->method('hasDefinition')
55-
->with(CachePoolPruneCommand::class)
56-
->will($this->returnValue(false));
57-
58-
$container
59-
->expects($this->never())
60-
->method('getDefinition');
47+
$container = new ContainerBuilder();
6148

62-
$container
63-
->expects($this->never())
64-
->method('findTaggedServiceIds');
49+
$definitionsBefore = count($container->getDefinitions());
50+
$aliasesBefore = count($container->getAliases());
6551

6652
$pass = new CachePoolPrunerPass();
6753
$pass->process($container);
54+
55+
// the container is untouched (i.e. no new definitions or aliases)
56+
$this->assertCount($definitionsBefore, $container->getDefinitions());
57+
$this->assertCount($aliasesBefore, $container->getAliases());
6858
}
6959

7060
/**

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/LoggingTranslatorPassTest.php

Lines changed: 41 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -13,96 +13,69 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\LoggingTranslatorPass;
16+
use Symfony\Component\DependencyInjection\ContainerBuilder;
17+
use Symfony\Component\DependencyInjection\Reference;
1618

1719
class LoggingTranslatorPassTest extends TestCase
1820
{
1921
public function testProcess()
2022
{
21-
$definition = $this->getMockBuilder('Symfony\Component\DependencyInjection\Definition')->getMock();
22-
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->getMock();
23-
$parameterBag = $this->getMockBuilder('Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface')->getMock();
24-
25-
$container->expects($this->exactly(2))
26-
->method('hasAlias')
27-
->will($this->returnValue(true));
28-
29-
$container->expects($this->once())
30-
->method('getParameter')
31-
->will($this->returnValue(true));
32-
33-
$container->expects($this->once())
34-
->method('getAlias')
35-
->will($this->returnValue('translation.default'));
36-
37-
$container->expects($this->exactly(3))
38-
->method('getDefinition')
39-
->will($this->returnValue($definition));
40-
41-
$container->expects($this->once())
42-
->method('hasParameter')
43-
->with('translator.logging')
44-
->will($this->returnValue(true));
45-
46-
$definition->expects($this->once())
47-
->method('getClass')
48-
->will($this->returnValue('Symfony\Bundle\FrameworkBundle\Translation\Translator'));
49-
50-
$parameterBag->expects($this->once())
51-
->method('resolveValue')
52-
->will($this->returnValue("Symfony\Bundle\FrameworkBundle\Translation\Translator"));
53-
54-
$container->expects($this->once())
55-
->method('getParameterBag')
56-
->will($this->returnValue($parameterBag));
57-
58-
$container->expects($this->once())
59-
->method('getReflectionClass')
60-
->with('Symfony\Bundle\FrameworkBundle\Translation\Translator')
61-
->will($this->returnValue(new \ReflectionClass('Symfony\Bundle\FrameworkBundle\Translation\Translator')));
62-
63-
$definition->expects($this->once())
64-
->method('getTag')
65-
->with('container.service_subscriber')
66-
->willReturn(array(array('id' => 'translator'), array('id' => 'foo')));
67-
68-
$definition->expects($this->once())
69-
->method('clearTag')
70-
->with('container.service_subscriber');
71-
72-
$definition->expects($this->any())
73-
->method('addTag')
74-
->withConsecutive(
75-
array('container.service_subscriber', array('id' => 'foo')),
76-
array('container.service_subscriber', array('key' => 'translator', 'id' => 'translator.logging.inner'))
77-
);
23+
$container = new ContainerBuilder();
24+
$container->setParameter('translator.logging', true);
25+
$container->setParameter('translator.class', 'Symfony\Component\Translation\Translator');
26+
$container->register('monolog.logger');
27+
$container->setAlias('logger', 'monolog.logger');
28+
$container->register('translator.default', '%translator.class%');
29+
$container->register('translator.logging', '%translator.class%');
30+
$container->setAlias('translator', 'translator.default');
31+
$translationWarmerDefinition = $container->register('translation.warmer')
32+
->addArgument(new Reference('translator'))
33+
->addTag('container.service_subscriber', array('id' => 'translator'))
34+
->addTag('container.service_subscriber', array('id' => 'foo'));
7835

7936
$pass = new LoggingTranslatorPass();
8037
$pass->process($container);
38+
39+
$this->assertEquals(
40+
array('container.service_subscriber' => array(
41+
array('id' => 'foo'),
42+
array('key' => 'translator', 'id' => 'translator.logging.inner'),
43+
)),
44+
$translationWarmerDefinition->getTags()
45+
);
8146
}
8247

8348
public function testThatCompilerPassIsIgnoredIfThereIsNotLoggerDefinition()
8449
{
85-
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->getMock();
86-
$container->expects($this->once())
87-
->method('hasAlias')
88-
->will($this->returnValue(false));
50+
$container = new ContainerBuilder();
51+
$container->register('identity_translator');
52+
$container->setAlias('translator', 'identity_translator');
53+
54+
$definitionsBefore = count($container->getDefinitions());
55+
$aliasesBefore = count($container->getAliases());
8956

9057
$pass = new LoggingTranslatorPass();
9158
$pass->process($container);
59+
60+
// the container is untouched (i.e. no new definitions or aliases)
61+
$this->assertCount($definitionsBefore, $container->getDefinitions());
62+
$this->assertCount($aliasesBefore, $container->getAliases());
9263
}
9364

9465
public function testThatCompilerPassIsIgnoredIfThereIsNotTranslatorDefinition()
9566
{
96-
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->getMock();
97-
$container->expects($this->at(0))
98-
->method('hasAlias')
99-
->will($this->returnValue(true));
67+
$container = new ContainerBuilder();
68+
$container->register('monolog.logger');
69+
$container->setAlias('logger', 'monolog.logger');
10070

101-
$container->expects($this->at(0))
102-
->method('hasAlias')
103-
->will($this->returnValue(false));
71+
$definitionsBefore = count($container->getDefinitions());
72+
$aliasesBefore = count($container->getAliases());
10473

10574
$pass = new LoggingTranslatorPass();
10675
$pass->process($container);
76+
77+
// the container is untouched (i.e. no new definitions or aliases)
78+
$this->assertCount($definitionsBefore, $container->getDefinitions());
79+
$this->assertCount($aliasesBefore, $container->getAliases());
10780
}
10881
}

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/UnusedTagsPassTest.php

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,22 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\UnusedTagsPass;
16+
use Symfony\Component\DependencyInjection\ContainerBuilder;
1617

1718
class UnusedTagsPassTest extends TestCase
1819
{
1920
public function testProcess()
2021
{
2122
$pass = new UnusedTagsPass();
2223

23-
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('findTaggedServiceIds', 'findUnusedTags', 'findTags', 'log'))->getMock();
24-
$container->expects($this->once())
25-
->method('log')
26-
->with($pass, 'Tag "kenrel.event_subscriber" was defined on service(s) "foo", "bar", but was never used. Did you mean "kernel.event_subscriber"?');
27-
$container->expects($this->once())
28-
->method('findTags')
29-
->will($this->returnValue(array('kenrel.event_subscriber')));
30-
$container->expects($this->once())
31-
->method('findUnusedTags')
32-
->will($this->returnValue(array('kenrel.event_subscriber', 'form.type')));
33-
$container->expects($this->once())
34-
->method('findTaggedServiceIds')
35-
->with('kenrel.event_subscriber')
36-
->will($this->returnValue(array(
37-
'foo' => array(),
38-
'bar' => array(),
39-
)));
24+
$container = new ContainerBuilder();
25+
$container->register('foo')
26+
->addTag('kenrel.event_subscriber');
27+
$container->register('bar')
28+
->addTag('kenrel.event_subscriber');
4029

4130
$pass->process($container);
31+
32+
$this->assertSame(array(sprintf('%s: Tag "kenrel.event_subscriber" was defined on service(s) "foo", "bar", but was never used. Did you mean "kernel.event_subscriber"?', UnusedTagsPass::class)), $container->getCompiler()->getLog());
4233
}
4334
}

src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Compiler/TwigLoaderPassTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace Symfony\Bundle\TwigBundle\Tests\DependencyInjection\Compiler;
1313

1414
use PHPUnit\Framework\TestCase;
15-
use Symfony\Component\DependencyInjection\Alias;
1615
use Symfony\Component\DependencyInjection\ContainerBuilder;
1716
use Symfony\Component\DependencyInjection\Definition;
1817
use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\TwigLoaderPass;

0 commit comments

Comments
 (0)
0