Skip to content

Commit 36566f1

Browse files
committed
Revert "Merge pull request #91 from jmgoncalves97/add-continue-on-errors-option"
This reverts commit e4eeb72, reversing changes made to 5d64a01.
1 parent e4eeb72 commit 36566f1

File tree

4 files changed

+4
-72
lines changed

4 files changed

+4
-72
lines changed

README.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,6 @@ The following usage will generate routes with the basic auth specified.
5454
php artisan export:postman --basic="username:password123"
5555
```
5656

57-
The following usage will continue until the end, even if it has error or incompatible endpoints.
58-
59-
```bash
60-
php artisan export:postman --continue-on-errors
61-
```
62-
6357
If both auths are specified, bearer will be favored.
6458

6559
## Examples

phpunit.xml

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit
3-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
bootstrap="vendor/autoload.php"
5-
backupGlobals="false"
6-
colors="true"
7-
processIsolation="false"
8-
stopOnFailure="false"
9-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.4/phpunit.xsd"
10-
cacheDirectory=".phpunit.cache"
11-
backupStaticProperties="false"
12-
>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.4/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
133
<coverage/>
144
<testsuites>
155
<testsuite name="Unit">

src/Commands/ExportPostmanCommand.php

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use Illuminate\Contracts\Validation\ValidationRule;
1010
use Illuminate\Foundation\Http\FormRequest;
1111
use Illuminate\Routing\Router;
12-
use Illuminate\Support\Facades\Log;
1312
use Illuminate\Support\Facades\Storage;
1413
use Illuminate\Support\Facades\Validator;
1514
use Illuminate\Support\Str;
@@ -28,8 +27,7 @@ class ExportPostmanCommand extends Command
2827
/** @var string */
2928
protected $signature = 'export:postman
3029
{--bearer= : The bearer token to use on your endpoints}
31-
{--basic= : The basic auth to use on your endpoints}
32-
{--continue-on-errors : Continues even if an error occurs in any route, middleware or method (boolean)}';
30+
{--basic= : The basic auth to use on your endpoints}';
3331

3432
/** @var string */
3533
protected $description = 'Automatically generate a Postman collection for your API routes';
@@ -64,9 +62,6 @@ class ExportPostmanCommand extends Command
6462
'basic',
6563
];
6664

67-
/** @var bool */
68-
private $stopOnErrors = true;
69-
7065
/** @var \Illuminate\Validation\Validator */
7166
private $validator;
7267

@@ -82,14 +77,12 @@ public function handle(): void
8277
{
8378
$this->setFilename();
8479
$this->setAuthToken();
85-
$this->setOptions();
8680
$this->initializeStructure();
8781
$this->initializePhpDocParser();
8882

8983
foreach ($this->router->getRoutes() as $route) {
9084
$methods = array_filter($route->methods(), fn ($value) => $value !== 'HEAD');
91-
92-
$middlewares = $this->handleCallable(fn () => $route->gatherMiddleware());
85+
$middlewares = $route->gatherMiddleware();
9386

9487
foreach ($methods as $method) {
9588
$includedMiddleware = false;
@@ -110,7 +103,7 @@ public function handle(): void
110103

111104
$routeAction = $route->getAction();
112105

113-
$reflectionMethod = $this->handleCallable(fn () => $this->getReflectionMethod($routeAction));
106+
$reflectionMethod = $this->getReflectionMethod($routeAction);
114107

115108
if (! $reflectionMethod) {
116109
continue;
@@ -230,18 +223,6 @@ public function handle(): void
230223
$this->info('Postman Collection Exported: '.storage_path('app/'.$exportName));
231224
}
232225

233-
protected function handleCallable($callable)
234-
{
235-
try {
236-
return $callable();
237-
} catch (\Throwable $th) {
238-
if ($this->stopOnErrors) {
239-
throw $th;
240-
}
241-
Log::error($th->getMessage()."\n[stacktrace]\n".$th->getTraceAsString()."\n");
242-
}
243-
}
244-
245226
protected function getReflectionMethod(array $routeAction): ?object
246227
{
247228
// Hydrates the closure if it is an instance of Opis\Closure\SerializableClosure
@@ -508,13 +489,6 @@ protected function setAuthToken()
508489
}
509490
}
510491

511-
protected function setOptions()
512-
{
513-
if ($this->option('continue-on-errors') === true) {
514-
$this->stopOnErrors = false;
515-
}
516-
}
517-
518492
protected function isStructured()
519493
{
520494
return $this->config['structured'];

tests/Feature/ExportPostmanTest.php

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -119,32 +119,6 @@ public function test_basic_export_works(bool $formDataEnabled)
119119
}
120120
}
121121

122-
public function test_continue_on_errors_works()
123-
{
124-
$router = $this->app['router'];
125-
126-
$router->middleware('api')->group(function ($router) {
127-
$router->get('endpoint/with/error', [NonExistentController::class, 'index']);
128-
$router->get('endpoint/without/error', function () {
129-
return 'index';
130-
});
131-
});
132-
133-
$this->artisan('export:postman --continue-on-errors')->assertExitCode(0);
134-
135-
$collection = json_decode(Storage::get('postman/'.config('api-postman.filename')), true);
136-
137-
$collectionRoute = Arr::first($collection['item'], function ($item) {
138-
return $item['name'] == 'endpoint/without/error';
139-
});
140-
$this->assertNotNull($collectionRoute);
141-
142-
$collectionRoute = Arr::first($collection['item'], function ($item) {
143-
return $item['name'] == 'endpoint/with/error';
144-
});
145-
$this->assertNull($collectionRoute);
146-
}
147-
148122
/**
149123
* @dataProvider providerFormDataEnabled
150124
*/

0 commit comments

Comments
 (0)