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:
@ -34,7 +34,10 @@
|
|||||||
"autoload-dev": {
|
"autoload-dev": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"Tests\\": "tests/PHPUnit/"
|
"Tests\\": "tests/PHPUnit/"
|
||||||
}
|
},
|
||||||
|
"files": [
|
||||||
|
"tests/Autoload.php"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"ergebnis/phpstan-rules": "^0.14.4",
|
"ergebnis/phpstan-rules": "^0.14.4",
|
||||||
|
|||||||
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
|
public static function getInstance(string $rootPath = null): TestSuite
|
||||||
{
|
{
|
||||||
if (is_string($rootPath)) {
|
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) {
|
if (self::$instance === null) {
|
||||||
|
|||||||
@ -3,3 +3,13 @@
|
|||||||
if (class_exists(NunoMaduro\Collision\Provider::class)) {
|
if (class_exists(NunoMaduro\Collision\Provider::class)) {
|
||||||
(new NunoMaduro\Collision\Provider())->register();
|
(new NunoMaduro\Collision\Provider())->register();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
trait PluginTrait
|
||||||
|
{
|
||||||
|
function assertPluginTraitGotRegistered(): void
|
||||||
|
{
|
||||||
|
assertTrue(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Pest\Plugin::uses(PluginTrait::class);
|
||||||
|
|||||||
3
tests/Plugins/Traits.php
Normal file
3
tests/Plugins/Traits.php
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
it('allows global uses')->assertPluginTraitGotRegistered();
|
||||||
Reference in New Issue
Block a user