-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #217 from facile-it/detect-phpunit-errors
Detect and report `PHPUnitError` events
- Loading branch information
Showing
8 changed files
with
123 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Paraunit\Logs\TestHook; | ||
|
||
use Paraunit\Logs\ValueObject\LogStatus; | ||
use Paraunit\Logs\ValueObject\Test; | ||
use PHPUnit\Event\Test\PhpunitErrorTriggered; | ||
use PHPUnit\Event\Test\PhpunitErrorTriggeredSubscriber; | ||
|
||
/** | ||
* @template-extends AbstractTestHook<PhpunitErrorTriggered> | ||
*/ | ||
class PhpUnitError extends AbstractTestHook implements PhpunitErrorTriggeredSubscriber | ||
{ | ||
public function notify(PhpunitErrorTriggered $event): void | ||
{ | ||
$this->write(LogStatus::ErrorTriggered, Test::fromPHPUnitTest($event->test()), $event->message()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Stub; | ||
|
||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class PHPUnitErrorTestStub extends TestCase | ||
{ | ||
public function testToAvoidWarnings(): void | ||
{ | ||
$this->assertTrue(true); | ||
} | ||
|
||
#[DataProvider('emptyDataProvider')] | ||
public function testWhichTriggersPHPUnitError(): void | ||
{ | ||
$this->assertTrue(true); | ||
} | ||
|
||
public static function emptyDataProvider(): array | ||
{ | ||
return []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Unit\Logs\TestHook; | ||
|
||
use Paraunit\Logs\TestHook\PhpUnitError; | ||
use Paraunit\Logs\ValueObject\LogStatus; | ||
use PHPUnit\Event\Test\PhpunitErrorTriggered; | ||
|
||
/** | ||
* @template-extends AbstractTestHookTestCase<PhpUnitError, PhpunitErrorTriggered> | ||
*/ | ||
class PhpUnitErrorTest extends AbstractTestHookTestCase | ||
{ | ||
protected function createSubscriber(): PhpUnitError | ||
{ | ||
return new PhpUnitError(); | ||
} | ||
|
||
protected function getExpectedStatus(): LogStatus | ||
{ | ||
return LogStatus::ErrorTriggered; | ||
} | ||
|
||
protected function createEvent(): PhpunitErrorTriggered | ||
{ | ||
return new PhpunitErrorTriggered( | ||
$this->createTelemetryInfo(), | ||
$this->createPHPUnitTestMethod(), | ||
$this->getExpectedMessage(), | ||
); | ||
} | ||
|
||
/** | ||
* @return non-empty-string | ||
*/ | ||
protected function getExpectedMessage(): string | ||
{ | ||
return 'test Error message'; | ||
} | ||
} |