Skip to content

Commit

Permalink
Merge pull request #79 from almightynassar/master
Browse files Browse the repository at this point in the history
[fix] Updated to include the new Closure (Laravel 9.x support)
  • Loading branch information
tomirons committed Jan 25, 2023
2 parents ec35f26 + fa51a59 commit 3fbcfc2
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 2 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,16 @@ on:
jobs:
tests:
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
testbench: ['^6.12', '^7.19']
name: Testbench ${{ matrix.testbench }}
steps:
- uses: actions/checkout@v2
- name: Install Dependencies
run: php /usr/bin/composer install -q --no-ansi --no-interaction --no-scripts --no-suggest --no-progress --prefer-dist
- name: Install Testbench
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 }}
- name: Execute tests via PHPUnit
run: php vendor/bin/phpunit --stop-on-failure
3 changes: 1 addition & 2 deletions src/Commands/ExportPostmanCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,7 @@ protected function getReflectionMethod(array $routeAction): ?object

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

protected function buildTree(array &$routes, array $segments, array $request): void
Expand Down
55 changes: 55 additions & 0 deletions tests/Feature/ExportPostmanWithCacheTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace AndreasElia\PostmanGenerator\Tests\Feature;

use AndreasElia\PostmanGenerator\Tests\TestCase;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Storage;

class ExportPostmanWithCacheTest extends TestCase
{
use \Orchestra\Testbench\Concerns\HandlesRoutes;

protected function setUp(): void
{
parent::setUp();

$this->defineCacheRoutes(<<<'PHP'
<?php
Route::middleware('api')->group(function () {
Route::get('serialized-route', function () {
return 'Serialized Route';
});
});
PHP);

config()->set('api-postman.filename', 'test.json');

Storage::disk()->deleteDirectory('postman');
}

public function test_cached_export_works()
{
$this->get('serialized-route')
->assertOk()
->assertSee('Serialized Route');

$this->artisan('export:postman')->assertExitCode(0);

$collection = json_decode(Storage::get('postman/'.config('api-postman.filename')), true);

$routes = $this->app['router']->getRoutes();

$collectionItems = $collection['item'];

$this->assertCount(count($routes), $collectionItems);

foreach ($routes as $route) {
$collectionRoute = Arr::first($collectionItems, function ($item) use ($route) {
return $item['name'] == $route->uri();
});
$this->assertNotNull($collectionRoute);
$this->assertTrue(in_array($collectionRoute['request']['method'], $route->methods()));
}
}
}

0 comments on commit 3fbcfc2

Please sign in to comment.