Skip to content

Commit 06f4970

Browse files
authored
Merge pull request #2 from minicli/2.1
Version 2.1: Improved error handling, updated README with testing instructions
2 parents 280bd79 + 520448b commit 06f4970

File tree

3 files changed

+44
-5
lines changed

3 files changed

+44
-5
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
.idea
22
vendor/
3-
composer.lock

README.md

+27-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ Once the installation is finished, you can run `minicli` it with:
2727
cd myapp
2828
./minicli
2929
```
30+
If that doesn't work for you, you may have to use instead:
3031

32+
```bash
33+
php minicli
34+
```
3135
This will show you the default app signature:
3236

3337
```bash
@@ -93,6 +97,27 @@ $app->registerCommand('mycommand', function(CommandCall $input) {
9397
$app->runCommand($argv);
9498
```
9599

96-
## Created with Minicli
100+
## Tests
101+
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).
102+
103+
### Bootstrapping Tests with PestPHP
104+
105+
To get started with PestPHP to test your Minicli application, first include the required dependencies with:
106+
107+
```bash
108+
composer require pestphp/pest --dev --with-all-dependencies
109+
```
110+
111+
Then, run the following command to create a tests folder and a couple example tests:
112+
113+
```bash
114+
./vendor/bin/pest --init
115+
```
116+
117+
Then you can use the following command to run the test suite:
118+
119+
```bash
120+
./vendor/bin/pest
121+
```
97122

98-
- [Dolphin](https://github.com/do-community/dolphin) - a CLI tool for managing DigitalOcean servers with Ansible.
123+
For more details on how to test your application with PestPHP, please refer to the [official documentation](https://pestphp.com/docs/writing-tests).

minicli

+17-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,24 @@ if (php_sapi_name() !== 'cli') {
88
require __DIR__ . '/vendor/autoload.php';
99

1010
use Minicli\App;
11+
use Minicli\Exception\CommandNotFoundException;
1112

1213
$app = new App([
13-
'app_path' => __DIR__ . '/app/Command'
14+
'app_path' => __DIR__ . '/app/Command',
15+
'debug' => true
1416
]);
1517

16-
$app->runCommand($argv);
18+
try {
19+
$app->runCommand($argv);
20+
} catch (CommandNotFoundException $notFoundException) {
21+
$app->getPrinter()->error("Command Not Found.");
22+
return 1;
23+
} catch (Exception $exception) {
24+
if ($app->config->debug) {
25+
$app->getPrinter()->error("An error occurred:");
26+
$app->getPrinter()->error($exception->getMessage());
27+
}
28+
return 1;
29+
}
30+
31+
return 0;

0 commit comments

Comments
 (0)