Skip to content

Commit

Permalink
Merge branch 'main' of github.com:spatie/laravel-pdf
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze committed Dec 26, 2023
2 parents 4b0b249 + 2c4c9b9 commit 1ee2a08
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 20 deletions.
8 changes: 7 additions & 1 deletion src/Pdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,17 @@
class Pdf implements Responsable
{
public string $viewName = '';

public array $data = [];

public string $html = '';

public string $downloadName = '';

public bool $inline = false;

public ?string $paperFormat = null;

public ?string $orientation = null;

public ?array $margins = null;
Expand Down Expand Up @@ -136,7 +142,7 @@ protected function getBrowsershot(): Browsershot
$browsershot = Browsershot::html($this->getHtml());

if ($this->margins) {
$browsershot->margins(... $this->margins);
$browsershot->margins(...$this->margins);
}

if ($this->paperFormat) {
Expand Down
2 changes: 1 addition & 1 deletion tests/FakePdfTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use Spatie\LaravelPdf\Facades\Pdf;

it('can determine the view that was used', function() {
it('can determine the view that was used', function () {
Pdf::fake();

Pdf::view('test');
Expand Down
29 changes: 15 additions & 14 deletions tests/PdfTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
use Spatie\Browsershot\Browsershot;
use Spatie\LaravelPdf\Enums\Orientation;
use Spatie\LaravelPdf\Enums\PaperFormat;
use function Spatie\LaravelPdf\Support\pdf;
use Spatie\LaravelPdf\Facades\Pdf;

beforeEach(function() {
use function Spatie\LaravelPdf\Support\pdf;

beforeEach(function () {
$this->targetPath = getTempPath('test.pdf');
});

Expand All @@ -22,46 +23,46 @@
assertMatchesPdfSnapshot($this->targetPath);
});

it('can accept some html', function() {
it('can accept some html', function () {
Pdf::html('<h1>Some custom HTML</h1>')->save($this->targetPath);

assertMatchesPdfSnapshot($this->targetPath);
});

it('can create a pdf using the facade', function() {
Pdf::view('test')->save($this->targetPath);
it('can create a pdf using the facade', function () {
Pdf::view('test')->save($this->targetPath);

assertMatchesPdfSnapshot($this->targetPath);
});

it('can return the base 64 encoded pdf', function() {
it('can return the base 64 encoded pdf', function () {
$base64string = Pdf::view('test')->base64();

expect($base64string)->toBeString();
});

it('can accept the paper format', function() {
it('can accept the paper format', function () {
Pdf::view('test')
->paperFormat(PaperFormat::A3)
->save($this->targetPath);

assertMatchesPdfSnapshot($this->targetPath);
});

it('can accept the orientation', function() {
it('can accept the orientation', function () {
Pdf::view('test')
->orientation(Orientation::Landscape)
->save($this->targetPath);

assertMatchesPdfSnapshot($this->targetPath);
});

it('can customize browsershot', function() {
Pdf::view('test')
->withBrowsershot(function(Browsershot $browsershot) {
$browsershot->landscape();
})
->save($this->targetPath);
it('can customize browsershot', function () {
Pdf::view('test')
->withBrowsershot(function (Browsershot $browsershot) {
$browsershot->landscape();
})
->save($this->targetPath);

assertMatchesPdfSnapshot($this->targetPath);
});
4 changes: 2 additions & 2 deletions tests/Pest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use Spatie\LaravelPdf\Tests\TestCase;
use Spatie\TemporaryDirectory\TemporaryDirectory;

use function Spatie\Snapshots\assertMatchesImageSnapshot;

uses(TestCase::class)
Expand All @@ -19,7 +20,6 @@
})
->in(__DIR__);


function getTestSupportPath($suffix = ''): string
{
return __DIR__."/TestSupport/{$suffix}";
Expand All @@ -32,7 +32,7 @@ function getTempPath($suffix = ''): string

function assertMatchesPdfSnapshot(string $pdfPath): void
{
$imagePath = getTempPath('test' . '.png');
$imagePath = getTempPath('test'.'.png');

$imagick = new Imagick($pdfPath);
$imagick->setImageFormat('png');
Expand Down
2 changes: 0 additions & 2 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

namespace Spatie\LaravelPdf\Tests;

use Illuminate\Database\Eloquent\Factories\Factory;
use Orchestra\Testbench\TestCase as Orchestra;
use Spatie\LaravelPdf\LaravelPdfServiceProvider;
use Spatie\LaravelPdf\PdfServiceProvider;

class TestCase extends Orchestra
Expand Down

0 comments on commit 1ee2a08

Please sign in to comment.