From 2df6654acd09600c04888287e7350ff7f313c209 Mon Sep 17 00:00:00 2001 From: James Titcumb Date: Wed, 2 Oct 2024 20:06:40 +0100 Subject: [PATCH] Improve feature description wording and outline remaining examples --- behat.yml.dist | 2 +- features/install-extensions.feature | 29 ++++++++++++----- phpcs.xml.dist | 1 + psalm.xml.dist | 1 + test/behaviour/CliContext.php | 49 ++++++++++++++++------------- 5 files changed, 53 insertions(+), 29 deletions(-) diff --git a/behat.yml.dist b/behat.yml.dist index 9d59323..d6b7a53 100644 --- a/behat.yml.dist +++ b/behat.yml.dist @@ -7,4 +7,4 @@ default: - Php\PieBehaviourTest\CliContext gherkin: filters: - tags: ~@wip + tags: "~@wip" diff --git a/features/install-extensions.feature b/features/install-extensions.feature index 8c88ced..aeacb1f 100644 --- a/features/install-extensions.feature +++ b/features/install-extensions.feature @@ -1,15 +1,30 @@ Feature: Extensions can be installed with Behat Example: The latest version of an extension can be downloaded - When I run PIE command "download asgrim/example-pie-extension" + When I run a command to download the latest version of an extension Then the latest version should have been downloaded Scenario Outline: A version matching the requested constraint can be downloaded - When I run PIE command "" - Then version "" of package "" should have been downloaded + When I run a command to download version "" of an extension + Then version "" should have been downloaded Examples: - | command | package | version | - | download xdebug/xdebug:dev-master | xdebug/xdebug | dev-master | - | download xdebug/xdebug:3.4.0alpha1@alpha | xdebug/xdebug | 3.4.0alpha1 | - | download asgrim/example-pie-extension:^2.0 | asgrim/example-pie-extension | 2.0.0 | + | constraint | version | + | dev-main | dev-main | + | 2.0.0 | 2.0.0 | + | ^2.0 | 2.0.0 | + + @wip + Example: An extension can be built + When I run a command to build an extension + Then the extension should have been built + + @wip + Example: An extension can be built with configure options + When I run a command to build an extension with configure options + Then the extension should have been built + + @wip + Example: An extension can be installed + When I run a command to install an extension + Then the extension should have been installed diff --git a/phpcs.xml.dist b/phpcs.xml.dist index b9e5857..e80678a 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -10,6 +10,7 @@ src test/unit test/integration + test/behaviour diff --git a/psalm.xml.dist b/psalm.xml.dist index cc9b3b2..1406f3e 100644 --- a/psalm.xml.dist +++ b/psalm.xml.dist @@ -13,6 +13,7 @@ + diff --git a/test/behaviour/CliContext.php b/test/behaviour/CliContext.php index 9a82768..87b0b62 100644 --- a/test/behaviour/CliContext.php +++ b/test/behaviour/CliContext.php @@ -8,46 +8,53 @@ use Behat\Behat\Context\Context; use Symfony\Component\Process\Process; use Webmozart\Assert\Assert; +use function array_merge; + +/** @psalm-api */ class CliContext implements Context { - private string|null $output; + private string|null $output = null; + private int|null $exitCode = null; - private string|null $errorOutput; - - private int|null $exitCode; - - /** - * @When I run PIE command :command - */ - public function iRunCommand(string $command) : void + /** @When I run a command to download the latest version of an extension */ + public function iRunACommandToDownloadTheLatestVersionOfAnExtension(): void { - $pieCommand = array_merge(['php', 'bin/pie'], explode(' ', $command)); + $this->runPieCommand(['download', 'asgrim/example-pie-extension']); + } + + /** @When I run a command to download version :version of an extension */ + public function iRunACommandToDownloadSpecificVersionOfAnExtension(string $version): void + { + $this->runPieCommand(['download', 'asgrim/example-pie-extension:' . $version]); + } + + /** @param list $command */ + public function runPieCommand(array $command): void + { + $pieCommand = array_merge(['php', 'bin/pie'], $command); $proc = (new Process($pieCommand))->mustRun(); - $this->output = $proc->getOutput(); - $this->errorOutput = $proc->getErrorOutput(); + $this->output = $proc->getOutput(); $this->exitCode = $proc->getExitCode(); } - /** - * @Then the latest version should have been downloaded - */ - public function theLatestVersionShouldHaveBeenDownloaded() : void + /** @Then the latest version should have been downloaded */ + public function theLatestVersionShouldHaveBeenDownloaded(): void { Assert::same(0, $this->exitCode); + Assert::notNull($this->output); Assert::regex($this->output, '#Found package: asgrim/example-pie-extension:v?\d+\.\d+\.\d+ which provides ext-example_pie_extension#'); Assert::regex($this->output, '#Extracted asgrim/example-pie-extension:v?\d+\.\d+\.\d+ source to: .+/asgrim-example-pie-extension-[a-z0-9]+#'); } - /** - * @Then version :version of package :package should have been downloaded - */ - public function versionOfTheExtensionShouldHaveBeen(string $version, string $package) + /** @Then version :version should have been downloaded */ + public function versionOfTheExtensionShouldHaveBeen(string $version): void { Assert::same(0, $this->exitCode); - Assert::contains($this->output, 'Found package: ' . $package . ':' . $version); + Assert::notNull($this->output); + Assert::contains($this->output, 'Found package: asgrim/example-pie-extension:' . $version); } }