Skip to content

Commit

Permalink
fix: pest()
Browse files Browse the repository at this point in the history
  • Loading branch information
nunomaduro committed Jul 6, 2024
1 parent 67dbce2 commit ccdf437
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 24 deletions.
33 changes: 11 additions & 22 deletions src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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)
);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ function uses(string ...$classAndTraits): UsesCall
*/
function pest(): Configuration
{
return Configuration::getInstance();
return new Configuration(Backtrace::file());
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/PendingCalls/UsesCall.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit ccdf437

Please sign in to comment.