Skip to content

Commit d4df6cf

Browse files
Merge branch '3.4' into 4.3
* 3.4: Minor fixes Use namespaced Phpunit classes [Form] remove leftover int child phpdoc Support DateTimeInterface in IntlDateFormatter::format [PhpUnitBridge] fixed PHPUnit 8.3 compatibility: method handleError was renamed to __invoke Use PHPunit assertion
2 parents 3a185e2 + b131278 commit d4df6cf

File tree

16 files changed

+75
-72
lines changed

16 files changed

+75
-72
lines changed

.php_cs.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ return PhpCsFixer\Config::create()
99
'@Symfony' => true,
1010
'@Symfony:risky' => true,
1111
'@PHPUnit75Migration:risky' => true,
12-
'php_unit_dedicate_assert' => ['target' => '3.5'],
12+
'php_unit_dedicate_assert' => ['target' => '5.6'],
1313
'phpdoc_no_empty_return' => false, // triggers almost always false positive
1414
'array_syntax' => ['syntax' => 'short'],
1515
'fopen_flags' => false,

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ install:
196196
git checkout -q FETCH_HEAD -- src/Symfony/Bridge/PhpUnit
197197
SYMFONY_VERSION=$(cat src/Symfony/Bridge/PhpUnit/composer.json | grep '^ *"dev-master". *"[1-9]' | grep -o '[0-9.]*')
198198
sed -i 's/"symfony\/phpunit-bridge": ".*"/"symfony\/phpunit-bridge": "'$SYMFONY_VERSION'.x@dev"/' composer.json
199+
rm -rf .phpunit
199200
fi
200201
201202
- |

src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Bridge\PhpUnit;
1313

14+
use PHPUnit\Framework\TestResult;
15+
use PHPUnit\Util\ErrorHandler;
1416
use Symfony\Bridge\PhpUnit\DeprecationErrorHandler\Configuration;
1517
use Symfony\Bridge\PhpUnit\DeprecationErrorHandler\Deprecation;
1618

@@ -49,6 +51,7 @@ class DeprecationErrorHandler
4951

5052
private static $isRegistered = false;
5153
private static $utilPrefix;
54+
private static $isAtLeastPhpUnit83;
5255

