From cf0b2bc3a9dbeca91307d071fa60005c9460c6c7 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Fri, 29 Dec 2023 15:18:16 +0800 Subject: [PATCH 1/5] wip Signed-off-by: Mior Muhammad Zaki --- .gitignore | 1 - composer.json | 4 +-- testbench.yaml | 8 +++++ tests/PdfReponseTest.php | 14 +------- tests/TestCase.php | 16 ++------- .../Providers/WorkbenchServiceProvider.php | 3 +- .../resources/views}/another-test.blade.php | 0 .../resources/views}/footer.blade.php | 0 .../resources/views}/header.blade.php | 0 .../resources/views}/test.blade.php | 0 workbench/routes/web.php | 36 +++++++++++++++++++ 11 files changed, 49 insertions(+), 33 deletions(-) create mode 100644 testbench.yaml rename {tests/TestSupport/Views => workbench/resources/views}/another-test.blade.php (100%) rename {tests/TestSupport/Views => workbench/resources/views}/footer.blade.php (100%) rename {tests/TestSupport/Views => workbench/resources/views}/header.blade.php (100%) rename {tests/TestSupport/Views => workbench/resources/views}/test.blade.php (100%) create mode 100644 workbench/routes/web.php diff --git a/.gitignore b/.gitignore index e6bb23c..d858abb 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,6 @@ coverage phpunit.xml phpstan.neon node_modules/ -testbench.yaml vendor node_modules tests/TestSupport/temp/ diff --git a/composer.json b/composer.json index a5c7bdc..30dd62e 100644 --- a/composer.json +++ b/composer.json @@ -52,13 +52,11 @@ }, "autoload-dev": { "psr-4": { - "Spatie\\LaravelPdf\\Tests\\": "tests/", - "Workbench\\App\\": "workbench/app/" + "Spatie\\LaravelPdf\\Tests\\": "tests/" } }, "scripts": { "post-autoload-dump": "@composer run prepare", - "clear": "@php vendor/bin/testbench package:purge-laravel-pdf --ansi", "prepare": "@php vendor/bin/testbench package:discover --ansi", "build": [ "@composer run prepare", diff --git a/testbench.yaml b/testbench.yaml new file mode 100644 index 0000000..13b650d --- /dev/null +++ b/testbench.yaml @@ -0,0 +1,8 @@ +providers: + - Spatie\LaravelPdf\PdfServiceProvider + # - Workbench\App\Providers\WorkbenchServiceProvider + +workbench: + discovers: + web: true + views: true diff --git a/tests/PdfReponseTest.php b/tests/PdfReponseTest.php index 28d1275..a954c2f 100644 --- a/tests/PdfReponseTest.php +++ b/tests/PdfReponseTest.php @@ -5,10 +5,6 @@ use function Spatie\LaravelPdf\Support\pdf; it('can inline the pdf', function () { - Route::get('inline-pdf', function () { - return pdf('test')->inline('my-custom-name.pdf'); - }); - $this ->get('inline-pdf') ->assertHeader('content-type', 'application/pdf') @@ -16,10 +12,6 @@ }); it('can download the pdf', function () { - Route::get('download-pdf', function () { - return pdf('test')->download('my-custom-name.pdf'); - }); - $this ->get('download-pdf') ->assertHeader('content-type', 'application/pdf') @@ -27,14 +19,10 @@ }); it('will tack on pdf to the filename if it is missing', function (string $method) { - Route::get('pdf', function () use ($method) { - return pdf('test')->{$method}('my-custom-name'); - }); - $headerMethod = $method === 'inline' ? 'inline' : 'attachment'; $this - ->get('pdf') + ->get("pdf/{$method}") ->assertHeader('content-disposition', $headerMethod.'; filename="my-custom-name.pdf"'); })->with(['inline', 'download']); diff --git a/tests/TestCase.php b/tests/TestCase.php index 8b30e85..400d4b0 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -2,22 +2,10 @@ namespace Spatie\LaravelPdf\Tests; +use Orchestra\Testbench\Concerns\WithWorkbench; use Orchestra\Testbench\TestCase as Orchestra; -use Spatie\LaravelPdf\PdfServiceProvider; class TestCase extends Orchestra { - protected function setUp(): void - { - parent::setUp(); - - $this->app->view->addLocation(__DIR__.'/TestSupport/Views'); - } - - protected function getPackageProviders($app) - { - return [ - PdfServiceProvider::class, - ]; - } + use WithWorkbench; } diff --git a/workbench/app/Providers/WorkbenchServiceProvider.php b/workbench/app/Providers/WorkbenchServiceProvider.php index 001d06d..e8cec9c 100644 --- a/workbench/app/Providers/WorkbenchServiceProvider.php +++ b/workbench/app/Providers/WorkbenchServiceProvider.php @@ -2,7 +2,6 @@ namespace Workbench\App\Providers; -use Illuminate\Support\Facades\Route; use Illuminate\Support\ServiceProvider; class WorkbenchServiceProvider extends ServiceProvider @@ -20,6 +19,6 @@ public function register(): void */ public function boot(): void { - Route::view('/', 'welcome'); + // } } diff --git a/tests/TestSupport/Views/another-test.blade.php b/workbench/resources/views/another-test.blade.php similarity index 100% rename from tests/TestSupport/Views/another-test.blade.php rename to workbench/resources/views/another-test.blade.php diff --git a/tests/TestSupport/Views/footer.blade.php b/workbench/resources/views/footer.blade.php similarity index 100% rename from tests/TestSupport/Views/footer.blade.php rename to workbench/resources/views/footer.blade.php diff --git a/tests/TestSupport/Views/header.blade.php b/workbench/resources/views/header.blade.php similarity index 100% rename from tests/TestSupport/Views/header.blade.php rename to workbench/resources/views/header.blade.php diff --git a/tests/TestSupport/Views/test.blade.php b/workbench/resources/views/test.blade.php similarity index 100% rename from tests/TestSupport/Views/test.blade.php rename to workbench/resources/views/test.blade.php diff --git a/workbench/routes/web.php b/workbench/routes/web.php new file mode 100644 index 0000000..881ef76 --- /dev/null +++ b/workbench/routes/web.php @@ -0,0 +1,36 @@ +{$method}('my-custom-name'); +}); + +Route::get('pdf', function () { + return pdf('test')->name('my-custom-name.pdf'); +}); + +Route::get('inline-pdf', function () { + return pdf('test')->inline('my-custom-name.pdf'); +}); + +Route::get('download-pdf', function () { + return pdf('test')->download('my-custom-name.pdf'); +}); From 8e79c64f2e2f58b009c67f7216869075aa7de5a2 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Fri, 29 Dec 2023 15:20:39 +0800 Subject: [PATCH 2/5] wip Signed-off-by: Mior Muhammad Zaki --- tests/FakePdfTest.php | 2 -- tests/PdfReponseTest.php | 3 --- 2 files changed, 5 deletions(-) diff --git a/tests/FakePdfTest.php b/tests/FakePdfTest.php index 51b18fe..8bc7372 100644 --- a/tests/FakePdfTest.php +++ b/tests/FakePdfTest.php @@ -4,8 +4,6 @@ use Spatie\LaravelPdf\Facades\Pdf; use Spatie\LaravelPdf\PdfBuilder; -use function Spatie\LaravelPdf\Support\pdf; - beforeEach(function () { Pdf::fake(); }); diff --git a/tests/PdfReponseTest.php b/tests/PdfReponseTest.php index a954c2f..edb088f 100644 --- a/tests/PdfReponseTest.php +++ b/tests/PdfReponseTest.php @@ -27,9 +27,6 @@ })->with(['inline', 'download']); it('will inline the pdf by default', function () { - Route::get('pdf', function () { - return pdf('test')->name('my-custom-name.pdf'); - }); $this ->get('pdf') From 23e004f3fdc014342a3634cdb5a81d634b4d87e9 Mon Sep 17 00:00:00 2001 From: crynobone Date: Fri, 29 Dec 2023 07:21:03 +0000 Subject: [PATCH 3/5] Fix styling --- tests/PdfReponseTest.php | 4 ---- workbench/routes/web.php | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/tests/PdfReponseTest.php b/tests/PdfReponseTest.php index edb088f..50ee83b 100644 --- a/tests/PdfReponseTest.php +++ b/tests/PdfReponseTest.php @@ -1,9 +1,5 @@ get('inline-pdf') diff --git a/workbench/routes/web.php b/workbench/routes/web.php index 881ef76..f74d858 100644 --- a/workbench/routes/web.php +++ b/workbench/routes/web.php @@ -19,7 +19,7 @@ return view('welcome'); }); -Route::get("pdf/{method}", function ($method) { +Route::get('pdf/{method}', function ($method) { return pdf('test')->{$method}('my-custom-name'); }); From 8b2cf09918a0fe38f93da9ec49088875094bd787 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Fri, 29 Dec 2023 15:24:52 +0800 Subject: [PATCH 4/5] wip Signed-off-by: Mior Muhammad Zaki --- phpunit.xml.dist | 3 +++ 1 file changed, 3 insertions(+) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 5235005..cd42cea 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -28,4 +28,7 @@ ./src + + + From 2f6c36a9e995d6e851c03f09d4f038c78751e0cc Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Fri, 29 Dec 2023 15:26:37 +0800 Subject: [PATCH 5/5] wip Signed-off-by: Mior Muhammad Zaki --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 30dd62e..e1d7fb7 100644 --- a/composer.json +++ b/composer.json @@ -62,7 +62,7 @@ "@composer run prepare", "@php vendor/bin/testbench workbench:build --ansi" ], - "start": [ + "serve": [ "Composer\\Config::disableProcessTimeout", "@composer run build", "@php vendor/bin/testbench serve"