Skip to content

Commit e71b10a

Browse files
committed
Added support for the error suppression operator.
1 parent efaeaa2 commit e71b10a

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

src/Theme/ClassicTheme.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function onTestFinished(TestResult $result): void
4646
$throwable = $throwable->previous();
4747
}
4848

49-
if ($result->trace) {
49+
if ($result->trace && !$result->trace->suppressed) {
5050
printf(
5151
Color::colorize("fg-$statusColour", '%s%s: %s in %s on line %s%1$s%1$s'),
5252
PHP_EOL,

src/Trace.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ public function __construct(
1313
public readonly string $message,
1414
public readonly string $file,
1515
public readonly int $line,
16+
public readonly bool $suppressed = false,
1617
) {}
1718

1819
public static function fromEvent(PhpWarningTriggered|PhpNoticeTriggered|PhpDeprecationTriggered $event): self
1920
{
20-
return new self($event->message(), $event->file(), $event->line());
21+
return new self($event->message(), $event->file(), $event->line(), $event->wasSuppressed());
2122
}
2223
}

test/CapabilitiesTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ public function testWarning(): void
6464
self::assertTrue(true);
6565
}
6666

67+
public function testSilencedWarning(): void
68+
{
69+
$foo = @$bar;
70+
71+
self::assertTrue(true);
72+
}
73+
6774
public function testDeprecation(): void
6875
{
6976
// Serializable interface is deprecated.

test/functional/warning silenced.phpt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
Tests that when a test generates a warning that is suppressed, the warning is not printed.
3+
4+
--ARGS--
5+
-c test --colors=always test/CapabilitiesTest.php --filter ::testSilencedWarning$
6+
7+
--FILE_EXTERNAL--
8+
../PHPUnit runner.php
9+
10+
--EXPECTF--
11+
PHPUnit %s
12+
13+
Runtime: %s
14+
Configuration: %s
15+
16+
100% W ScriptFUSIONTest\Pip\CapabilitiesTest::testSilencedWarning (%d ms)
17+
18+
19+
Time: %s
20+
%A
21+
OK (1 test, 1 assertion)

0 commit comments

Comments
 (0)