Skip to content

Commit 5e0910c

Browse files
committed
Fix warnings in DriverTest
1 parent 551d8e3 commit 5e0910c

1 file changed

Lines changed: 28 additions & 33 deletions

File tree

test/Driver/DriverTest.php

Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,10 @@ public function checkForSignalCapability(): void
110110
}
111111

112112
try {
113-
$callbackId = $this->loop->onSignal(SIGUSR1, function (): void {
113+
$callbackId = $this->loop->onSignal(SIGUSR1, static function (): void {
114114
});
115115
$this->loop->cancel($callbackId);
116-
} catch (UnsupportedFeatureException $e) {
116+
} catch (UnsupportedFeatureException) {
117117
self::markTestSkipped("The event loop is not capable of handling signals properly. Skipping.");
118118
}
119119
}
@@ -198,7 +198,7 @@ public function testOnSignalCallbackKeepAliveRunResult(): void
198198
$this->checkForSignalCapability();
199199
$invoked = false;
200200
$this->start(function (Driver $loop) use (&$invoked): void {
201-
$callbackId = $loop->onSignal(SIGUSR1, function () {
201+
$callbackId = $loop->onSignal(SIGUSR1, static function () {
202202
// empty
203203
});
204204
$callbackId = $loop->delay(0.1, function () use (&$invoked, $loop, $callbackId): void {
@@ -218,7 +218,7 @@ public function testUnreferencedDeferredCallbackStillExecutes(): void
218218
$invoked = true;
219219
});
220220
$loop->unreference($callbackId);
221-
$loop->defer(function () {
221+
$loop->defer(static function () {
222222
// just to keep loop running
223223
});
224224
});
@@ -256,57 +256,55 @@ public function testDisabledDeferReenableInSubsequentTick(): void
256256

257257
public function provideRegistrationArgs(): array
258258
{
259-
$args = [
259+
return [
260260
[
261261
"defer",
262262
[
263-
function () {
263+
static function () {
264264
},
265265
],
266266
],
267267
[
268268
"delay",
269269
[
270270
0.005,
271-
function () {
271+
static function () {
272272
},
273273
],
274274
],
275275
[
276276
"repeat",
277277
[
278278
0.005,
279-
function () {
279+
static function () {
280280
},
281281
],
282282
],
283283
[
284284
"onWritable",
285285
[
286286
\STDOUT,
287-
function () {
287+
static function () {
288288
},
289289
],
290290
],
291291
[
292292
"onReadable",
293293
[
294294
\STDIN,
295-
function () {
295+
static function () {
296296
},
297297
],
298298
],
299299
[
300300
"onSignal",
301301
[
302302
\SIGUSR1,
303-
function () {
303+
static function () {
304304
},
305305
],
306306
],
307307
];
308-
309-
return $args;
310308
}
311309

312310
/** @dataProvider provideRegistrationArgs */
@@ -340,7 +338,7 @@ public function testCallbackReferenceInfo(string $type, array $args): void
340338
$loop = $this->loop;
341339

342340
$func = [$loop, $type];
343-
if (\substr($type, 0, 2) === "on") {
341+
if (\str_starts_with($type, "on")) {
344342
$type = "on_" . \lcfirst(\substr($type, 2));
345343
}
346344

@@ -378,7 +376,7 @@ public function testCallbackReferenceInfo(string $type, array $args): void
378376
$expected = ["referenced" => 2, "unreferenced" => 0];
379377
self::assertSame($expected, $info["enabled_watchers"]);
380378

381-
// cancelling an referenced callback should decrement the referenced count
379+
// cancelling a referenced callback should decrement the referenced count
382380
$loop->cancel($callbackId2);
383381
$info = $loop->getInfo();
384382
$expected = ["referenced" => 1, "unreferenced" => 0];
@@ -407,7 +405,7 @@ public function testCallbackRegistrationAndCancellationInfo(string $type, array
407405
$loop = $this->loop;
408406

409407
$func = [$loop, $type];
410-
if (\substr($type, 0, 2) === "on") {
408+
if (\str_starts_with($type, "on")) {
411409
$type = "on_" . \lcfirst(\substr($type, 2));
412410
}
413411

@@ -417,13 +415,13 @@ public function testCallbackRegistrationAndCancellationInfo(string $type, array
417415
$expected = ["enabled" => 1, "disabled" => 0];
418416
self::assertSame($expected, $info[$type]);
419417

420-
// invoke enable() on active callback to ensure it has no side-effects
418+
// invoke enable() on active callback to ensure it has no side effects
421419
$loop->enable($callbackId);
422420
$info = $loop->getInfo();
423421
$expected = ["enabled" => 1, "disabled" => 0];
424422
self::assertSame($expected, $info[$type]);
425423

426-
// invoke disable() twice to ensure it has no side-effects
424+
// invoke disable() twice to ensure it has no side effects
427425
$loop->disable($callbackId);
428426
$loop->disable($callbackId);
429427

@@ -484,7 +482,7 @@ public function testNoMemoryLeak(string $type, array $args): void
484482

485483
$this->start(function (Driver $loop) use ($type, $args, $runs) {
486484
$initialMem = \memory_get_usage();
487-
$cb = function ($runs) use ($loop, $type, $args): void {
485+
$cb = static function ($runs) use ($loop, $type, $args): void {
488486
$func = [$loop, $type];
489487
for ($callbacks = [], $i = 0; $i < $runs; $i++) {
490488
$callbacks[] = $func(...$args);
@@ -568,10 +566,7 @@ public function testNoMemoryLeak(string $type, array $args): void
568566
if ($i--) {
569567
// explicitly use *different* streams with *different* resource ids
570568
$ends = \stream_socket_pair(
571-
\stripos(
572-
PHP_OS,
573-
"win"
574-
) === 0 ? STREAM_PF_INET : STREAM_PF_UNIX,
569+
\DIRECTORY_SEPARATOR === "\\" ? STREAM_PF_INET : STREAM_PF_UNIX,
575570
STREAM_SOCK_STREAM,
576571
STREAM_IPPROTO_IP
577572
);
@@ -588,7 +583,7 @@ public function testNoMemoryLeak(string $type, array $args): void
588583
$loop->run();
589584
}
590585
if ($type === "onSignal") {
591-
$sendSignal = function (): void {
586+
$sendSignal = static function (): void {
592587
\posix_kill(\getmypid(), \SIGUSR1);
593588
};
594589
$loop->onSignal(
@@ -732,8 +727,8 @@ public function testSignalExecutionOrder(): void
732727

733728
$this->expectOutputString("122222");
734729
$this->start(function (Driver $loop): void {
735-
$f = function ($i) use ($loop) {
736-
return function ($callbackId) use ($loop, $i): void {
730+
$f = static function ($i) use ($loop) {
731+
return static function ($callbackId) use ($loop, $i): void {
737732
$loop->cancel($callbackId);
738733
echo $i;
739734
};
@@ -1036,7 +1031,7 @@ public function testLoopAllowsExceptionToBubbleUpFromRepeatingAlarmDuringStart()
10361031
public function testErrorHandlerCapturesUncaughtException(): void
10371032
{
10381033
$msg = "";
1039-
$this->loop->setErrorHandler($f = function (): void {
1034+
$this->loop->setErrorHandler($f = static function (): void {
10401035
});
10411036
$oldErrorHandler = $this->loop->setErrorHandler(function (\Exception $error) use (&$msg): void {
10421037
$msg = $error->getMessage();
@@ -1283,17 +1278,17 @@ public function testOptionalCallbackDataPassedOnInvocation(): void
12831278
$callbackData = new \StdClass();
12841279

12851280
$this->start(function (Driver $loop) use ($callbackData): void {
1286-
$loop->defer(function ($callbackId) use ($callbackData): void {
1281+
$loop->defer(function () use ($callbackData): void {
12871282
$callbackData->defer = true;
12881283
});
1289-
$loop->delay(0.001, function ($callbackId) use ($callbackData): void {
1284+
$loop->delay(0.001, function () use ($callbackData): void {
12901285
$callbackData->delay = true;
12911286
});
12921287
$loop->repeat(0.001, function ($callbackId) use ($loop, $callbackData): void {
12931288
$callbackData->repeat = true;
12941289
$loop->cancel($callbackId);
12951290
});
1296-
$loop->onWritable(STDERR, function ($callbackId, $stream) use ($loop, $callbackData): void {
1291+
$loop->onWritable(STDERR, function ($callbackId) use ($loop, $callbackData): void {
12971292
$callbackData->onWritable = true;
12981293
$loop->cancel($callbackId);
12991294
});
@@ -1345,7 +1340,7 @@ public function testDeferEnabledInNextTick(): void
13451340

13461341
public function testMicrotaskExecutedImmediatelyAfterCallback(): void
13471342
{
1348-
self::expectOutputString('12835674');
1343+
$this->expectOutputString('12835674');
13491344

13501345
$this->loop->queue(function (): void {
13511346
print 1;
@@ -1427,7 +1422,7 @@ public function testRethrowsFromCallbacks(): void
14271422

14281423
case "onReadable":
14291424
$ends = \stream_socket_pair(
1430-
\stripos(PHP_OS, "win") === 0 ? STREAM_PF_INET : STREAM_PF_UNIX,
1425+
\DIRECTORY_SEPARATOR === "\\" ? STREAM_PF_INET : STREAM_PF_UNIX,
14311426
STREAM_SOCK_STREAM,
14321427
STREAM_IPPROTO_IP
14331428
);
@@ -1466,7 +1461,7 @@ public function testRethrowsFromCallbacks(): void
14661461
public function testMultipleCallbacksOnSameDescriptor(): void
14671462
{
14681463
$sockets = \stream_socket_pair(
1469-
\stripos(PHP_OS, "win") === 0 ? STREAM_PF_INET : STREAM_PF_UNIX,
1464+
\DIRECTORY_SEPARATOR === "\\" ? STREAM_PF_INET : STREAM_PF_UNIX,
14701465
STREAM_SOCK_STREAM,
14711466
STREAM_IPPROTO_IP
14721467
);

0 commit comments

Comments
 (0)