fix: pest()

This commit is contained in:
Nuno Maduro
2024-07-06 18:25:43 +01:00
parent 67dbce2d42
commit ccdf43726d
3 changed files with 13 additions and 24 deletions

View File

@ -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)
);
} }
/** /**

View File

@ -117,7 +117,7 @@ if (! function_exists('pest')) {
*/ */
function pest(): Configuration function pest(): Configuration
{ {
return Configuration::getInstance(); return new Configuration(Backtrace::file());
} }
} }

View 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);