mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 07:47:22 +01:00
feat: adds plugin uses api
This commit is contained in:
30
src/Plugin.php
Normal file
30
src/Plugin.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Pest;
|
||||
|
||||
use Pest\TestSuite;
|
||||
|
||||
final class Plugin
|
||||
{
|
||||
/**
|
||||
* The lazy callables to be executed
|
||||
* once the test suite boots.
|
||||
*
|
||||
* @var array<int, callable>
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
public static $callables = [];
|
||||
|
||||
/**
|
||||
* Lazy loads an `uses` call on the context of plugins.
|
||||
*/
|
||||
public static function uses(...$traits): void
|
||||
{
|
||||
self::$callables[] = function () use ($traits) {
|
||||
uses(...$traits)->in(TestSuite::getInstance()->rootPath . DIRECTORY_SEPARATOR . 'tests');
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -106,7 +106,13 @@ final class TestSuite
|
||||
public static function getInstance(string $rootPath = null): TestSuite
|
||||
{
|
||||
if (is_string($rootPath)) {
|
||||
return self::$instance ?? self::$instance = new TestSuite($rootPath);
|
||||
self::$instance = new TestSuite($rootPath);
|
||||
|
||||
foreach (Plugin::$callables as $callable) {
|
||||
$callable();
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
if (self::$instance === null) {
|
||||
|
||||
Reference in New Issue
Block a user