From 179848064db7d3c15b07088f68785b5c87ef995b Mon Sep 17 00:00:00 2001 From: Erika Heidi Date: Fri, 15 Oct 2021 14:46:45 +0200 Subject: [PATCH 1/2] removing lock from gitignore, adding exception catch --- .gitignore | 1 - minicli | 19 +++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 157ff0c..f2ecd3c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ .idea vendor/ -composer.lock diff --git a/minicli b/minicli index 657b85d..0c3c81a 100755 --- a/minicli +++ b/minicli @@ -8,9 +8,24 @@ if (php_sapi_name() !== 'cli') { require __DIR__ . '/vendor/autoload.php'; use Minicli\App; +use Minicli\Exception\CommandNotFoundException; $app = new App([ - 'app_path' => __DIR__ . '/app/Command' + 'app_path' => __DIR__ . '/app/Command', + 'debug' => true ]); -$app->runCommand($argv); +try { + $app->runCommand($argv); +} catch (CommandNotFoundException $notFoundException) { + $app->getPrinter()->error("Command Not Found."); + return 1; +} catch (Exception $exception) { + if ($app->config->debug) { + $app->getPrinter()->error("An error occurred:"); + $app->getPrinter()->error($exception->getMessage()); + } + return 1; +} + +return 0; \ No newline at end of file From 520448bd4f1c942de1d22c0e1585e0c63e9edf61 Mon Sep 17 00:00:00 2001 From: Erika Heidi Date: Fri, 15 Oct 2021 17:04:39 +0200 Subject: [PATCH 2/2] Updated Readme --- README.md | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4490daa..202730f 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,11 @@ Once the installation is finished, you can run `minicli` it with: cd myapp ./minicli ``` +If that doesn't work for you, you may have to use instead: +```bash +php minicli +``` This will show you the default app signature: ```bash @@ -93,6 +97,27 @@ $app->registerCommand('mycommand', function(CommandCall $input) { $app->runCommand($argv); ``` -## Created with Minicli +## Tests +To keep dependencies to a minimum, the `minicli/application` template repository doesn't require any specific testing framework, but we highly recommend using [PestPHP](https://pestphp.com), which is the testing framework used by [minicli/minicli](https://github.com/minicli/minicli). + +### Bootstrapping Tests with PestPHP + +To get started with PestPHP to test your Minicli application, first include the required dependencies with: + +```bash +composer require pestphp/pest --dev --with-all-dependencies +``` + +Then, run the following command to create a tests folder and a couple example tests: + +```bash +./vendor/bin/pest --init +``` + +Then you can use the following command to run the test suite: + +```bash +./vendor/bin/pest +``` -- [Dolphin](https://github.com/do-community/dolphin) - a CLI tool for managing DigitalOcean servers with Ansible. +For more details on how to test your application with PestPHP, please refer to the [official documentation](https://pestphp.com/docs/writing-tests).