Skip to content

Commit 5fefe94

Browse files
Laravel 13.x Compatibility (#121)
* Bump dependencies for Laravel 13 * Update GitHub Actions for Laravel 13 * fix tests * lint fixes --------- Co-authored-by: Andreas Elia <andreaselia@live.co.uk>
1 parent 1bf62b7 commit 5fefe94

File tree

7 files changed

+56
-49
lines changed

7 files changed

+56
-49
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,22 @@ on:
99
jobs:
1010
tests:
1111
runs-on: ubuntu-latest
12+
1213
strategy:
1314
fail-fast: true
1415
matrix:
15-
testbench: ['^8.0']
16+
testbench: [^8.0, ^11.0]
17+
1618
name: Testbench ${{ matrix.testbench }}
19+
1720
steps:
1821
- uses: actions/checkout@v2
22+
1923
- name: Install Dependencies
2024
run: php /usr/bin/composer install -q --no-ansi --no-interaction --no-scripts --no-suggest --no-progress --prefer-dist
25+
2126
- name: Install Testbench
2227
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 }}
28+
2329
- name: Execute tests via PHPUnit
2430
run: php vendor/bin/phpunit --stop-on-failure

composer.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@
2929
"require": {
3030
"php": "^7.4|^8.0",
3131
"ext-json": "*",
32-
"illuminate/config": "^7.0|^8.0|^9.0|^10.0|^11.0|^12.0",
33-
"illuminate/console": "^7.0|^8.0|^9.0|^10.0|^11.0|^12.0",
34-
"illuminate/contracts": "^7.0|^8.0|^9.0|^10.0|^11.0|^12.0",
35-
"illuminate/support": "^7.0|^8.0|^9.0|^10.0|^11.0|^12.0",
36-
"illuminate/routing": "^7.0|^8.0|^9.0|^10.0|^11.0|^12.0",
32+
"illuminate/config": "^7.0|^8.0|^9.0|^10.0|^11.0|^12.0|^13.0",
33+
"illuminate/console": "^7.0|^8.0|^9.0|^10.0|^11.0|^12.0|^13.0",
34+
"illuminate/contracts": "^7.0|^8.0|^9.0|^10.0|^11.0|^12.0|^13.0",
35+
"illuminate/support": "^7.0|^8.0|^9.0|^10.0|^11.0|^12.0|^13.0",
36+
"illuminate/routing": "^7.0|^8.0|^9.0|^10.0|^11.0|^12.0|^13.0",
3737
"phpstan/phpdoc-parser": "^1.26|^2.0"
3838
},
3939
"extra": {
@@ -46,8 +46,8 @@
4646
"minimum-stability": "dev",
4747
"prefer-stable": true,
4848
"require-dev": {
49-
"orchestra/testbench": "^8.0|^9.0",
50-
"phpunit/phpunit": "^10.0|^11.0",
49+
"orchestra/testbench": "^8.0|^9.0|^11.0",
50+
"phpunit/phpunit": "^10.0|^11.0|^12.5.12",
5151
"laravel/pint": "^1.13"
5252
}
5353
}

src/Commands/ExportPostmanCommand.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace AndreasElia\PostmanGenerator\Commands;
44

