Skip to content

Commit

Permalink
Merge pull request #280 from Jubeki/catch-phpunit-errors-and-deprecat…
Browse files Browse the repository at this point in the history
…ions

Catch PHPUnit Errors and Deprecations
  • Loading branch information
nunomaduro authored Aug 7, 2023
2 parents 3dd615a + f3c1e61 commit 61553ad
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/Adapters/Phpunit/Printers/DefaultPrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
use PHPUnit\Event\Test\Passed;
use PHPUnit\Event\Test\PhpDeprecationTriggered;
use PHPUnit\Event\Test\PhpNoticeTriggered;
use PHPUnit\Event\Test\PhpunitDeprecationTriggered;
use PHPUnit\Event\Test\PhpunitErrorTriggered;
use PHPUnit\Event\Test\PhpunitWarningTriggered;
use PHPUnit\Event\Test\PhpWarningTriggered;
use PHPUnit\Event\Test\PreparationStarted;
Expand Down Expand Up @@ -316,6 +318,26 @@ public function testDeprecationTriggered(DeprecationTriggered $event): void
$this->state->add(TestResult::fromTestCase($event->test(), TestResult::DEPRECATED, $throwable));
}

/**
* Listen to the test phpunit deprecation triggered event.
*/
public function testPhpunitDeprecationTriggered(PhpunitDeprecationTriggered $event): void
{
$throwable = ThrowableBuilder::from(new TestOutcome($event->message()));

$this->state->add(TestResult::fromTestCase($event->test(), TestResult::DEPRECATED, $throwable));
}

/**
* Listen to the test phpunit error triggered event.
*/
public function testPhpunitErrorTriggered(PhpunitErrorTriggered $event): void
{
$throwable = ThrowableBuilder::from(new TestOutcome($event->message()));

$this->state->add(TestResult::fromTestCase($event->test(), TestResult::FAIL, $throwable));
}

/**
* Listen to the test warning triggered event.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
use PHPUnit\Event\Test\PhpDeprecationTriggeredSubscriber;
use PHPUnit\Event\Test\PhpNoticeTriggered;
use PHPUnit\Event\Test\PhpNoticeTriggeredSubscriber;
use PHPUnit\Event\Test\PhpunitDeprecationTriggered;
use PHPUnit\Event\Test\PhpunitDeprecationTriggeredSubscriber;
use PHPUnit\Event\Test\PhpunitErrorTriggered;
use PHPUnit\Event\Test\PhpunitErrorTriggeredSubscriber;
use PHPUnit\Event\Test\PhpunitWarningTriggered;
use PHPUnit\Event\Test\PhpunitWarningTriggeredSubscriber;
use PHPUnit\Event\Test\PhpWarningTriggered;
Expand Down Expand Up @@ -189,6 +193,14 @@ public function notify(PhpDeprecationTriggered $event): void
}
},

new class($printer) extends Subscriber implements PhpunitDeprecationTriggeredSubscriber
{
public function notify(PhpunitDeprecationTriggered $event): void
{
$this->printer()->testPhpunitDeprecationTriggered($event);
}
},

new class($printer) extends Subscriber implements PhpNoticeTriggeredSubscriber
{
public function notify(PhpNoticeTriggered $event): void
Expand All @@ -213,6 +225,14 @@ public function notify(PhpunitWarningTriggered $event): void
}
},

new class($printer) extends Subscriber implements PhpunitErrorTriggeredSubscriber
{
public function notify(PhpunitErrorTriggered $event): void
{
$this->printer()->testPhpunitErrorTriggered($event);
}
},

// Test > Outcome ...

new class($printer) extends Subscriber implements ErroredSubscriber
Expand Down

0 comments on commit 61553ad

Please sign in to comment.