Skip to content

Commit

Permalink
Added support for the error suppression operator.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bilge committed Sep 25, 2024
1 parent efaeaa2 commit e71b10a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Theme/ClassicTheme.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function onTestFinished(TestResult $result): void
$throwable = $throwable->previous();
}

if ($result->trace) {
if ($result->trace && !$result->trace->suppressed) {
printf(
Color::colorize("fg-$statusColour", '%s%s: %s in %s on line %s%1$s%1$s'),
PHP_EOL,
Expand Down
3 changes: 2 additions & 1 deletion src/Trace.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ public function __construct(
public readonly string $message,
public readonly string $file,
public readonly int $line,
public readonly bool $suppressed = false,
) {}

public static function fromEvent(PhpWarningTriggered|PhpNoticeTriggered|PhpDeprecationTriggered $event): self
{
return new self($event->message(), $event->file(), $event->line());
return new self($event->message(), $event->file(), $event->line(), $event->wasSuppressed());
}
}
7 changes: 7 additions & 0 deletions test/CapabilitiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ public function testWarning(): void
self::assertTrue(true);
}

public function testSilencedWarning(): void
{
$foo = @$bar;

self::assertTrue(true);
}

public function testDeprecation(): void
{
// Serializable interface is deprecated.
Expand Down
21 changes: 21 additions & 0 deletions test/functional/warning silenced.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--TEST--
Tests that when a test generates a warning that is suppressed, the warning is not printed.

--ARGS--
-c test --colors=always test/CapabilitiesTest.php --filter ::testSilencedWarning$

--FILE_EXTERNAL--
../PHPUnit runner.php

--EXPECTF--
PHPUnit %s

Runtime: %s
Configuration: %s

100% W ScriptFUSIONTest\Pip\CapabilitiesTest::testSilencedWarning (%d ms)


Time: %s
%A
OK (1 test, 1 assertion)

0 comments on commit e71b10a

Please sign in to comment.