5+
use AndreasElia\PostmanGenerator\Authentication\Basic;
6+
use AndreasElia\PostmanGenerator\Authentication\Bearer;
57
use AndreasElia\PostmanGenerator\Exporter;
68
use Illuminate\Console\Command;
79
use Illuminate\Support\Facades\Storage;
@@ -34,11 +36,11 @@ public function handle(Exporter $exporter): void
3436
->to($filename)
3537
->setAuthentication(value(function () {
3638
if (filled($this->option('bearer'))) {
37-
return new \AndreasElia\PostmanGenerator\Authentication\Bearer($this->option('bearer'));
39+
return new Bearer($this->option('bearer'));
3840
}
3941

4042
if (filled($this->option('basic'))) {
41-
return new \AndreasElia\PostmanGenerator\Authentication\Basic($this->option('basic'));
43+
return new Basic($this->option('basic'));
4244
}
4345

4446
return null;

src/Processors/DocBlockProcessor.php

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,43 @@
33
namespace AndreasElia\PostmanGenerator\Processors;
44

55
use Illuminate\Support\Str;
6-
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTextNode;
7-
use PHPStan\PhpDocParser\Lexer\Lexer;
8-
use PHPStan\PhpDocParser\Parser\ConstExprParser;
9-
use PHPStan\PhpDocParser\Parser\PhpDocParser;
10-
use PHPStan\PhpDocParser\Parser\TokenIterator;
11-
use PHPStan\PhpDocParser\Parser\TypeParser;
126
use ReflectionFunction;
137
use ReflectionMethod;
14-
use Throwable;
158

169
class DocBlockProcessor
1710
{
1811
public function __invoke(ReflectionMethod|ReflectionFunction $reflectionMethod): string
1912
{
20-
try {
21-
$lexer = new Lexer;
22-
$constExprParser = new ConstExprParser;
23-
$parser = new PhpDocParser(new TypeParser($constExprParser), $constExprParser);
24-
25-
$description = '';
26-
$comment = $reflectionMethod->getDocComment();
27-
$tokens = new TokenIterator($lexer->tokenize($comment));
28-
$phpDocNode = $parser->parse($tokens);
29-
30-
foreach ($phpDocNode->children as $child) {
31-
if ($child instanceof PhpDocTextNode) {
32-
$description .= ' '.$child->text;
33-
}
34-
}
13+
$comment = $reflectionMethod->getDocComment();
3514

36-
return Str::squish($description);
37-
} catch (Throwable $e) {
15+
if (! $comment) {
3816
return '';
3917
}
18+
19+
$description = collect(preg_split('/\R/', $comment) ?: [])
20+
->map(function (string $line) {
21+
$line = trim($line);
22+
23+
if (in_array($line, ['/**', '/*', '*/', '*'], true)) {
24+
return '';
25+
}
26+
27+
if (Str::startsWith($line, ['/**', '/*'])) {
28+
$line = ltrim(substr($line, 3));
29+
} elseif (Str::startsWith($line, '*')) {
30+
$line = ltrim(substr($line, 1));
31+
}
32+
33+
if (Str::endsWith($line, '*/')) {
34+
$line = rtrim(substr($line, 0, -2));
35+
}
36+
37+
return $line;
38+
})
39+
->reject(fn (string $line) => $line === '')
40+
->reject(fn (string $line) => Str::startsWith($line, '@'))
41+
->implode(' ');
42+
43+
return Str::squish($description);
4044
}
4145
}

tests/Feature/ExportPostmanTest.php

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use AndreasElia\PostmanGenerator\Tests\TestCase;
77
use Illuminate\Support\Arr;
88
use Illuminate\Support\Facades\Storage;
9+
use PHPUnit\Framework\Attributes\DataProvider;
910

1011
class ExportPostmanTest extends TestCase
1112
{
@@ -20,9 +21,7 @@ protected function setUp(): void
2021
Storage::disk()->deleteDirectory('postman');
2122
}
2223

23-
/**
24-
* @dataProvider providerFormDataEnabled
25-
*/
24+
#[DataProvider('providerFormDataEnabled')]
2625
public function test_standard_export_works(bool $formDataEnabled)
2726
{
2827
config()->set('api-postman.enable_formdata', $formDataEnabled);
@@ -57,9 +56,7 @@ public function test_standard_export_works(bool $formDataEnabled)
5756
}
5857
}
5958

60-
/**
61-
* @dataProvider providerFormDataEnabled
62-
*/
59+
#[DataProvider('providerFormDataEnabled')]
6360
public function test_bearer_export_works(bool $formDataEnabled)
6461
{
6562
config()->set('api-postman.enable_formdata', $formDataEnabled);
@@ -104,9 +101,7 @@ public function test_bearer_export_works(bool $formDataEnabled)
104101
}
105102
}
106103

107-
/**
108-
* @dataProvider providerFormDataEnabled
109-
*/
104+
#[DataProvider('providerFormDataEnabled')]
110105
public function test_basic_export_works(bool $formDataEnabled)
111106
{
112107
config()->set('api-postman.enable_formdata', $formDataEnabled);
@@ -151,9 +146,7 @@ public function test_basic_export_works(bool $formDataEnabled)
151146
}
152147
}
153148

154-
/**
155-
* @dataProvider providerFormDataEnabled
156-
*/
149+
#[DataProvider('providerFormDataEnabled')]
157150
public function test_structured_export_works(bool $formDataEnabled)
158151
{
159152
config([
@@ -316,7 +309,7 @@ public function test_php_doc_comment_export()
316309
->where('name', 'example/phpDocRoute')
317310
->first();
318311

319-
$this->assertEquals($targetRequest['request']['description'], 'This is the php doc route. Which is also multi-line. and has a blank line.');
312+
$this->assertSame('This is the php doc route. Which is also multi-line. and has a blank line.', $targetRequest['request']['description']);
320313
}
321314

322315
public function test_uri_is_correct()

tests/Feature/ExportPostmanWithCacheTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
use AndreasElia\PostmanGenerator\Tests\TestCase;
66
use Illuminate\Support\Arr;
77
use Illuminate\Support\Facades\Storage;
8+
use Orchestra\Testbench\Concerns\HandlesRoutes;
89

910
class ExportPostmanWithCacheTest extends TestCase
1011
{
11-
use \Orchestra\Testbench\Concerns\HandlesRoutes;
12+
use HandlesRoutes;
1213

1314
protected function setUp(): void
1415
{

tests/Fixtures/UppercaseRule.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44

55
use Closure;
66
use Illuminate\Contracts\Validation\ValidationRule;
7+
use Illuminate\Translation\PotentiallyTranslatedString;
78

89
class UppercaseRule implements ValidationRule
910
{
1011
/**
1112
* Run the validation rule.
1213
*
13-
* @param \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail
14+
* @param Closure(string): PotentiallyTranslatedString $fail
1415
*/
1516
public function validate(string $attribute, mixed $value, Closure $fail): void
1617
{

0 commit comments

Comments
 (0)