Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze committed Dec 28, 2023
2 parents 98a3fb5 + a34e13b commit 510b01a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 27 deletions.
10 changes: 2 additions & 8 deletions src/FakePdfBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ class FakePdfBuilder extends PdfBuilder
/** @var array<int, \Spatie\LaravelPdf\PdfBuilder> */
protected array $savedPdfs = [];



public function save(string $path): self
{
$this->getBrowsershot();
Expand Down Expand Up @@ -92,7 +90,7 @@ public function assertSaved(string|callable $path): void
}

$callable = $path;
foreach($this->savedPdfs as $savedPdf) {
foreach ($this->savedPdfs as $savedPdf) {
$result = $callable($savedPdf['pdf'], $savedPdf['path']);

if ($result === true) {
Expand All @@ -102,7 +100,7 @@ public function assertSaved(string|callable $path): void
}
}

Assert::fail("Did not save a PDF that matched the expectations");
Assert::fail('Did not save a PDF that matched the expectations');
}

public function assertSee(string $text): void
Expand All @@ -118,8 +116,6 @@ public function assertSee(string $text): void
Assert::fail("Did not save a PDF that contains `{$text}`");
}



public function assertRespondedWithPdf(Closure $expectations): void
{
Assert::assertNotEmpty($this->respondedWithPdf);
Expand All @@ -137,8 +133,6 @@ public function assertRespondedWithPdf(Closure $expectations): void
Assert::fail('Did not respond with a PDF that matched the expectations');
}



protected function markAssertionPassed(): void
{
Assert::assertTrue(true);
Expand Down
1 change: 0 additions & 1 deletion src/PdfServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Spatie\LaravelPackageTools\Package;
use Spatie\LaravelPackageTools\PackageServiceProvider;
use Spatie\LaravelPdf\Facades\Pdf;

class PdfServiceProvider extends PackageServiceProvider
{
Expand Down
34 changes: 17 additions & 17 deletions tests/FakePdfTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@
Pdf::assertSaved('non-existing.pdf');
})->fails();

it('can determine that a pdf was saved with certain properties', function() {
Pdf::view('test')->save('my-custom-name.pdf');
it('can determine that a pdf was saved with certain properties', function () {
Pdf::view('test')->save('my-custom-name.pdf');

Pdf::view('another-test')->save('my-other-custom-name.pdf');
Pdf::view('another-test')->save('my-other-custom-name.pdf');

Pdf::assertSaved('my-custom-name.pdf', function (PdfBuilder $pdf) {
return $pdf->viewName === 'test';
return $pdf->viewName === 'test';
});
});

Expand Down Expand Up @@ -105,45 +105,45 @@
});
})->fails();

it('can determine if a pdf was saved with certain properties', function() {
Pdf::view('test', ['foo'=> 'bar'])->save('hey.pdf');
it('can determine if a pdf was saved with certain properties', function () {
Pdf::view('test', ['foo' => 'bar'])->save('hey.pdf');

Pdf::assertSaved(function(PdfBuilder $pdf) {
Pdf::assertSaved(function (PdfBuilder $pdf) {
return $pdf->viewName === 'test';
});
});

it('can determine if a pdf was not saved with certain properties', function() {
Pdf::view('test', ['foo'=> 'bar'])->save('hey.pdf');
it('can determine if a pdf was not saved with certain properties', function () {
Pdf::view('test', ['foo' => 'bar'])->save('hey.pdf');

Pdf::assertSaved(function(PdfBuilder $pdf) {
Pdf::assertSaved(function (PdfBuilder $pdf) {
return $pdf->viewName === 'non-existing-view';
});
})->fails();

it('it will not combine properties of different instances', function() {
Pdf::view('test', ['foo'=> 'bar'])->save('first.pdf');
it('it will not combine properties of different instances', function () {
Pdf::view('test', ['foo' => 'bar'])->save('first.pdf');

Pdf::view('another-test')->save('second.pdf');

Pdf::assertSaved(function(PdfBuilder $pdf) {
Pdf::assertSaved(function (PdfBuilder $pdf) {
return $pdf->viewName === 'another-test'
&& array_key_exists('foo', $pdf->viewData);
});
})->fails();

it('can verify that a pdf was saved a given path', function() {
it('can verify that a pdf was saved a given path', function () {
Pdf::view('test')->save('my-name.pdf');

Pdf::assertSaved(function(PdfBuilder $pdf, string $path) {
Pdf::assertSaved(function (PdfBuilder $pdf, string $path) {
return $path === 'my-name.pdf';
});
});

it('can verify that a pdf was not saved a given path', function() {
it('can verify that a pdf was not saved a given path', function () {
Pdf::view('test')->save('my-name.pdf');

Pdf::assertSaved(function(PdfBuilder $pdf, string $path) {
Pdf::assertSaved(function (PdfBuilder $pdf, string $path) {
return $path === 'non-existing-path';
});
})->fails();
1 change: 0 additions & 1 deletion tests/Pest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php

use PHPUnit\Framework\AssertionFailedError;
use Spatie\Image\Image;
use Spatie\LaravelPdf\Tests\TestCase;
use Spatie\TemporaryDirectory\TemporaryDirectory;
Expand Down

0 comments on commit 510b01a

Please sign in to comment.