From e28e3d130b80e7dd7001bb01df681d1a1189ef6e Mon Sep 17 00:00:00 2001 From: Guillaume Aveline <917449+joky@users.noreply.github.com> Date: Tue, 21 Nov 2017 09:21:36 +0100 Subject: [PATCH 01/16] [Bridge/PhpUnit] Remove trailing "\n" from ClockMock::microtime(false) --- ClockMock.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ClockMock.php b/ClockMock.php index fe5cd851..8bfb9a62 100644 --- a/ClockMock.php +++ b/ClockMock.php @@ -66,7 +66,7 @@ public static function microtime($asFloat = false) return self::$now; } - return sprintf("%0.6f %d\n", self::$now - (int) self::$now, (int) self::$now); + return sprintf('%0.6f %d', self::$now - (int) self::$now, (int) self::$now); } public static function register($class) From 7df91891266c83259dad175f8cbdef84094874e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Sun, 31 Dec 2017 13:09:44 +0100 Subject: [PATCH 02/16] Update LICENSE year... forever --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 207646a0..29f72d5e 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2014-2017 Fabien Potencier +Copyright (c) 2014-present Fabien Potencier Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From cebc0e70c3b1b29aafdfa35bcd6f3192a997e4f6 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 3 Jan 2018 08:23:28 +0100 Subject: [PATCH 03/16] fixed years in copyright --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 29f72d5e..15fc1c88 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2014-present Fabien Potencier +Copyright (c) 2014-2018 Fabien Potencier Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From 33524c36b71a02a6c85de7cbb6665afc4298915a Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 11 Jan 2018 10:49:26 +0100 Subject: [PATCH 04/16] minor #25752 Don't right trim the deprecation message (alexpott) This PR was submitted for the 3.4 branch but it was squashed and merged into the 3.3 branch instead (closes #25752). Discussion ---------- Don't right trim the deprecation message | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | maybe yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #... | License | MIT | Doc PR | symfony/symfony-docs#... The PhpUnit bridge lists deprecation messages after a test. In order to do this it outputs the message but it right trims the message - removing any fullstops. This is unexpected. It does this to add the number of time the message appears but this is not really necessary because the number of the times a deprecation message is triggered and from where is added below. Commits ------- 0b03631 Don't right trim the deprecation message --- DeprecationErrorHandler.php | 2 +- Tests/DeprecationErrorHandler/default.phpt | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/DeprecationErrorHandler.php b/DeprecationErrorHandler.php index 66b8762c..dae47591 100644 --- a/DeprecationErrorHandler.php +++ b/DeprecationErrorHandler.php @@ -134,7 +134,7 @@ public static function register($mode = false) uasort($deprecations[$group], $cmp); foreach ($deprecations[$group] as $msg => $notices) { - echo "\n", rtrim($msg, '.'), ': ', $notices['count'], "x\n"; + echo "\n ", $notices['count'], 'x: ', $msg, "\n"; arsort($notices); diff --git a/Tests/DeprecationErrorHandler/default.phpt b/Tests/DeprecationErrorHandler/default.phpt index cd733724..39a3e985 100644 --- a/Tests/DeprecationErrorHandler/default.phpt +++ b/Tests/DeprecationErrorHandler/default.phpt @@ -63,20 +63,20 @@ $foo->testNonLegacyBar(); --EXPECTF-- Unsilenced deprecation notices (3) -unsilenced foo deprecation: 2x + 2x: unsilenced foo deprecation 2x in FooTestCase::testLegacyFoo -unsilenced bar deprecation: 1x + 1x: unsilenced bar deprecation 1x in FooTestCase::testNonLegacyBar Remaining deprecation notices (1) -silenced bar deprecation: 1x + 1x: silenced bar deprecation 1x in FooTestCase::testNonLegacyBar Legacy deprecation notices (1) Other deprecation notices (1) -root deprecation: 1x + 1x: root deprecation From 65e296736cffcb0e2b52cf7cb8ee51427b34aa71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=9D=A6=E7=B1=B3?= Date: Tue, 30 Jan 2018 23:53:25 +0800 Subject: [PATCH 05/16] support sapi_windows_vt100_support for php 7.2+ --- DeprecationErrorHandler.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/DeprecationErrorHandler.php b/DeprecationErrorHandler.php index dae47591..f73690db 100644 --- a/DeprecationErrorHandler.php +++ b/DeprecationErrorHandler.php @@ -161,7 +161,8 @@ private static function hasColorSupport() { if ('\\' === DIRECTORY_SEPARATOR) { return - '10.0.10586' === PHP_WINDOWS_VERSION_MAJOR.'.'.PHP_WINDOWS_VERSION_MINOR.'.'.PHP_WINDOWS_VERSION_BUILD + defined('STDOUT') && function_exists('sapi_windows_vt100_support') && sapi_windows_vt100_support(STDOUT) + || '10.0.10586' === PHP_WINDOWS_VERSION_MAJOR.'.'.PHP_WINDOWS_VERSION_MINOR.'.'.PHP_WINDOWS_VERSION_BUILD || false !== getenv('ANSICON') || 'ON' === getenv('ConEmuANSI') || 'xterm' === getenv('TERM'); From 575971e061ab2cc0f39b1acf36ffd1e7b27d5700 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Thu, 1 Feb 2018 23:45:44 +0100 Subject: [PATCH 06/16] [Bridge\PhpUnit] Exit as late as possible People might want to register other shutdown functions that should be able to control the exit code themselves, without the deprecation error handler taking over. The php manual says: > If you call exit() within one registered shutdown function, processing > will stop completely and no other registered shutdown functions will be > called. See https://secure.php.net/manual/en/function.register-shutdown-function.php --- DeprecationErrorHandler.php | 53 +++++++---- Tests/DeprecationErrorHandler/default.phpt | 5 + .../shutdown_deprecations.phpt | 91 +++++++++++++++++++ 3 files changed, 133 insertions(+), 16 deletions(-) create mode 100644 Tests/DeprecationErrorHandler/shutdown_deprecations.phpt diff --git a/DeprecationErrorHandler.php b/DeprecationErrorHandler.php index f73690db..b0f241c8 100644 --- a/DeprecationErrorHandler.php +++ b/DeprecationErrorHandler.php @@ -127,32 +127,53 @@ public static function register($mode = false) return $b['count'] - $a['count']; }; - foreach (array('unsilenced', 'remaining', 'legacy', 'other') as $group) { - if ($deprecations[$group.'Count']) { - echo "\n", $colorize(sprintf('%s deprecation notices (%d)', ucfirst($group), $deprecations[$group.'Count']), 'legacy' !== $group), "\n"; + $displayDeprecations = function ($deprecations) use ($colorize, $cmp) { + foreach (array('unsilenced', 'remaining', 'legacy', 'other') as $group) { + if ($deprecations[$group.'Count']) { + echo "\n", $colorize(sprintf('%s deprecation notices (%d)', ucfirst($group), $deprecations[$group.'Count']), 'legacy' !== $group), "\n"; - uasort($deprecations[$group], $cmp); + uasort($deprecations[$group], $cmp); - foreach ($deprecations[$group] as $msg => $notices) { - echo "\n ", $notices['count'], 'x: ', $msg, "\n"; + foreach ($deprecations[$group] as $msg => $notices) { + echo "\n ", $notices['count'], 'x: ', $msg, "\n"; - arsort($notices); + arsort($notices); - foreach ($notices as $method => $count) { - if ('count' !== $method) { - echo ' ', $count, 'x in ', preg_replace('/(.*)\\\\(.*?::.*?)$/', '$2 from $1', $method), "\n"; + foreach ($notices as $method => $count) { + if ('count' !== $method) { + echo ' ', $count, 'x in ', preg_replace('/(.*)\\\\(.*?::.*?)$/', '$2 from $1', $method), "\n"; + } } } } } - } - if (!empty($notices)) { - echo "\n"; - } + if (!empty($notices)) { + echo "\n"; + } + }; + + $displayDeprecations($deprecations); - if ('weak' !== $mode && ($deprecations['unsilenced'] || $deprecations['remaining'] || $deprecations['other'])) { - exit(1); + // store failing status + $isFailing = 'weak' !== $mode && ($deprecations['unsilenced'] || $deprecations['remaining'] || $deprecations['other']); + + // reset deprecations array + foreach ($deprecations as $group => $arrayOrInt) { + $deprecations[$group] = is_int($arrayOrInt) ? 0 : array(); } + + register_shutdown_function(function () use (&$deprecations, $isFailing, $displayDeprecations, $mode) { + foreach ($deprecations as $group => $arrayOrInt) { + if (0 < (is_int($arrayOrInt) ? $arrayOrInt : count($arrayOrInt))) { + echo "Shutdown-time deprecations:\n"; + break; + } + } + $displayDeprecations($deprecations); + if ($isFailing || 'weak' !== $mode && ($deprecations['unsilenced'] || $deprecations['remaining'] || $deprecations['other'])) { + exit(1); + } + }); }); } } diff --git a/Tests/DeprecationErrorHandler/default.phpt b/Tests/DeprecationErrorHandler/default.phpt index 39a3e985..7a0595a7 100644 --- a/Tests/DeprecationErrorHandler/default.phpt +++ b/Tests/DeprecationErrorHandler/default.phpt @@ -59,6 +59,10 @@ $foo = new FooTestCase(); $foo->testLegacyFoo(); $foo->testNonLegacyBar(); +register_shutdown_function(function () { + exit('I get precedence over any exit statements inside the deprecation error handler.'); +}); + ?> --EXPECTF-- Unsilenced deprecation notices (3) @@ -80,3 +84,4 @@ Other deprecation notices (1) 1x: root deprecation +I get precedence over any exit statements inside the deprecation error handler. diff --git a/Tests/DeprecationErrorHandler/shutdown_deprecations.phpt b/Tests/DeprecationErrorHandler/shutdown_deprecations.phpt new file mode 100644 index 00000000..fddeed60 --- /dev/null +++ b/Tests/DeprecationErrorHandler/shutdown_deprecations.phpt @@ -0,0 +1,91 @@ +--TEST-- +Test DeprecationErrorHandler in default mode +--FILE-- +testLegacyFoo(); +$foo->testNonLegacyBar(); + +register_shutdown_function(function () { + @trigger_error('root deprecation during shutdown', E_USER_DEPRECATED); +}); + +?> +--EXPECTF-- +Unsilenced deprecation notices (3) + + 2x: unsilenced foo deprecation + 2x in FooTestCase::testLegacyFoo + + 1x: unsilenced bar deprecation + 1x in FooTestCase::testNonLegacyBar + +Remaining deprecation notices (1) + + 1x: silenced bar deprecation + 1x in FooTestCase::testNonLegacyBar + +Legacy deprecation notices (1) + +Other deprecation notices (1) + + 1x: root deprecation + +Shutdown-time deprecations: + +Other deprecation notices (1) + + 1x: root deprecation during shutdown From 6542484e4706e58ed380abf195958e2cb8063708 Mon Sep 17 00:00:00 2001 From: johnstevenson Date: Thu, 12 Apr 2018 21:07:25 +0100 Subject: [PATCH 07/16] Use new PHP7.2 functions in hasColorSupport --- DeprecationErrorHandler.php | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/DeprecationErrorHandler.php b/DeprecationErrorHandler.php index b0f241c8..2b5c734c 100644 --- a/DeprecationErrorHandler.php +++ b/DeprecationErrorHandler.php @@ -178,17 +178,38 @@ public static function register($mode = false) } } + /** + * Returns true if STDOUT is defined and supports colorization. + * + * Reference: Composer\XdebugHandler\Process::supportsColor + * https://github.com/composer/xdebug-handler + * + * @return bool + */ private static function hasColorSupport() { - if ('\\' === DIRECTORY_SEPARATOR) { - return - defined('STDOUT') && function_exists('sapi_windows_vt100_support') && sapi_windows_vt100_support(STDOUT) - || '10.0.10586' === PHP_WINDOWS_VERSION_MAJOR.'.'.PHP_WINDOWS_VERSION_MINOR.'.'.PHP_WINDOWS_VERSION_BUILD + if (!defined('STDOUT')) { + return false; + } + + if (DIRECTORY_SEPARATOR === '\\') { + return (function_exists('sapi_windows_vt100_support') + && sapi_windows_vt100_support(STDOUT)) || false !== getenv('ANSICON') || 'ON' === getenv('ConEmuANSI') || 'xterm' === getenv('TERM'); } - return defined('STDOUT') && function_exists('posix_isatty') && @posix_isatty(STDOUT); + if (function_exists('stream_isatty')) { + return stream_isatty(STDOUT); + } + + if (function_exists('posix_isatty')) { + return posix_isatty(STDOUT); + } + + $stat = fstat(STDOUT); + // Check if formatted mode is S_IFCHR + return $stat ? 0020000 === ($stat['mode'] & 0170000) : false; } } From 15489d248fde3a16ff2470eb0a2375f072ae2129 Mon Sep 17 00:00:00 2001 From: AzJezz Date: Sun, 1 Jul 2018 16:55:08 +0200 Subject: [PATCH 08/16] Add color support for Hyper terminal . --- DeprecationErrorHandler.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/DeprecationErrorHandler.php b/DeprecationErrorHandler.php index 0290a69f..57751d73 100644 --- a/DeprecationErrorHandler.php +++ b/DeprecationErrorHandler.php @@ -231,7 +231,8 @@ private static function hasColorSupport() && sapi_windows_vt100_support(STDOUT)) || false !== getenv('ANSICON') || 'ON' === getenv('ConEmuANSI') - || 'xterm' === getenv('TERM'); + || 'xterm' === getenv('TERM') + || 'Hyper' === getenv('TERM_PROGRAM'); } if (function_exists('stream_isatty')) { From 93a9a78dcf65d64c6f5c110105240e3c960403a3 Mon Sep 17 00:00:00 2001 From: Saif Eddin Gmati Date: Tue, 3 Jul 2018 17:28:18 +0200 Subject: [PATCH 09/16] Check for Hyper terminal on all operating systems. --- DeprecationErrorHandler.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/DeprecationErrorHandler.php b/DeprecationErrorHandler.php index 57751d73..d1440bb1 100644 --- a/DeprecationErrorHandler.php +++ b/DeprecationErrorHandler.php @@ -226,13 +226,16 @@ private static function hasColorSupport() return false; } + if ('Hyper' === getenv('TERM_PROGRAM')) { + return true; + } + if (DIRECTORY_SEPARATOR === '\\') { return (function_exists('sapi_windows_vt100_support') && sapi_windows_vt100_support(STDOUT)) || false !== getenv('ANSICON') || 'ON' === getenv('ConEmuANSI') - || 'xterm' === getenv('TERM') - || 'Hyper' === getenv('TERM_PROGRAM'); + || 'xterm' === getenv('TERM'); } if (function_exists('stream_isatty')) { From fe3fca1bac6cb481c137f7a8caae6a8ce66a0b16 Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Thu, 5 Jul 2018 13:24:53 +0200 Subject: [PATCH 10/16] Enable the fixer enforcing fully-qualified calls for compiler-optimized functions --- ClockMock.php | 4 ++-- DeprecationErrorHandler.php | 20 ++++++++++---------- TextUI/Command.php | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/ClockMock.php b/ClockMock.php index 8bfb9a62..5cd3531d 100644 --- a/ClockMock.php +++ b/ClockMock.php @@ -71,7 +71,7 @@ public static function microtime($asFloat = false) public static function register($class) { - $self = get_called_class(); + $self = \get_called_class(); $mockedNs = array(substr($class, 0, strrpos($class, '\\'))); if (strpos($class, '\\Tests\\')) { @@ -79,7 +79,7 @@ public static function register($class) $mockedNs[] = substr($ns, 0, strrpos($ns, '\\')); } foreach ($mockedNs as $ns) { - if (function_exists($ns.'\time')) { + if (\function_exists($ns.'\time')) { continue; } eval(<<setAccessible(true); - $r->setValue($e, array_slice($trace, 1, $i)); + $r->setValue($e, \array_slice($trace, 1, $i)); echo "\n".ucfirst($group).' deprecation triggered by '.$class.'::'.$method.':'; echo "\n".$msg; @@ -193,12 +193,12 @@ public static function register($mode = 0) // reset deprecations array foreach ($deprecations as $group => $arrayOrInt) { - $deprecations[$group] = is_int($arrayOrInt) ? 0 : array(); + $deprecations[$group] = \is_int($arrayOrInt) ? 0 : array(); } register_shutdown_function(function () use (&$deprecations, $isFailing, $displayDeprecations, $mode) { foreach ($deprecations as $group => $arrayOrInt) { - if (0 < (is_int($arrayOrInt) ? $arrayOrInt : count($arrayOrInt))) { + if (0 < (\is_int($arrayOrInt) ? $arrayOrInt : \count($arrayOrInt))) { echo "Shutdown-time deprecations:\n"; break; } @@ -222,7 +222,7 @@ public static function register($mode = 0) */ private static function hasColorSupport() { - if (!defined('STDOUT')) { + if (!\defined('STDOUT')) { return false; } @@ -231,18 +231,18 @@ private static function hasColorSupport() } if (DIRECTORY_SEPARATOR === '\\') { - return (function_exists('sapi_windows_vt100_support') + return (\function_exists('sapi_windows_vt100_support') && sapi_windows_vt100_support(STDOUT)) || false !== getenv('ANSICON') || 'ON' === getenv('ConEmuANSI') || 'xterm' === getenv('TERM'); } - if (function_exists('stream_isatty')) { + if (\function_exists('stream_isatty')) { return stream_isatty(STDOUT); } - if (function_exists('posix_isatty')) { + if (\function_exists('posix_isatty')) { return posix_isatty(STDOUT); } diff --git a/TextUI/Command.php b/TextUI/Command.php index 7f218af9..82d6ab32 100644 --- a/TextUI/Command.php +++ b/TextUI/Command.php @@ -38,7 +38,7 @@ protected function handleBootstrap($filename) // By default, we want PHPUnit's autoloader before Symfony's one if (!getenv('SYMFONY_PHPUNIT_OVERLOAD')) { $filename = realpath(stream_resolve_include_path($filename)); - $symfonyLoader = realpath(dirname(PHPUNIT_COMPOSER_INSTALL).'/../../../vendor/autoload.php'); + $symfonyLoader = realpath(\dirname(PHPUNIT_COMPOSER_INSTALL).'/../../../vendor/autoload.php'); if ($filename === $symfonyLoader) { $symfonyLoader = require $symfonyLoader; From 85c95412dd60855542256d4c40992062f37912cf Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 26 Jul 2018 13:13:39 +0200 Subject: [PATCH 11/16] Enable native_constant_invocation CS fixer --- DeprecationErrorHandler.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DeprecationErrorHandler.php b/DeprecationErrorHandler.php index aff7c5b9..5f59dbe5 100644 --- a/DeprecationErrorHandler.php +++ b/DeprecationErrorHandler.php @@ -106,7 +106,7 @@ public static function register($mode = 0) echo "\n".ucfirst($group).' deprecation triggered by '.$class.'::'.$method.':'; echo "\n".$msg; echo "\nStack trace:"; - echo "\n".str_replace(' '.getcwd().DIRECTORY_SEPARATOR, ' ', $e->getTraceAsString()); + echo "\n".str_replace(' '.getcwd().\DIRECTORY_SEPARATOR, ' ', $e->getTraceAsString()); echo "\n"; exit(1); @@ -230,7 +230,7 @@ private static function hasColorSupport() return true; } - if (DIRECTORY_SEPARATOR === '\\') { + if (\DIRECTORY_SEPARATOR === '\\') { return (\function_exists('sapi_windows_vt100_support') && sapi_windows_vt100_support(STDOUT)) || false !== getenv('ANSICON') From a1295ca6e2a7f2d8ced9e0dd70900d7a64d9474b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Tue, 18 Sep 2018 23:04:50 +0200 Subject: [PATCH 12/16] Provide debug_backtrace with proper args This would fail if we were using strict mode with php 7, because true is only a valid argument for php < 5.3.6. This was changed from PHP_VERSION_ID >= 50400 ? DEBUG_BACKTRACE_IGNORE_ARGS | DEBUG_BACKTRACE_PROVIDE_OBJECT : true in #18272, but I do not understand why it was simplified, nor why DEBUG_BACKTRACE_IGNORE_ARGS was there at that time. --- DeprecationErrorHandler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DeprecationErrorHandler.php b/DeprecationErrorHandler.php index 5f59dbe5..f95d1389 100644 --- a/DeprecationErrorHandler.php +++ b/DeprecationErrorHandler.php @@ -72,7 +72,7 @@ public static function register($mode = 0) } $mode = $getMode(); - $trace = debug_backtrace(true); + $trace = debug_backtrace(); $group = 'other'; $i = \count($trace); From 270bb46276574359e9d2380b593fe06bccbb862b Mon Sep 17 00:00:00 2001 From: Albert Casdemont Date: Thu, 12 Jul 2018 14:04:46 +0200 Subject: [PATCH 13/16] [PHPUnitBridge] Fix microtime() format --- ClockMock.php | 2 +- Tests/ClockMockTest.php | 60 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 Tests/ClockMockTest.php diff --git a/ClockMock.php b/ClockMock.php index 5cd3531d..962649bc 100644 --- a/ClockMock.php +++ b/ClockMock.php @@ -66,7 +66,7 @@ public static function microtime($asFloat = false) return self::$now; } - return sprintf('%0.6f %d', self::$now - (int) self::$now, (int) self::$now); + return sprintf('%0.6f00 %d', self::$now - (int) self::$now, (int) self::$now); } public static function register($class) diff --git a/Tests/ClockMockTest.php b/Tests/ClockMockTest.php new file mode 100644 index 00000000..82cfb6f5 --- /dev/null +++ b/Tests/ClockMockTest.php @@ -0,0 +1,60 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bridge\PhpUnit\Tests; + +use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ClockMock; + +/** + * @author Dominic Tubach + * + * @covers \Symfony\Bridge\PhpUnit\ClockMock + */ +class ClockMockTest extends TestCase +{ + public static function setUpBeforeClass() + { + ClockMock::register(__CLASS__); + } + + protected function setUp() + { + ClockMock::withClockMock(1234567890.125); + } + + public function testTime() + { + $this->assertSame(1234567890, time()); + } + + public function testSleep() + { + sleep(2); + $this->assertSame(1234567892, time()); + } + + public function testMicrotime() + { + $this->assertSame('0.12500000 1234567890', microtime()); + } + + public function testMicrotimeAsFloat() + { + $this->assertSame(1234567890.125, microtime(true)); + } + + public function testUsleep() + { + usleep(2); + $this->assertSame(1234567890.125002, microtime(true)); + } +} From 879144b050015f64ecb04ef053af68ff63c8abb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Sun, 11 Nov 2018 12:11:22 +0100 Subject: [PATCH 14/16] Bump phpunit XSD version to 5.2 Some attributes being used in the phpunit configuration files, namely failOnRisky and failOnWarning were introduced in phpunit 5.2.0. The Composer configuration shows that tests should run with old versions of phpunit, but phpunit only validates the configuration against the XSD since phpunit 7.2.0. These changes can be tested as follows: wget http://schema.phpunit.de/5.2/phpunit.xsd xargs xmllint --schema phpunit.xsd 1>/dev/null find src -name phpunit.xml.dist| xargs xmllint --schema phpunit.xsd 1>/dev/null See https://github.com/sebastianbergmann/phpunit/commit/7e06a82806be004cbfd30a02d92162e9ed4abc7c See https://github.com/symfony/symfony/blob/46e3745a03e199e64cc0fcf3284a96b5a25dcee9/composer.json#L98 --- phpunit.xml.dist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 816cfe49..d37d2eac 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,7 +1,7 @@ Date: Mon, 12 Nov 2018 19:05:42 +0100 Subject: [PATCH 15/16] [PhpUnitBridge] Fix typo --- DeprecationErrorHandler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DeprecationErrorHandler.php b/DeprecationErrorHandler.php index f95d1389..7a48f1a1 100644 --- a/DeprecationErrorHandler.php +++ b/DeprecationErrorHandler.php @@ -30,7 +30,7 @@ class DeprecationErrorHandler * - use "/some-regexp/" to stop the test suite whenever a deprecation * message matches the given regular expression; * - use a number to define the upper bound of allowed deprecations, - * making the test suite fail whenever more notices are trigerred. + * making the test suite fail whenever more notices are triggered. * * @param int|string|false $mode The reporting mode, defaults to not allowing any deprecations */ From 4aa44ecbfb5e2c50797d17756da11c93a8a6974f Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 16 Apr 2019 11:01:24 +0200 Subject: [PATCH 16/16] security #cve-2019-10912 [PHPUnit Bridge] Prevent destructors with side-effects from being unserialized (nicolas-grekas) This PR was merged into the 2.8 branch. Discussion ---------- [PHPUnit Bridge] Prevent destructors with side-effects from being unserialized | Q | A | ------------- | --- | Branch? | 2.8 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Commits ------- 908b64d17e [2.8][PHPUnit Bridge] Prevent destructors with side-effects from being unserialized - CVE-2019-10912 --- SymfonyTestsListener.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/SymfonyTestsListener.php b/SymfonyTestsListener.php index e7e2d08e..98696371 100644 --- a/SymfonyTestsListener.php +++ b/SymfonyTestsListener.php @@ -61,6 +61,16 @@ public function __construct(array $mockedNamespaces = array()) } } + public function __sleep() + { + throw new \BadMethodCallException('Cannot serialize '.__CLASS__); + } + + public function __wakeup() + { + throw new \BadMethodCallException('Cannot unserialize '.__CLASS__); + } + public function __destruct() { if (0 < $this->state) {