Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workbench Improvements #1

Merged
merged 6 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ coverage
phpunit.xml
phpstan.neon
node_modules/
testbench.yaml
vendor
node_modules
tests/TestSupport/temp/
Expand Down
6 changes: 2 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,17 @@
},
"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",
"@php vendor/bin/testbench workbench:build --ansi"
],
"start": [
"serve": [
"Composer\\Config::disableProcessTimeout",
"@composer run build",
"@php vendor/bin/testbench serve"
Expand Down
3 changes: 3 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,7 @@
<directory suffix=".php">./src</directory>
</include>
</source>
<php>
<env name="APP_KEY" value="AckfSECXIvnK5r28GVIWUAxmbBSjTsmF"/>
</php>
</phpunit>
8 changes: 8 additions & 0 deletions testbench.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
providers:
- Spatie\LaravelPdf\PdfServiceProvider
# - Workbench\App\Providers\WorkbenchServiceProvider

workbench:
discovers:
web: true
views: true
2 changes: 0 additions & 2 deletions tests/FakePdfTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
use Spatie\LaravelPdf\Facades\Pdf;
use Spatie\LaravelPdf\PdfBuilder;

use function Spatie\LaravelPdf\Support\pdf;

beforeEach(function () {
Pdf::fake();
});
Expand Down
21 changes: 1 addition & 20 deletions tests/PdfReponseTest.php
Original file line number Diff line number Diff line change
@@ -1,47 +1,28 @@
<?php

use Illuminate\Support\Facades\Route;

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')
->assertHeader('content-disposition', 'inline; filename="my-custom-name.pdf"');
});

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')
->assertHeader('content-disposition', 'attachment; filename="my-custom-name.pdf"');
});

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']);

it('will inline the pdf by default', function () {
Route::get('pdf', function () {
return pdf('test')->name('my-custom-name.pdf');
});

$this
->get('pdf')
Expand Down
16 changes: 2 additions & 14 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now can be auto-discovered if we use workbench/resources/views and update testbench.yaml:

discovers:
  views: true

}

protected function getPackageProviders($app)
{
return [
PdfServiceProvider::class,
];
}
use WithWorkbench;
}
3 changes: 1 addition & 2 deletions workbench/app/Providers/WorkbenchServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Workbench\App\Providers;

use Illuminate\Support\Facades\Route;
use Illuminate\Support\ServiceProvider;

class WorkbenchServiceProvider extends ServiceProvider
Expand All @@ -20,6 +19,6 @@ public function register(): void
*/
public function boot(): void
{
Route::view('/', 'welcome');
//
}
}
36 changes: 36 additions & 0 deletions workbench/routes/web.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

use Illuminate\Support\Facades\Route;

use function Spatie\LaravelPdf\Support\pdf;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/

Route::get('/', function () {
return view('welcome');
});

Route::get('pdf/{method}', function ($method) {
return pdf('test')->{$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');
});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automatically available within tests and can be previewed using composer run serve, registered to Testbench via testbench.yaml:

discovers:
  web: true