Skip to content

Commit 3fbcfc2

Browse files
authored
Merge pull request #79 from almightynassar/master
[fix] Updated to include the new Closure (Laravel 9.x support)
2 parents ec35f26 + fa51a59 commit 3fbcfc2

File tree

3 files changed

+63
-2
lines changed

3 files changed

+63
-2
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,16 @@ on:
99
jobs:
1010
tests:
1111
runs-on: ubuntu-latest
12+
strategy:
13+
fail-fast: true
14+
matrix:
15+
testbench: ['^6.12', '^7.19']
16+
name: Testbench ${{ matrix.testbench }}
1217
steps:
1318
- uses: actions/checkout@v2
1419
- name: Install Dependencies
1520
run: php /usr/bin/composer install -q --no-ansi --no-interaction --no-scripts --no-suggest --no-progress --prefer-dist
21+
- name: Install Testbench
22+
run: php /usr/bin/composer require -q --dev -W --no-ansi --no-interaction --no-scripts --no-suggest --no-progress --prefer-dist orchestra/testbench:${{ matrix.testbench }}
1623
- name: Execute tests via PHPUnit
1724
run: php vendor/bin/phpunit --stop-on-failure

src/Commands/ExportPostmanCommand.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,7 @@ protected function getReflectionMethod(array $routeAction): ?object
213213

214214
public static function containsSerializedClosure(array $action): bool
215215
{
216-
return is_string($action['uses']) &&
217-
Str::startsWith($action['uses'], 'C:32:"Opis\\Closure\\SerializableClosure') !== false;
216+
return is_string($action['uses']) && Str::startsWith($action['uses'], ['C:32:"Opis\\Closure\\SerializableClosure', 'O:47:"Laravel\SerializableClosure\SerializableClosure']);
218217
}
219218

220219
protected function buildTree(array &$routes, array $segments, array $request): void
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
namespace AndreasElia\PostmanGenerator\Tests\Feature;
4+
5+
use AndreasElia\PostmanGenerator\Tests\TestCase;
6+
use Illuminate\Support\Arr;
7+
use Illuminate\Support\Facades\Storage;
8+
9+
class ExportPostmanWithCacheTest extends TestCase
10+
{
11+
use \Orchestra\Testbench\Concerns\HandlesRoutes;
12+
13+
protected function setUp(): void
14+
{
15+
parent::setUp();
16+
17+
$this->defineCacheRoutes(<<<'PHP'
18+
<?php
19+
Route::middleware('api')->group(function () {
20+
Route::get('serialized-route', function () {
21+
return 'Serialized Route';
22+
});
23+
});
24+
PHP);
25+
26+
config()->set('api-postman.filename', 'test.json');
27+
28+
Storage::disk()->deleteDirectory('postman');
29+
}
30+
31+
public function test_cached_export_works()
32+
{
33+
$this->get('serialized-route')
34+
->assertOk()
35+
->assertSee('Serialized Route');
36+
37+
$this->artisan('export:postman')->assertExitCode(0);
38+
39+
$collection = json_decode(Storage::get('postman/'.config('api-postman.filename')), true);
40+
41+
$routes = $this->app['router']->getRoutes();
42+
43+
$collectionItems = $collection['item'];
44+
45+
$this->assertCount(count($routes), $collectionItems);
46+
47+
foreach ($routes as $route) {
48+
$collectionRoute = Arr::first($collectionItems, function ($item) use ($route) {
49+
return $item['name'] == $route->uri();
50+
});
51+
$this->assertNotNull($collectionRoute);
52+
$this->assertTrue(in_array($collectionRoute['request']['method'], $route->methods()));
53+
}
54+
}
55+
}

0 commit comments

Comments
 (0)