diff --git a/composer.json b/composer.json index afdead31..a3691452 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,7 @@ "pestphp/pest-plugin-mutate": "^4.0.1", "pestphp/pest-plugin-profanity": "^4.2.1", "phpunit/phpunit": "^12.5.16", - "symfony/process": "^7.4.5|^8.0.8" + "symfony/process": "^7.4.8|^8.0.8" }, "conflict": { "filp/whoops": "<2.18.3", 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 1b8c0dcc..75439fc3 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 @@ -147,6 +147,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