diff --git a/src/Configuration.php b/src/Configuration.php index 55fb589d..03d357a2 100644 --- a/src/Configuration.php +++ b/src/Configuration.php @@ -5,37 +5,25 @@ namespace Pest; use Pest\PendingCalls\UsesCall; -use Pest\Support\Backtrace; /** * @internal */ final class Configuration { - /** - * 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(), - ); - } + private readonly string $filename; /** * Creates a new configuration instance. */ - private function __construct( - private readonly string $filename, - ) {} + public function __construct( + 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 { @@ -47,9 +35,10 @@ public function in(string ...$targets): UsesCall */ public function extend(string ...$classAndTraits): UsesCall { - return (new UsesCall($this->filename, array_values($classAndTraits))) - ->in($this->filename) - ->extend(...$classAndTraits); + return new UsesCall( + $this->filename, + array_values($classAndTraits) + ); } /** diff --git a/src/Functions.php b/src/Functions.php index 2ce48fba..8a004e67 100644 --- a/src/Functions.php +++ b/src/Functions.php @@ -117,7 +117,7 @@ function uses(string ...$classAndTraits): UsesCall */ function pest(): Configuration { - return Configuration::getInstance(); + return new Configuration(Backtrace::file()); } } diff --git a/src/PendingCalls/UsesCall.php b/src/PendingCalls/UsesCall.php index 942930f1..fb7fa27e 100644 --- a/src/PendingCalls/UsesCall.php +++ b/src/PendingCalls/UsesCall.php @@ -101,7 +101,7 @@ public function in(string ...$targets): self return str_starts_with($path, $startChar) ? $path : implode(DIRECTORY_SEPARATOR, [ - dirname($this->filename), + is_dir($this->filename) ? $this->filename : dirname($this->filename), $path, ]); }, $targets);