Skip to content

Commit

Permalink
Merge pull request #1 from crynobone/workbench
Browse files Browse the repository at this point in the history
Workbench Improvements
  • Loading branch information
freekmurze authored Dec 29, 2023
2 parents 85558aa + 2f6c36a commit ab16cd0
Show file tree
Hide file tree
Showing 13 changed files with 53 additions and 43 deletions.
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');
}

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');
//
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
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');
});

0 comments on commit ab16cd0

Please sign in to comment.