-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ondřej Ešler
committed
May 24, 2023
1 parent
e67c0e6
commit dcf48ba
Showing
7 changed files
with
84 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
vendor | ||
/vendor | ||
composer.lock | ||
composer.phar |
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,33 @@ | ||
<?php | ||
namespace Esler\PHPUnit; | ||
|
||
use BadMethodCallException; | ||
use PHPUnit\Runner\Extension\Extension; | ||
use PHPUnit\Runner\Extension\Facade; | ||
use PHPUnit\Runner\Extension\ParameterCollection; | ||
use PHPUnit\TextUI\Configuration\Configuration; | ||
|
||
/** | ||
* This class defines an extension for PHPUnit. | ||
* | ||
* It allows interrupt running test gracefully. By hitting Ctrl+\ (SIGQUIT) | ||
* you will let know to PHPUnit | ||
* | ||
* @author Ondrej Esler <esler.ondrej@gmail.com> | ||
* @license MIT | ||
*/ | ||
final class GracefulInterruptExtension implements Extension | ||
{ | ||
public function bootstrap(Configuration $configuration, Facade $facade, ParameterCollection $parameters): void | ||
{ | ||
if (!function_exists('pcntl_signal')) { | ||
throw new BadMethodCallException('PCNTL is disabled'); | ||
} | ||
|
||
$facade->registerSubscriber($subscriber = new GracefulInterruptSubscriber()); | ||
|
||
pcntl_signal(SIGQUIT, static function () use ($subscriber) { | ||
$subscriber->interrupted = true; | ||
}); | ||
} | ||
} |
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,29 @@ | ||
<?php | ||
namespace Esler\PHPUnit; | ||
|
||
use PHPUnit\Event\Test\PreparedSubscriber; | ||
use PHPUnit\Event\Test\Prepared; | ||
use PHPUnit\Framework\Assert; | ||
|
||
/** | ||
* This class defines an extension for PHPUnit. | ||
* | ||
* It allows interrupt running test gracefully. By hitting Ctrl+\ (SIGQUIT) | ||
* you will let know to PHPUnit | ||
* | ||
* @author Ondrej Esler <esler.ondrej@gmail.com> | ||
* @license MIT | ||
*/ | ||
final class GracefulInterruptSubscriber implements PreparedSubscriber | ||
{ | ||
public bool $interrupted = false; | ||
|
||
public function notify(Prepared $event): void | ||
{ | ||
pcntl_signal_dispatch(); | ||
|
||
if ($this->interrupted) { | ||
Assert::markTestSkipped('Skipped by ' . $this::class); | ||
} | ||
} | ||
} |
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