mirror of
https://github.com/pestphp/pest.git
synced 2026-03-07 00:07:22 +01:00
fix: pest()
This commit is contained in:
@ -5,37 +5,25 @@ declare(strict_types=1);
|
|||||||
namespace Pest;
|
namespace Pest;
|
||||||
|
|
||||||
use Pest\PendingCalls\UsesCall;
|
use Pest\PendingCalls\UsesCall;
|
||||||
use Pest\Support\Backtrace;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
final class Configuration
|
final class Configuration
|
||||||
{
|
{
|
||||||
/**
|
private readonly string $filename;
|
||||||
* The instance of the configuration.
|
|
||||||
*/
|
|
||||||
private static ?Configuration $instance = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the instance of the configuration.
|
|
||||||
*/
|
|
||||||
public static function getInstance(): Configuration
|
|
||||||
{
|
|
||||||
return self::$instance ??= new Configuration(
|
|
||||||
Backtrace::file(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new configuration instance.
|
* Creates a new configuration instance.
|
||||||
*/
|
*/
|
||||||
private function __construct(
|
public function __construct(
|
||||||
private readonly string $filename,
|
string $filename,
|
||||||
) {}
|
) {
|
||||||
|
$this->filename = str_ends_with($filename, '/Pest.php') ? dirname($filename) : $filename;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the configuration of a certain folder.
|
* Use the given classes and traits in the given targets.
|
||||||
*/
|
*/
|
||||||
public function in(string ...$targets): UsesCall
|
public function in(string ...$targets): UsesCall
|
||||||
{
|
{
|
||||||
@ -47,9 +35,10 @@ final class Configuration
|
|||||||
*/
|
*/
|
||||||
public function extend(string ...$classAndTraits): UsesCall
|
public function extend(string ...$classAndTraits): UsesCall
|
||||||
{
|
{
|
||||||
return (new UsesCall($this->filename, array_values($classAndTraits)))
|
return new UsesCall(
|
||||||
->in($this->filename)
|
$this->filename,
|
||||||
->extend(...$classAndTraits);
|
array_values($classAndTraits)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -117,7 +117,7 @@ if (! function_exists('pest')) {
|
|||||||
*/
|
*/
|
||||||
function pest(): Configuration
|
function pest(): Configuration
|
||||||
{
|
{
|
||||||
return Configuration::getInstance();
|
return new Configuration(Backtrace::file());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -101,7 +101,7 @@ final class UsesCall
|
|||||||
return str_starts_with($path, $startChar)
|
return str_starts_with($path, $startChar)
|
||||||
? $path
|
? $path
|
||||||
: implode(DIRECTORY_SEPARATOR, [
|
: implode(DIRECTORY_SEPARATOR, [
|
||||||
dirname($this->filename),
|
is_dir($this->filename) ? $this->filename : dirname($this->filename),
|
||||||
$path,
|
$path,
|
||||||
]);
|
]);
|
||||||
}, $targets);
|
}, $targets);
|
||||||
|
|||||||
Reference in New Issue
Block a user