From 1895ab6525292cc75fefbb37680f5b693e5af49a Mon Sep 17 00:00:00 2001 From: Michi Hoffmann Date: Mon, 29 Sep 2025 11:04:43 +0200 Subject: [PATCH 1/3] meta: Pin symfony/phpunit-bridge (#1928) --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 0be4a6531e..d8e863cc8f 100644 --- a/composer.json +++ b/composer.json @@ -39,7 +39,7 @@ "phpbench/phpbench": "^1.0", "phpstan/phpstan": "^1.3", "phpunit/phpunit": "^8.5|^9.6", - "symfony/phpunit-bridge": "^5.2|^6.0|^7.0", + "symfony/phpunit-bridge": "^5.2|6.4.25|7.3.3", "vimeo/psalm": "^4.17" }, "suggest": { From bc33d2b81d81de4de0e8016466a94e7e26919809 Mon Sep 17 00:00:00 2001 From: Martin Linzmayer Date: Tue, 30 Sep 2025 00:30:34 +0200 Subject: [PATCH 2/3] ref: remove phpunit bridge (#1930) --- composer.json | 1 - phpstan.neon | 1 + phpunit.xml.dist | 4 - psalm.xml.dist | 1 + src/Util/ClockMock.php | 202 +++++++++++++++++++++ tests/BreadcrumbTest.php | 2 +- tests/ClientTest.php | 3 - tests/DsnTest.php | 3 - tests/Metrics/MetricsTest.php | 2 +- tests/OptionsTest.php | 3 - tests/Serializer/PayloadSerializerTest.php | 2 +- tests/Tracing/SpanTest.php | 2 +- tests/Tracing/TransactionContextTest.php | 3 - tests/Tracing/TransactionTest.php | 2 +- tests/Transport/HttpTransportTest.php | 2 +- tests/Transport/RateLimiterTest.php | 2 +- tests/bootstrap.php | 3 +- 17 files changed, 213 insertions(+), 25 deletions(-) create mode 100644 src/Util/ClockMock.php diff --git a/composer.json b/composer.json index d8e863cc8f..40e58869ba 100644 --- a/composer.json +++ b/composer.json @@ -39,7 +39,6 @@ "phpbench/phpbench": "^1.0", "phpstan/phpstan": "^1.3", "phpunit/phpunit": "^8.5|^9.6", - "symfony/phpunit-bridge": "^5.2|6.4.25|7.3.3", "vimeo/psalm": "^4.17" }, "suggest": { diff --git a/phpstan.neon b/phpstan.neon index 91af9c48e5..61e18b96c3 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -10,6 +10,7 @@ parameters: excludePaths: - tests/resources - tests/Fixtures + - src/Util/ClockMock.php dynamicConstantNames: - Monolog\Logger::API bootstrapFiles: diff --git a/phpunit.xml.dist b/phpunit.xml.dist index d064f87759..8d5384d667 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -34,10 +34,6 @@ - - - - diff --git a/psalm.xml.dist b/psalm.xml.dist index ea60216a6e..502f940b3b 100644 --- a/psalm.xml.dist +++ b/psalm.xml.dist @@ -10,6 +10,7 @@ + diff --git a/src/Util/ClockMock.php b/src/Util/ClockMock.php new file mode 100644 index 0000000000..ea3f18f184 --- /dev/null +++ b/src/Util/ClockMock.php @@ -0,0 +1,202 @@ + + * @author Dominic Tubach + */ +class ClockMock +{ + private static $now; + + public static function withClockMock($enable = null): ?bool + { + if ($enable === null) { + return self::$now !== null; + } + + self::$now = is_numeric($enable) ? (float) $enable : ($enable ? microtime(true) : null); + + return null; + } + + public static function time(): int + { + if (self::$now === null) { + return time(); + } + + return (int) self::$now; + } + + public static function sleep($s): int + { + if (self::$now === null) { + return sleep($s); + } + + self::$now += (int) $s; + + return 0; + } + + public static function usleep($us): void + { + if (self::$now === null) { + usleep($us); + } else { + self::$now += $us / 1000000; + } + } + + /** + * @return string|float + */ + public static function microtime($asFloat = false) + { + if (self::$now === null) { + return microtime($asFloat); + } + + if ($asFloat) { + return self::$now; + } + + return \sprintf('%0.6f00 %d', self::$now - (int) self::$now, (int) self::$now); + } + + public static function date($format, $timestamp = null): string + { + if ($timestamp === null) { + $timestamp = self::time(); + } + + return date($format, $timestamp); + } + + public static function gmdate($format, $timestamp = null): string + { + if ($timestamp === null) { + $timestamp = self::time(); + } + + return gmdate($format, $timestamp); + } + + /** + * @return array|int|float + */ + public static function hrtime($asNumber = false) + { + $ns = (self::$now - (int) self::$now) * 1000000000; + + if ($asNumber) { + $number = \sprintf('%d%d', (int) self::$now, $ns); + + return \PHP_INT_SIZE === 8 ? (int) $number : (float) $number; + } + + return [(int) self::$now, (int) $ns]; + } + + /** + * @return false|int + */ + public static function strtotime(string $datetime, ?int $timestamp = null) + { + if ($timestamp === null) { + $timestamp = self::time(); + } + + return strtotime($datetime, $timestamp); + } + + public static function register($class): void + { + $self = static::class; + + $mockedNs = [substr($class, 0, strrpos($class, '\\'))]; + if (strpos($class, '\\Tests\\') > 0) { + $ns = str_replace('\\Tests\\', '\\', $class); + $mockedNs[] = substr($ns, 0, strrpos($ns, '\\')); + } elseif (str_starts_with($class, 'Tests\\')) { + $mockedNs[] = substr($class, 6, strrpos($class, '\\') - 6); + } + foreach ($mockedNs as $ns) { + if (\function_exists($ns . '\time')) { + continue; + } + eval(<< Date: Mon, 13 Oct 2025 09:47:56 +0200 Subject: [PATCH 3/3] ref: replace str_starts_with with strpos in ClockMock (#1936) --- src/Util/ClockMock.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Util/ClockMock.php b/src/Util/ClockMock.php index ea3f18f184..004291d39e 100644 --- a/src/Util/ClockMock.php +++ b/src/Util/ClockMock.php @@ -146,7 +146,7 @@ public static function register($class): void if (strpos($class, '\\Tests\\') > 0) { $ns = str_replace('\\Tests\\', '\\', $class); $mockedNs[] = substr($ns, 0, strrpos($ns, '\\')); - } elseif (str_starts_with($class, 'Tests\\')) { + } elseif (strpos($class, 'Tests\\') === 0) { $mockedNs[] = substr($class, 6, strrpos($class, '\\') - 6); } foreach ($mockedNs as $ns) {