8000 Merge branch '4.4' · symfony/symfony@fe11c99 · GitHub
[go: up one dir, main page]

Skip to content

Commit fe11c99

Browse files
Merge branch '4.4'
* 4.4: cs fix Replace calls to setExpectedException by Pollyfill
2 parents c7bade2 + 57725de commit fe11c99

File tree

59 files changed

+231
-260
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+231
-260
lines changed

src/Symfony/Bridge/Doctrine/Tests/Security/User/EntityUserProviderTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@
1717
use Symfony\Bridge\Doctrine\Security\User\EntityUserProvider;
1818
use Symfony\Bridge\Doctrine\Test\DoctrineTestHelper;
1919
use Symfony\Bridge\Doctrine\Tests\Fixtures\User;
20+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
2021

2122
class EntityUserProviderTest extends TestCase
2223
{
24+
use ForwardCompatTestTrait;
25+
2326
public function testRefreshUserGetsUserByPrimaryKey()
2427
{
2528
$em = DoctrineTestHelper::createTestEntityManager();
@@ -106,10 +109,8 @@ public function testRefreshUserRequiresId()
106109
$user1 = new User(null, null, 'user1');
107110
$provider = new EntityUserProvider($this->getManager($em), 'Symfony\Bridge\Doctrine\Tests\Fixtures\User', 'name');
108111

109-
$this->expectException(
110-
'InvalidArgumentException',
111-
'You cannot refresh a user from the EntityUserProvider that does not contain an identifier. The user object has to be serialized with its own identifier mapped by Doctrine'
112-
);
112+
$this->expectException('InvalidArgumentException');
113+
$this->expectExceptionMessage('You cannot refresh a user from the EntityUserProvider that does not contain an identifier. The user object has to be serialized with its own identifier mapped by Doctrine');
113114
$provider->refreshUser($user1);
114115
}
115116

@@ -126,10 +127,9 @@ public function testRefreshInvalidUser()
126127
$provider = new EntityUserProvider($this->getManager($em), 'Symfony\Bridge\Doctrine\Tests\Fixtures\User', 'name');
127128

128129
$user2 = new User(1, 2, 'user2');
129-
$this->expectException(
130-
'Symfony\Component\Security\Core\Exception\UsernameNotFoundException',
131-
'User with id {"id1":1,"id2":2} not found'
132-
);
130+
$this->expectException('Symfony\Component\Security\Core\Exception\UsernameNotFoundException');
131+
$this->expectExceptionMessage('User with id {"id1":1,"id2":2} not found');
132+
133133
$provider->refreshUser($user2);
134134
}
135135

src/Symfony/Bridge/PhpUnit/Legacy/ForwardCompatTestTraitForV7.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ protected function createMock($originalClassName): MockObject
3030
->disableOriginalClone()
3131
->disableArgumentCloning()
3232
->disallowMockingUnknownTypes()
33-
->getMock();
33+
->getMock();
3434
}
3535
}

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Symfony\Bridge\PhpUnit\Tests;
44

55
use PHPUnit\Framework\TestCase;
6+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
67

