diff --git a/src/Factories/TestCaseFactory.php b/src/Factories/TestCaseFactory.php index 7db0bcfa..c2f61e40 100644 --- a/src/Factories/TestCaseFactory.php +++ b/src/Factories/TestCaseFactory.php @@ -59,6 +59,11 @@ final class TestCaseFactory Concerns\Expectable::class, ]; + /** + * The namespace for the test case, overrides the path-based namespace when set. + */ + public ?string $namespace = null; + /** * Creates a new Factory instance. */ @@ -127,7 +132,7 @@ final class TestCaseFactory $partsFQN = explode('\\', $classFQN); $className = array_pop($partsFQN); - $namespace = implode('\\', $partsFQN); + $namespace = $this->namespace ?? implode('\\', $partsFQN); $baseClass = sprintf('\%s', $this->class); if (trim($className) === '') { diff --git a/src/Plugins/Concerns/HandleArguments.php b/src/Plugins/Concerns/HandleArguments.php index 9cf5e606..6fdcff8c 100644 --- a/src/Plugins/Concerns/HandleArguments.php +++ b/src/Plugins/Concerns/HandleArguments.php @@ -56,4 +56,31 @@ trait HandleArguments return array_values(array_flip($arguments)); } + + /** + * Pops the given argument and its value from the arguments, returning the value. + * + * @param array $arguments + */ + public function popArgumentValue(string $argument, array &$arguments): ?string + { + foreach ($arguments as $key => $value) { + if (str_contains($value, "$argument=")) { + unset($arguments[$key]); + $arguments = array_values($arguments); + + return substr($value, strlen($argument) + 1); + } + + if ($value === $argument && isset($arguments[$key + 1])) { + $result = $arguments[$key + 1]; + unset($arguments[$key], $arguments[$key + 1]); + $arguments = array_values($arguments); + + return $result; + } + } + + return null; + } } diff --git a/src/Plugins/Help.php b/src/Plugins/Help.php index 096f2914..a2fb1ef0 100644 --- a/src/Plugins/Help.php +++ b/src/Plugins/Help.php @@ -107,6 +107,13 @@ final readonly class Help implements HandlesArguments 'desc' => 'Initialise a standard Pest configuration', ]], ...$content['Configuration']]; + $content['AI'] = [ + [ + 'arg' => '--ai', + 'desc' => 'Run a code snippet as a fully scaffolded test for AI verification', + ], + ]; + $content['Execution'] = [...[ [ 'arg' => '--parallel', diff --git a/src/Repositories/TestRepository.php b/src/Repositories/TestRepository.php index 466d3226..cfce2cf1 100644 --- a/src/Repositories/TestRepository.php +++ b/src/Repositories/TestRepository.php @@ -113,6 +113,16 @@ final class TestRepository $this->testCaseMethodFilters[] = $filter; } + /** + * Gets the class and traits configured for the given directory path. + * + * @return array + */ + public function getUsesForPath(string $path): array + { + return $this->uses[$path][0] ?? []; + } + /** * Gets the test case factory from the given filename. */ diff --git a/tests/.pest/snapshots/Visual/Help/visual_snapshot_of_help_command_output.snap b/tests/.pest/snapshots/Visual/Help/visual_snapshot_of_help_command_output.snap index c04572a3..7eeddd2f 100644 --- a/tests/.pest/snapshots/Visual/Help/visual_snapshot_of_help_command_output.snap +++ b/tests/.pest/snapshots/Visual/Help/visual_snapshot_of_help_command_output.snap @@ -148,6 +148,9 @@ --disable-coverage-ignore ...... Disable metadata for ignoring code coverage --no-coverage Ignore code coverage reporting configured in the XML configuration file + AI OPTIONS: + --ai ..... Run a code snippet as a fully scaffolded test for AI verification + MUTATION TESTING OPTIONS: --mutate .... Runs mutation testing, to understand the quality of your tests --mutate --parallel ...................... Runs mutation testing in parallel