5356
/**
5457
* Registers and configures the deprecation handler.
@@ -73,14 +76,15 @@ public static function register($mode = 0)
7376
}
7477

7578
self::$utilPrefix = class_exists('PHPUnit_Util_ErrorHandler') ? 'PHPUnit_Util_' : 'PHPUnit\Util\\';
79+
self::$isAtLeastPhpUnit83 = method_exists('PHPUnit\Util\ErrorHandler', '__invoke');
7680

7781
$handler = new self();
7882
$oldErrorHandler = set_error_handler([$handler, 'handleError']);
7983

8084
if (null !== $oldErrorHandler) {
8185
restore_error_handler();
8286

83-
if ([self::$utilPrefix.'ErrorHandler', 'handleError'] === $oldErrorHandler) {
87+
if ($oldErrorHandler instanceof ErrorHandler || [self::$utilPrefix.'ErrorHandler', 'handleError'] === $oldErrorHandler) {
8488
restore_error_handler();
8589
self::register($mode);
8690
}
@@ -100,12 +104,7 @@ public static function collectDeprecations($outputFile)
100104
return $previousErrorHandler($type, $msg, $file, $line, $context);
101105
}
102106

103-
static $autoload = true;
104-
105-
$ErrorHandler = class_exists('PHPUnit_Util_ErrorHandler', $autoload) ? 'PHPUnit_Util_ErrorHandler' : 'PHPUnit\Util\ErrorHandler';
106-
$autoload = false;
107-
108-
return $ErrorHandler::handleError($type, $msg, $file, $line, $context);
107+
return \call_user_func(self::getPhpUnitErrorHandler(), $type, $msg, $file, $line, $context);
109108
}
110109

111110
$deprecations[] = [error_reporting(), $msg, $file];
@@ -122,9 +121,7 @@ public static function collectDeprecations($outputFile)
122121
public function handleError($type, $msg, $file, $line, $context = [])
123122
{
124123
if ((E_USER_DEPRECATED !== $type && E_DEPRECATED !== $type) || !$this->getConfiguration()->isEnabled()) {
125-
$ErrorHandler = self::$utilPrefix.'ErrorHandler';
126-
127-
return $ErrorHandler::handleError($type, $msg, $file, $line, $context);
124+
return \call_user_func(self::getPhpUnitErrorHandler(), $type, $msg, $file, $line, $context);
128125
}
129126

130127
$deprecation = new Deprecation($msg, debug_backtrace(), $file);
@@ -319,6 +316,26 @@ private function displayDeprecations($groups, $configuration)
319316
}
320317
}
321318

319+
private static function getPhpUnitErrorHandler()
320+
{
321+
if (!self::$isAtLeastPhpUnit83) {
322+
return (class_exists('PHPUnit_Util_ErrorHandler', false) ? 'PHPUnit_Util_' : 'PHPUnit\Util\\').'ErrorHandler::handleError';
323+
}
324+
325+
foreach (debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT | DEBUG_BACKTRACE_IGNORE_ARGS) as $frame) {
326+
if (isset($frame['object']) && $frame['object'] instanceof TestResult) {
327+
return new ErrorHandler(
328+
$frame['object']->getConvertDeprecationsToExceptions(),
329+
$frame['object']->getConvertErrorsToExceptions(),
330+
$frame['object']->getConvertNoticesToExceptions(),
331+
$frame['object']->getConvertWarningsToExceptions()
332+
);
333+
}
334+
}
335+
336+
return function () { return false; };
337+
}
338+
322339
/**
323340
* Returns true if STDOUT is defined and supports colorization.
324341
*

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ public function testProcessForAutoconfiguredCalls()
233233
public function testProcessThrowsExceptionForArguments()
234234
{
235235
$this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException');
236-
$this->expectExceptionMessage('Autoconfigured instanceof for type "PHPUnit\Framework\TestCase" defines arguments but these are not supported and should be removed.');
236+
$this->expectExceptionMessageRegExp('/Autoconfigured instanceof for type "PHPUnit[\\\\_]Framework[\\\\_]TestCase" defines arguments but these are not supported and should be removed\./');
237237
$container = new ContainerBuilder();
238238
$container->registerForAutoconfiguration(parent::class)
239239
->addArgument('bar');

src/Symfony/Component/DependencyInjection/Tests/Config/ContainerParametersResourceCheckerTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\DependencyInjection\Tests\Config;
1313

14+
use PHPUnit\Framework\MockObject\MockObject;
1415
use PHPUnit\Framework\TestCase;
1516
use Symfony\Component\Config\ResourceCheckerInterface;
1617
use Symfony\Component\DependencyInjection\Config\ContainerParametersResource;
@@ -52,15 +53,15 @@ public function testIsFresh(callable $mockContainer, $expected)
5253

5354
public function isFreshProvider()
5455
{
55-
yield 'not fresh on missing parameter' => [function (\PHPUnit\Framework\MockObject\MockObject $container) {
56+
yield 'not fresh on missing parameter' => [function (MockObject $container) {
5657
$container->method('hasParameter')->with('locales')->willReturn(false);
5758
}, false];
5859

59-
yield 'not fresh on different value' => [function (\PHPUnit\Framework\MockObject\MockObject $container) {
60+
yield 'not fresh on different value' => [function (MockObject $container) {
6061
$container->method('getParameter')->with('locales')->willReturn(['nl', 'es']);
6162
}, false];
6263

63-
yield 'fresh on every identical parameters' => [function (\PHPUnit\Framework\MockObject\MockObject $container) {
64+
yield 'fresh on every identical parameters' => [function (MockObject $container) {
6465
$container->expects($this->exactly(2))->method('hasParameter')->willReturn(true);
6566
$container->expects($this->exactly(2))->method('getParameter')
6667
->withConsecutive(

src/Symfony/Component/Filesystem/Tests/FilesystemTest.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public function testCopyCreatesTargetDirectoryIfItDoesNotExist()
153153

154154
$this->filesystem->copy($sourceFilePath, $targetFilePath);
155155

156-
$this->assertTrue(is_dir($targetFileDirectory));
156+
$this->assertDirectoryExists($targetFileDirectory);
157157
$this->assertFileExists($targetFilePath);
158158
$this->assertStringEqualsFile($targetFilePath, 'SOURCE FILE');
159159
}
@@ -185,7 +185,7 @@ public function testMkdirCreatesDirectoriesRecursively()
185185

186186
$this->filesystem->mkdir($directory);
187187

188-
$this->assertTrue(is_dir($directory));
188+
$this->assertDirectoryExists($directory);
189189
}
190190

191191
public function testMkdirCreatesDirectoriesFromArray()
@@ -197,9 +197,9 @@ public function testMkdirCreatesDirectoriesFromArray()
197197

198198
$this->filesystem->mkdir($directories);
199199

200-
$this->assertTrue(is_dir($basePath.'1'));
201-
$this->assertTrue(is_dir($basePath.'2'));
202-
$this->assertTrue(is_dir($basePath.'3'));
200+
$this->assertDirectoryExists($basePath.'1');
201+
$this->assertDirectoryExists($basePath.'2');
202+
$this->assertDirectoryExists($basePath.'3');
203203
}
204204

205205
public function testMkdirCreatesDirectoriesFromTraversableObject()
@@ -211,9 +211,9 @@ public function testMkdirCreatesDirectoriesFromTraversableObject()
211211

212212
$this->filesystem->mkdir($directories);
213213

214-
$this->assertTrue(is_dir($basePath.'1'));
215-
$this->assertTrue(is_dir($basePath.'2'));
216-
$this->assertTrue(is_dir($basePath.'3'));
214+
$this->assertDirectoryExists($basePath.'1');
215+
$this->assertDirectoryExists($basePath.'2');
216+
$this->assertDirectoryExists($basePath.'3');
217217
}
218218

219219
public function testMkdirCreatesDirectoriesFails()
@@ -347,7 +347,7 @@ public function testRemoveCleansInvalidLinks()
347347

348348
// create symlink to dir using trailing forward slash
349349
$this->filesystem->symlink($basePath.'dir/', $basePath.'dir-link');
350-
$this->assertTrue(is_dir($basePath.'dir-link'));
350+
$this->assertDirectoryExists($basePath.'dir-link');
351351

352352
// create symlink to nonexistent dir
353353
rmdir($basePath.'dir');
@@ -821,7 +821,7 @@ public function testRemoveSymlink()
821821

822822
$this->assertFalse(is_link($link));
823823
$this->assertFalse(is_file($link));
824-
$this->assertFalse(is_dir($link));
824+
$this->assertDirectoryNotExists($link);
825825
}
826826

827827
public function testSymlinkIsOverwrittenIfPointsToDifferentTarget()
@@ -1150,8 +1150,8 @@ public function testMirrorCopiesFilesAndDirectoriesRecursively()
11501150

11511151
$this->filesystem->mirror($sourcePath, $targetPath);
11521152

1153-
$this->assertTrue(is_dir($targetPath));
1154-
$this->assertTrue(is_dir($targetPath.'directory'));
1153+
$this->assertDirectoryExists($targetPath);
1154+
$this->assertDirectoryExists($targetPath.'directory');
11551155
$this->assertFileEquals($file1, $targetPath.'directory'.\DIRECTORY_SEPARATOR.'file1');
11561156
$this->assertFileEquals($file2, $targetPath.'file2');
11571157

@@ -1184,7 +1184,7 @@ public function testMirrorCreatesEmptyDirectory()
11841184

11851185
$this->filesystem->mirror($sourcePath, $targetPath);
11861186

1187-
$this->assertTrue(is_dir($targetPath));
1187+
$this->assertDirectoryExists($targetPath);
11881188

11891189
$this->filesystem->remove($sourcePath);
11901190
}
@@ -1203,7 +1203,7 @@ public function testMirrorCopiesLinks()
12031203

12041204
$this->filesystem->mirror($sourcePath, $targetPath);
12051205

1206-
$this->assertTrue(is_dir($targetPath));
1206+
$this->assertDirectoryExists($targetPath);
12071207
$this->assertFileEquals($sourcePath.'file1', $targetPath.'link1');
12081208
$this->assertTrue(is_link($targetPath.\DIRECTORY_SEPARATOR.'link1'));
12091209
}
@@ -1223,7 +1223,7 @@ public function testMirrorCopiesLinkedDirectoryContents()
12231223

12241224
$this->filesystem->mirror($sourcePath, $targetPath);
12251225

1226-
$this->assertTrue(is_dir($targetPath));
1226+
$this->assertDirectoryExists($targetPath);
12271227
$this->assertFileEquals($sourcePath.'/nested/file1.txt', $targetPath.'link1/file1.txt');
12281228
$this->assertTrue(is_link($targetPath.\DIRECTORY_SEPARATOR.'link1'));
12291229
}
@@ -1247,7 +1247,7 @@ public function testMirrorCopiesRelativeLinkedContents()
12471247

12481248
$this->filesystem->mirror($sourcePath, $targetPath);
12491249

1250-
$this->assertTrue(is_dir($targetPath));
1250+
$this->assertDirectoryExists($targetPath);
12511251
$this->assertFileEquals($sourcePath.'/nested/file1.txt', $targetPath.'link1/file1.txt');
12521252
$this->assertTrue(is_link($targetPath.\DIRECTORY_SEPARATOR.'link1'));
12531253
$this->assertEquals('\\' === \DIRECTORY_SEPARATOR ? realpath($sourcePath.'\nested') : 'nested', readlink($targetPath.\DIRECTORY_SEPARATOR.'link1'));
@@ -1270,7 +1270,7 @@ public function testMirrorContentsWithSameNameAsSourceOrTargetWithoutDeleteOptio
12701270

12711271
chdir($oldPath);
12721272

1273-
$this->assertTrue(is_dir($targetPath));
1273+
$this->assertDirectoryExists($targetPath);
12741274
$this->assertFileExists($targetPath.'source');
12751275
$this->assertFileExists($targetPath.'target');
12761276
}
@@ -1295,7 +1295,7 @@ public function testMirrorContentsWithSameNameAsSourceOrTargetWithDeleteOption()
12951295

12961296
chdir($oldPath);
12971297

1298-
$this->assertTrue(is_dir($targetPath));
1298+
$this->assertDirectoryExists($targetPath);
12991299
$this->assertFileExists($targetPath.'source');
13001300
$this->assertFileNotExists($targetPath.'target');
13011301
}

src/Symfony/Component/Finder/Tests/FinderTest.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,11 +1365,7 @@ public function testAccessDeniedException()
13651365
} catch (\Exception $e) {
13661366
$expectedExceptionClass = 'Symfony\\Component\\Finder\\Exception\\AccessDeniedException';
13671367
if ($e instanceof \PHPUnit\Framework\ExpectationFailedException) {
1368-
$this->fail(sprintf("Expected exception:\n%s\nGot:\n%s\nWith comparison failure:\n%s", $expectedExceptionClass, 'PHPUnit_Framework_ExpectationFailedException', $e->getComparisonFailure()->getExpectedAsString()));
1369-
}
1370-
1371-
if ($e instanceof \PHPUnit\Framework\ExpectationFailedException) {
1372-
$this->fail(sprintf("Expected exception:\n%s\nGot:\n%s\nWith comparison failure:\n%s", $expectedExceptionClass, '\PHPUnit\Framework\ExpectationFailedException', $e->getComparisonFailure()->getExpectedAsString()));
1368+
$this->fail(sprintf("Expected exception:\n%s\nGot:\n%s\nWith comparison failure:\n%s", $expectedExceptionClass, 'PHPUnit\Framework\ExpectationFailedException', $e->getComparisonFailure()->getExpectedAsString()));
13731369
}
13741370

13751371
$this->assertInstanceOf($expectedExceptionClass, $e);

src/Symfony/Component/Form/Button.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ class Button implements \IteratorAggregate, FormInterface
3838

3939
/**
4040
* Creates a new button from a form configuration.
41-
*
42-
* @param FormConfigInterface $config The button's configuration
4341
*/
4442
public function __construct(FormConfigInterface $config)
4543
{
@@ -128,10 +126,6 @@ public function getParent()
128126
*
129127
* This method should not be invoked.
130128
*
131-
* @param int|string|FormInterface $child
132-
* @param null $type
133-
* @param array $options
134-
*
135129
* @throws BadMethodCallException
136130
*/
137131
public function add($child, $type = null, array $options = [])

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/NativeFileSessionHandlerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function testConstructSavePath($savePath, $expectedSavePath, $path)
4242
{
4343
$handler = new NativeFileSessionHandler($savePath);
4444
$this->assertEquals($expectedSavePath, ini_get('session.save_path'));
45-
$this->assertTrue(is_dir(realpath($path)));
45+
$this->assertDirectoryExists(realpath($path));
4646

4747
rmdir($path);
4848
}

src/Symfony/Component/HttpKernel/Tests/DependencyInjection/RemoveEmptyControllerArgumentLocatorsPassTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function testProcess()
2626
$resolver = $container->register('argument_resolver.service')->addArgument([]);
2727

2828
$container->register('stdClass', 'stdClass');
29-
$container->register(parent::class, 'stdClass');
29+
$container->register(TestCase::class, 'stdClass');
3030
$container->register('c1', RemoveTestController1::class)->addTag('controller.service_arguments');
3131
$container->register('c2', RemoveTestController2::class)->addTag('controller.service_arguments')
3232
->addMethodCall('setTestCase', [new Reference('c1')]);

0 commit comments

Comments
 (0)