78
/**
89
* Don't remove this test case, it tests the legacy group.
@@ -13,6 +14,8 @@
1314
*/
1415
class ProcessIsolationTest extends TestCase
1516
{
17+
use ForwardCompatTestTrait;
18+
1619
/**
1720
* @expectedDeprecation Test abc
1821
*/
@@ -25,12 +28,8 @@ public function testIsolation()
2528
public function testCallingOtherErrorHandler()
2629
{
2730
$class = class_exists('PHPUnit\Framework\Exception') ? 'PHPUnit\Framework\Exception' : 'PHPUnit_Framework_Exception';
28-
if (method_exists($this, 'expectException')) {
29-
$this->expectException($class);
30-
$this->expectExceptionMessage('Test that PHPUnit\'s error handler fires.');
31-
} else {
32-
$this->setExpectedException($class, 'Test that PHPUnit\'s error handler fires.');
33-
}
31+
$this->expectException($class);
32+
$this->expectExceptionMessage('Test that PHPUnit\'s error handler fires.');
3433

3534
trigger_error('Test that PHPUnit\'s error handler fires.', E_USER_WARNING);
3635
}

src/Symfony/Bridge/Twig/Tests/Extension/HttpKernelExtensionTest.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bridge\Twig\Tests\Extension;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
1516
use Symfony\Bridge\Twig\Extension\HttpKernelExtension;
1617
use Symfony\Bridge\Twig\Extension\HttpKernelRuntime;
1718
use Symfony\Component\HttpFoundation\Request;
@@ -22,6 +23,8 @@
2223

2324
class HttpKernelExtensionTest extends TestCase
2425
{
26+
use ForwardCompatTestTrait;
27+
2528
/**
2629
* @expectedException \Twig\Error\RuntimeError
2730
*/
@@ -49,12 +52,8 @@ public function testUnknownFragmentRenderer()
4952
;
5053
$renderer = new FragmentHandler($context);
5154

52-
if (method_exists($this, 'expectException')) {
53-
$this->expectException('InvalidArgumentException');
54-
$this->expectExceptionMessage('The "inline" renderer does not exist.');
55-
} else {
56-
$this->setExpectedException('InvalidArgumentException', 'The "inline" renderer does not exist.');
57-
}
55+
$this->expectException('InvalidArgumentException');
56+
$this->expectExceptionMessage('The "inline" renderer does not exist.');
5857

5958
$renderer->render('/foo');
6059
}

src/Symfony/Bundle/FrameworkBundle/Tests/Command/CachePoolDeleteCommandTest.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,7 @@ public function testCommandDeleteFailed()
7676
->with('bar')
7777
->willReturn(false);
7878

79-
if (method_exists($this, 'expectExceptionMessage')) {
80-
$this->expectExceptionMessage('Cache item "bar" could not be deleted.');
81-
} else {
82-
$this->setExpectedException('Exception', 'Cache item "bar" could not be deleted.');
83-
}
79+
$this->expectExceptionMessage('Cache item "bar" could not be deleted.');
8480

8581
$tester = $this->getCommandTester($this->getKernel());
8682
$tester->execute(['pool' => 'foo', 'key' => 'bar']);

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Doctrine\DBAL\Connection;
1515
use PHPUnit\Framework\TestCase;
16+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
1617
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Configuration;
1718
use Symfony\Bundle\FullStack;
1819
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
@@ -24,6 +25,8 @@
2425

2526
class ConfigurationTest extends TestCase
2627
{
28+
use ForwardCompatTestTrait;
29+
2730
public function testDefaultConfig()
2831
{
2932
$processor = new Processor();
@@ -124,12 +127,8 @@ public function provideValidAssetsPackageNameConfigurationTests()
124127
*/
125128
public function testInvalidAssetsConfiguration(array $assetConfig, $expectedMessage)
126129
{
127-
if (method_exists($this, 'expectException')) {
128-
$this->expectException(InvalidConfigurationException::class);
129-
$this->expectExceptionMessage($expectedMessage);
130-
} else {
131-
$this->setExpectedException(InvalidConfigurationException::class, $expectedMessage);
132-
}
130+
$this->expectException(InvalidConfigurationException::class);
131+
$this->expectExceptionMessage($expectedMessage);
133132

134133
$processor = new Processor();
135134
$configuration = new Configuration(true);
@@ -178,12 +177,8 @@ public function provideInvalidAssetConfigurationTests()
178177
public function testItShowANiceMessageIfTwoMessengerBusesAreConfiguredButNoDefaultBus()
179178
{
180179
$expectedMessage = 'You must specify the "default_bus" if you define more than one bus.';
181-
if (method_exists($this, 'expectException')) {
182-
$this->expectException(InvalidConfigurationException::class);
183-
$this->expectExceptionMessage($expectedMessage);
184-
} else {
185-
$this->setExpectedException(InvalidConfigurationException::class, $expectedMessage);
186-
}
180+
$this->expectException(InvalidConfigurationException::class);
181+
$this->expectExceptionMessage($expectedMessage);
187182
$processor = new Processor();
188183
$configuration = new Configuration(true);
189184

src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Compiler/AddSecurityVotersPassTest.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bundle\SecurityBundle\Tests\DependencyInjection\Compiler;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
1516
use Symfony\Bundle\SecurityBundle\DependencyInjection\Compiler\AddSecurityVotersPass;
1617
use Symfony\Component\DependencyInjection\ContainerBuilder;
1718
use Symfony\Component\DependencyInjection\Definition;
@@ -21,6 +22,8 @@
2122

2223
class AddSecurityVotersPassTest extends TestCase
2324
{
25+
use ForwardCompatTestTrait;
26+
2427
/**
2528
* @expectedException \Symfony\Component\DependencyInjection\Exception\LogicException
2629
* @expectedExceptionMessage No security voters found. You need to tag at least one with "security.voter".
@@ -128,12 +131,14 @@ public function testThatVotersAreNotTraceableWithoutDebugMode(): void
128131
$this->assertFalse($container->has('debug.security.voter.voter2'), 'voter2 should not be traced');
129132
}
130133

131-
/**
132-
* @expectedException \Symfony\Component\DependencyInjection\Exception\LogicException
133-
* @expectedExceptionMessage stdClass must implement the Symfony\Component\Security\Core\Authorization\Voter\VoterInterface when used as a voter.
134-
*/
135134
public function testVoterMissingInterface()
136135
{
136+
$exception = LogicException::class;
137+
$message = 'stdClass must implement the Symfony\Component\Security\Core\Authorization\Voter\VoterInterface when used as a voter.';
138+
139+
$this->expectException($exception);
140+
$this->expectExceptionMessage($message);
141+
137142
$container = new ContainerBuilder();
138143
$container->setParameter('kernel.debug', false);
139144
$container

src/Symfony/Bundle/SecurityBundle/Tests/Functional/UserPasswordEncoderCommandTest.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,8 @@ public function testEncodePasswordSodiumOutput()
169169

170170
public function testEncodePasswordNoConfigForGivenUserClass()
171171
{
172-
if (method_exists($this, 'expectException')) {
173-
$this->expectException('\RuntimeException');
174-
$this->expectExceptionMessage('No encoder has been configured for account "Foo\Bar\User".');
175-
} else {
176-
$this->setExpectedException('\RuntimeException', 'No encoder has been configured for account "Foo\Bar\User".');
177-
}
172+
$this->expectException('\RuntimeException');
173+
$this->expectExceptionMessage('No encoder has been configured for account "Foo\Bar\User".');
178174

179175
$this->passwordEncoderCommandTester->execute([
180176
'command' => 'security:encode-password',

src/Symfony/Component/BrowserKit/Tests/CookieTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@
1212
namespace Symfony\Component\BrowserKit\Tests;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
1516
use Symfony\Component\BrowserKit\Cookie;
1617

1718
class CookieTest extends TestCase
1819
{
20+
use ForwardCompatTestTrait;
21+
1922
public function testToString()
2023
{
2124
$cookie = new Cookie('foo', 'bar', strtotime('Fri, 20-May-2011 15:25:52 GMT'), '/', '.myfoodomain.com', true);

src/Symfony/Component/Config/Tests/Definition/ArrayNodeTest.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@
1212
namespace Symfony\Component\Config\Tests\Definition;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
1516
use Symfony\Component\Config\Definition\ArrayNode;
1617
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
1718
use Symfony\Component\Config\Definition\ScalarNode;
1819

1920
class ArrayNodeTest extends TestCase
2021
{
22+
use ForwardCompatTestTrait;
23+
2124
/**
2225
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidTypeException
2326
*/
@@ -80,12 +83,8 @@ public function ignoreAndRemoveMatrixProvider()
8083
public function testIgnoreAndRemoveBehaviors($ignore, $remove, $expected, $message = '')
8184
{
8285
if ($expected instanceof \Exception) {
83-
if (method_exists($this, 'expectException')) {
84-
$this->expectException(\get_class($expected));
85-
$this->expectExceptionMessage($expected->getMessage());
86-
} else {
87-
$this->setExpectedException(\get_class($expected), $expected->getMessage());
88-
}
86+
$this->expectException(\get_class($expected));
87+
$this->expectExceptionMessage($expected->getMessage());
8988
}
9089
$node = new ArrayNode('root');
9190
$node->setIgnoreExtraKeys($ignore, $remove);

src/Symfony/Component/Config/Tests/Definition/ScalarNodeTest.php

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@
1212
namespace Symfony\Component\Config\Tests\Definition;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
1516
use Symfony\Component\Config\Definition\ArrayNode;
1617
use Symfony\Component\Config\Definition\ScalarNode;
1718

1819
class ScalarNodeTest extends TestCase
1920
{
21+
use ForwardCompatTestTrait;
22+
2023
/**
2124
* @dataProvider getValidValues
2225
*/
@@ -95,12 +98,8 @@ public function testNormalizeThrowsExceptionWithoutHint()
9598
{
9699
$node = new ScalarNode('test');
97100

98-
if (method_exists($this, 'expectException')) {
99-
$this->expectException('Symfony\Component\Config\Definition\Exception\InvalidTypeException');
100-
$this->expectExceptionMessage('Invalid type for path "test". Expected scalar, but got array.');
101-
} else {
102-
$this->setExpectedException('Symfony\Component\Config\Definition\Exception\InvalidTypeException', 'Invalid type for path "test". Expected scalar, but got array.');
103-
}
101+
$this->expectException('Symfony\Component\Config\Definition\Exception\InvalidTypeException');
102+
$this->expectExceptionMessage('Invalid type for path "test". Expected scalar, but got array.');
104103

105104
$node->normalize([]);
106105
}
@@ -110,12 +109,8 @@ public function testNormalizeThrowsExceptionWithErrorMessage()
110109
$node = new ScalarNode('test');
111110
$node->setInfo('"the test value"');
112111

113-
if (method_exists($this, 'expectException')) {
114-
$this->expectException('Symfony\Component\Config\Definition\Exception\InvalidTypeException');
115-
$this->expectExceptionMessage("Invalid type for path \"test\". Expected scalar, but got array.\nHint: \"the test value\"");
116-
} else {
117-
$this->setExpectedException('Symfony\Component\Config\Definition\Exception\InvalidTypeException', "Invalid type for path \"test\". Expected scalar, but got array.\nHint: \"the test value\"");
118-
}
112+
$this->expectException('Symfony\Component\Config\Definition\Exception\InvalidTypeException');
113+
$this->expectExceptionMessage("Invalid type for path \"test\". Expected scalar, but got array.\nHint: \"the test value\"");
119114

120115
$node->normalize([]);
121116
}

src/Symfony/Component/Config/Tests/Util/XmlUtilsTest.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@
1212
namespace Symfony\Component\Config\Tests\Util;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
1516
use Symfony\Component\Config\Util\XmlUtils;
1617

1718
class XmlUtilsTest extends TestCase
1819
{
20+
use ForwardCompatTestTrait;
21+
1922
public function testLoadFile()
2023
{
2124
$fixtures = __DIR__.'/../Fixtures/Util/';
@@ -166,12 +169,8 @@ public function testLoadEmptyXmlFile()
166169
{
167170
$file = __DIR__.'/../Fixtures/foo.xml';
168171

169-
if (method_exists($this, 'expectException')) {
170-
$this->expectException('InvalidArgumentException');
171-
$this->expectExceptionMessage(sprintf('File %s does not contain valid XML, it is empty.', $file));
172-
} else {
173-
$this->setExpectedException('InvalidArgumentException', sprintf('File %s does not contain valid XML, it is empty.', $file));
174-
}
172+
$this->expectException('InvalidArgumentException');
173+
$this->expectExceptionMessage(sprintf('File %s does not contain valid XML, it is empty.', $file));
175174

176175
XmlUtils::loadFile($file);
177176
}

src/Symfony/Component/Console/Tests/ApplicationTest.php

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -316,12 +316,8 @@ public function testFindAmbiguousNamespace()
316316

317317
$expectedMsg = "The namespace \"f\" is ambiguous.\nDid you mean one of these?\n foo\n foo1";
318318

319-
if (method_exists($this, 'expectException')) {
320-
$this->expectException(NamespaceNotFoundException::class);
321-
$this->expectExceptionMessage($expectedMsg);
322-
} else {
323-
$this->setExpectedException(NamespaceNotFoundException::class, $expectedMsg);
324-
}
319+
$this->expectException(NamespaceNotFoundException::class);
320+
$this->expectExceptionMessage($expectedMsg);
325321

326322
$application->findNamespace('f');
327323
}
@@ -425,12 +421,8 @@ public function testFindWithCommandLoader()
425421
public function testFindWithAmbiguousAbbreviations($abbreviation, $expectedExceptionMessage)
426422
{
427423
putenv('COLUMNS=120');
428-
if (method_exists($this, 'expectException')) {
429-
$this->expectException('Symfony\Component\Console\Exception\CommandNotFoundException');
430-
$this->expectExceptionMessage($expectedExceptionMessage);
431-
} else {
432-
$this->setExpectedException('Symfony\Component\Console\Exception\CommandNotFoundException', $expectedExceptionMessage);
433-
}
424+
$this->expectException('Symfony\Component\Console\Exception\CommandNotFoundException');
425+
$this->expectExceptionMessage($expectedExceptionMessage);
434426

435427
$application = new Application();
436428
$application->add(new \FooCommand());

src/Symfony/Component/Console/Tests/Command/CommandTest.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,8 @@ public function testGetNamespaceGetNameSetName()
120120
*/
121121
public function testInvalidCommandNames($name)
122122
{
123-
if (method_exists($this, 'expectException')) {
124-
$this->expectException('InvalidArgumentException');
125-
$this->expectExceptionMessage(sprintf('Command name "%s" is invalid.', $name));
126-
} else {
127-
$this->setExpectedException('InvalidArgumentException', sprintf('Command name "%s" is invalid.', $name));
128-
}
123+
$this->expectException('InvalidArgumentException');
124+
$this->expectExceptionMessage(sprintf('Command name "%s" is invalid.', $name));
129125

130126
$command = new \TestCommand();
131127
$command->setName($name);

0 commit comments

Comments
 (0)
0