From 9ea51caf3f74569debb1e465992e9ea916cb80fe Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Fri, 26 Jun 2020 18:17:11 +0200 Subject: [PATCH] feat: adds --version option --- composer.json | 8 ++++++- src/Pest.php | 10 +++++++++ src/Plugins/Version.php | 39 ++++++++++++++++++++++++++++++++++ tests/.snapshots/success.txt | 20 ++++++++++------- tests/Unit/Plugins/Version.php | 20 +++++++++++++++++ 5 files changed, 88 insertions(+), 9 deletions(-) create mode 100644 src/Pest.php create mode 100644 src/Plugins/Version.php create mode 100644 tests/Unit/Plugins/Version.php diff --git a/composer.json b/composer.json index 509ee8e4..7cf4955d 100644 --- a/composer.json +++ b/composer.json @@ -31,6 +31,7 @@ }, "files": [ "src/globals.php", + "src/Pest.php", "compiled/globals.php" ] }, @@ -67,7 +68,7 @@ "compile": "@php ./scripts/compile.php", "lint": "rector process src && php-cs-fixer fix -v", "test:lint": "php-cs-fixer fix -v --dry-run && rector process src --dry-run", - "test:types": "phpstan analyse --ansi", + "test:types": "phpstan analyse --ansi --memory-limit=0", "test:unit": "php bin/pest --colors=always --exclude-group=integration", "test:integration": "php bin/pest --colors=always --group=integration", "update:snapshots": "REBUILD_SNAPSHOTS=true php bin/pest --colors=always", @@ -82,6 +83,11 @@ "branch-alias": { "dev-master": "0.2.x-dev" }, + "pest": { + "plugins": [ + "Pest\\Plugins\\Version" + ] + }, "laravel": { "providers": [ "Pest\\Laravel\\PestServiceProvider" diff --git a/src/Pest.php b/src/Pest.php new file mode 100644 index 00000000..79981d1b --- /dev/null +++ b/src/Pest.php @@ -0,0 +1,10 @@ +output = $output; + } + + public function handleArguments(array $arguments): array + { + if (in_array('--version', $arguments, true)) { + $this->output->writeln( + sprintf('Pest %s', version()), + ); + } + + return $arguments; + } +} diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index 4c61fce4..8d8e3e56 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -88,12 +88,12 @@ WARN Tests\Features\Skip ✓ it do not skips - s it skips with truthy - s it skips with truthy condition by default - s it skips with message → skipped because bar - s it skips with truthy closure condition + - it skips with truthy + - it skips with truthy condition by default + - it skips with message → skipped because bar + - it skips with truthy closure condition ✓ it do not skips with falsy closure condition - s it skips with condition and message → skipped because foo + - it skips with condition and message → skipped because foo PASS Tests\Features\Test ✓ a test @@ -135,6 +135,10 @@ ✓ it throws exception when `process isolation` is true ✓ it do not throws exception when `process isolation` is false + PASS Tests\Unit\Plugins\Version + ✓ it outputs the version when --version is used + ✓ it do not outputs version when --version is not used + PASS Tests\Unit\Support\Backtrace ✓ it gets file name from called file @@ -161,7 +165,7 @@ ✓ it disable decorating printer when colors is set to never WARN Tests\Visual\Success - s visual snapshot of test suite on success + - visual snapshot of test suite on success - Tests: 6 skipped, 94 passed - Time: 3.73s + Tests: 6 skipped, 96 passed + Time: 3.56s diff --git a/tests/Unit/Plugins/Version.php b/tests/Unit/Plugins/Version.php new file mode 100644 index 00000000..6f770612 --- /dev/null +++ b/tests/Unit/Plugins/Version.php @@ -0,0 +1,20 @@ +handleArguments(['foo', '--version']); + assertEquals("Pest 0.2.2\n", $output->fetch()); +}); + +it('do not outputs version when --version is not used', function () { + $output = new BufferedOutput(); + $plugin = new Version($output); + + $plugin->handleArguments(['foo', 'bar']); + assertEquals('', $output->fetch()); +});