Skip to content

Commit

Permalink
Merge pull request #2 from minicli/2.1
Browse files Browse the repository at this point in the history
Version 2.1: Improved error handling, updated README with testing instructions
  • Loading branch information
erikaheidi authored Oct 15, 2021
2 parents 280bd79 + 520448b commit 06f4970
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 5 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
.idea
vendor/
composer.lock
29 changes: 27 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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).
19 changes: 17 additions & 2 deletions minicli
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit 06f4970

Please sign in to comment.