Skip to content

Commit bc33d2b

Browse files
authored
ref: remove phpunit bridge (#1930)
1 parent 1895ab6 commit bc33d2b

17 files changed

+213
-25
lines changed

composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
"phpbench/phpbench": "^1.0",
4040
"phpstan/phpstan": "^1.3",
4141
"phpunit/phpunit": "^8.5|^9.6",
42-
"symfony/phpunit-bridge": "^5.2|6.4.25|7.3.3",
4342
"vimeo/psalm": "^4.17"
4443
},
4544
"suggest": {

phpstan.neon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ parameters:
1010
excludePaths:
1111
- tests/resources
1212
- tests/Fixtures
13+
- src/Util/ClockMock.php
1314
dynamicConstantNames:
1415
- Monolog\Logger::API
1516
bootstrapFiles:

phpunit.xml.dist

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@
3434
</whitelist>
3535
</filter>
3636

37-
<listeners>
38-
<listener class="\Symfony\Bridge\PhpUnit\SymfonyTestsListener" />
39-
</listeners>
40-
4137
<extensions>
4238
<extension class="Sentry\Tests\SentrySdkExtension" />
4339
</extensions>

psalm.xml.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<directory name="src" />
1111
<ignoreFiles>
1212
<directory name="vendor" />
13+
<file name="src/Util/ClockMock.php" />
1314
</ignoreFiles>
1415
</projectFiles>
1516

src/Util/ClockMock.php

Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* Original file: https://github.com/symfony/symfony/blob/9c413a356ccb3c982add8fa2b19813927157aa0e/src/Symfony/Bridge/PhpUnit/ClockMock.php#L18
7+
*
8+
* Copyright (c) 2004-present Fabien Potencier
9+
*
10+
* Permission is hereby granted, free of charge, to any person obtaining a copy
11+
* of this software and associated documentation files (the "Software"), to deal
12+
* in the Software without restriction, including without limitation the rights
13+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14+
* copies of the Software, and to permit persons to whom the Software is furnished
15+
* to do so, subject to the following conditions:
16+
*
17+
* The above copyright notice and this permission notice shall be included in all
18+
* copies or substantial portions of the Software.
19+
*
20+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26+
* THE SOFTWARE.
27+
*/
28+
29+
namespace Sentry\Util;
30+
31+
/**
32+
* @author Nicolas Grekas <p@tchwork.com>
33+
* @author Dominic Tubach <dominic.tubach@to.com>
34+
*/
35+
class ClockMock
36+
{
37+
private static $now;
38+
39+
public static function withClockMock($enable = null): ?bool
40+
{
41+
if ($enable === null) {
42+
return self::$now !== null;
43+
}
44+
45+
self::$now = is_numeric($enable) ? (float) $enable : ($enable ? microtime(true) : null);
46+
47+
return null;
48+
}
49+
50+
public static function time(): int
51+
{
52+
if (self::$now === null) {
53+
return time();
54+
}
55+
56+
return (int) self::$now;
57+
}
58+
59+
public static function sleep($s): int
60+
{
61+
if (self::$now === null) {
62+
return sleep($s);
63+
}
64+
65+
self::$now += (int) $s;
66+
67+
return 0;
68+
}
69+
70+
public static function usleep($us): void
71+
{
72+
if (self::$now === null) {
73+
usleep($us);
74+
} else {
75+
self::$now += $us / 1000000;
76+
}
77+
}
78+
79+
/**
80+
* @return string|float
81+
*/
82+
public static function microtime($asFloat = false)
83+
{
84+
if (self::$now === null) {
85+
return microtime($asFloat);
86+
}
87+
88+
if ($asFloat) {
89+
return self::$now;
90+
}
91+
92+
return \sprintf('%0.6f00 %d', self::$now - (int) self::$now, (int) self::$now);
93+
}
94+
95+
public static function date($format, $timestamp = null): string
96+
{
97+
if ($timestamp === null) {
98+
$timestamp = self::time();
99+
}
100+
101+
return date($format, $timestamp);
102+
}
103+
104+
public static function gmdate($format, $timestamp = null): string
105+
{
106+
if ($timestamp === null) {
107+
$timestamp = self::time();
108+
}
109+
110+
return gmdate($format, $timestamp);
111+
}
112+
113+
/**
114+
* @return array|int|float
115+
*/
116+
public static function hrtime($asNumber = false)
117+
{
118+
$ns = (self::$now - (int) self::$now) * 1000000000;
119+
120+
if ($asNumber) {
121+
$number = \sprintf('%d%d', (int) self::$now, $ns);
122+
123+
return \PHP_INT_SIZE === 8 ? (int) $number : (float) $number;
124+
}
125+
126+
return [(int) self::$now, (int) $ns];
127+
}
128+
129+
/**
130+
* @return false|int
131+
*/
132+
public static function strtotime(string $datetime, ?int $timestamp = null)
133+
{
134+
if ($timestamp === null) {
135+
$timestamp = self::time();
136+
}
137+
138+
return strtotime($datetime, $timestamp);
139+
}
140+
141+
public static function register($class): void
142+
{
143+
$self = static::class;
144+
145+
$mockedNs = [substr($class, 0, strrpos($class, '\\'))];
146+
if (strpos($class, '\\Tests\\') > 0) {
147+
$ns = str_replace('\\Tests\\', '\\', $class);
148+
$mockedNs[] = substr($ns, 0, strrpos($ns, '\\'));
149+
} elseif (str_starts_with($class, 'Tests\\')) {
150+
$mockedNs[] = substr($class, 6, strrpos($class, '\\') - 6);
151+
}
152+
foreach ($mockedNs as $ns) {
153+
if (\function_exists($ns . '\time')) {
154+
continue;
155+
}
156+
eval(<<<EOPHP
157+
namespace $ns;
158+
159+
function time()
160+
{
161+
return \\$self::time();
162+
}
163+
164+
function microtime(\$asFloat = false)
165+
{
166+
return \\$self::microtime(\$asFloat);
167+
}
168+
169+
function sleep(\$s)
170+
{
171+
return \\$self::sleep(\$s);
172+
}
173+
174+
function usleep(\$us)
175+
{
176+
\\$self::usleep(\$us);
177+
}
178+
179+
function date(\$format, \$timestamp = null)
180+
{
181+
return \\$self::date(\$format, \$timestamp);
182+
}
183+
184+
function gmdate(\$format, \$timestamp = null)
185+
{
186+
return \\$self::gmdate(\$format, \$timestamp);
187+
}
188+
189+
function hrtime(\$asNumber = false)
190+
{
191+
return \\$self::hrtime(\$asNumber);
192+
}
193+
194+
function strtotime(\$datetime, \$timestamp = null)
195+
{
196+
return \\$self::strtotime(\$datetime, \$timestamp);
197+
}
198+
EOPHP
199+
);
200+
}
201+
}
202+
}

tests/BreadcrumbTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use PHPUnit\Framework\TestCase;
88
use Sentry\Breadcrumb;
9-
use Symfony\Bridge\PhpUnit\ClockMock;
9+
use Sentry\Util\ClockMock;
1010

1111
final class BreadcrumbTest extends TestCase
1212
{

tests/ClientTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,9 @@
2424
use Sentry\Transport\Result;
2525
use Sentry\Transport\ResultStatus;
2626
use Sentry\Transport\TransportInterface;
27-
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
2827

2928
final class ClientTest extends TestCase
3029
{
31-
use ExpectDeprecationTrait;
32-
3330
public function testConstructorSetupsIntegrations(): void
3431
{
3532
$integrationCalled = false;

tests/DsnTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,9 @@
66

77
use PHPUnit\Framework\TestCase;
88
use Sentry\Dsn;
9-
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
109

1110
final class DsnTest extends TestCase
1211
{
13-
use ExpectDeprecationTrait;
14-
1512
/**
1613
* @dataProvider createFromStringDataProvider
1714
*/

tests/Metrics/MetricsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use Sentry\State\Hub;
1414
use Sentry\Tracing\SpanContext;
1515
use Sentry\Tracing\TransactionContext;
16-
use Symfony\Bridge\PhpUnit\ClockMock;
16+
use Sentry\Util\ClockMock;
1717

1818
use function Sentry\metrics;
1919

tests/OptionsTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,10 @@
1111
use Sentry\Options;
1212
use Sentry\Serializer\PayloadSerializer;
1313
use Sentry\Transport\HttpTransport;
14-
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
1514
use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
1615

1716
final class OptionsTest extends TestCase
1817
{
19-
use ExpectDeprecationTrait;
20-
2118
/**
2219
* @var int
2320
*/

0 commit comments

Comments
 (0)