Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
StevenRenaux committed Feb 29, 2024
1 parent dd17304 commit 50bd0a1
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 60 deletions.
36 changes: 9 additions & 27 deletions tests/Builder/HtmlPdfBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Sensiolabs\GotenbergBundle\Tests\Builder;

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\UsesClass;
use Sensiolabs\GotenbergBundle\Builder\HtmlPdfBuilder;
use Sensiolabs\GotenbergBundle\Client\GotenbergClientInterface;
use Sensiolabs\GotenbergBundle\Exception\ExtraHttpHeadersJsonEncodingException;
Expand All @@ -12,16 +13,14 @@
use Symfony\Component\Mime\Part\DataPart;

#[CoversClass(HtmlPdfBuilder::class)]
#[UsesClass(AssetBaseDirFormatter::class)]
#[UsesClass(Filesystem::class)]
final class HtmlPdfBuilderTest extends AbstractBuilderTestCase
{
public function testWithConfigurations(): void
{
$client = $this->createMock(GotenbergClientInterface::class);
$assetBaseDirFormatter = $this->createMock(AssetBaseDirFormatter::class);
$assetBaseDirFormatter->expects($this->any())
->method('resolve')
->willReturn(self::FIXTURE_DIR.'/templates/content.html')
;
$assetBaseDirFormatter = new AssetBaseDirFormatter(new Filesystem(), self::FIXTURE_DIR, self::FIXTURE_DIR);

$builder = new HtmlPdfBuilder($client, $assetBaseDirFormatter);
$builder->contentFile('content.html');
Expand Down Expand Up @@ -62,11 +61,7 @@ public function testWithConfigurations(): void
public function testWithTemplate(): void
{
$client = $this->createMock(GotenbergClientInterface::class);
$assetBaseDirFormatter = $this->createMock(AssetBaseDirFormatter::class);
$assetBaseDirFormatter->expects($this->any())
->method('resolve')
->willReturn(self::FIXTURE_DIR.'/templates/content.html')
;
$assetBaseDirFormatter = new AssetBaseDirFormatter(new Filesystem(), self::FIXTURE_DIR, self::FIXTURE_DIR);

$builder = new HtmlPdfBuilder($client, $assetBaseDirFormatter, self::$twig);
$builder->content('content.html.twig');
Expand All @@ -84,11 +79,7 @@ public function testWithTemplate(): void
public function testWithAssets(): void
{
$client = $this->createMock(GotenbergClientInterface::class);
$assetBaseDirFormatter = $this->createMock(AssetBaseDirFormatter::class);
$assetBaseDirFormatter->expects($this->exactly(2))
->method('resolve')
->willReturnOnConsecutiveCalls(self::FIXTURE_DIR.'/templates/content.html', self::FIXTURE_DIR.'/assets/logo.png')
;
$assetBaseDirFormatter = new AssetBaseDirFormatter(new Filesystem(), self::FIXTURE_DIR, self::FIXTURE_DIR);

$builder = new HtmlPdfBuilder($client, $assetBaseDirFormatter);
$builder->contentFile('content.html');
Expand All @@ -108,11 +99,7 @@ public function testWithAssets(): void
public function testWithHeader(): void
{
$client = $this->createMock(GotenbergClientInterface::class);
$assetBaseDirFormatter = $this->createMock(AssetBaseDirFormatter::class);
$assetBaseDirFormatter->expects($this->exactly(2))
->method('resolve')
->willReturnOnConsecutiveCalls(self::FIXTURE_DIR.'/templates/header.html', self::FIXTURE_DIR.'/templates/content.html')
;
$assetBaseDirFormatter = new AssetBaseDirFormatter(new Filesystem(), self::FIXTURE_DIR, self::FIXTURE_DIR);

$builder = new HtmlPdfBuilder($client, $assetBaseDirFormatter);
$builder->headerFile('header.html');
Expand All @@ -135,10 +122,7 @@ public function testInvalidTwigTemplate(): void
$this->expectExceptionMessage('Could not render template "invalid.html.twig" into PDF part "index.html".');

$client = $this->createMock(GotenbergClientInterface::class);
$assetBaseDirFormatter = $this->createMock(AssetBaseDirFormatter::class);
$assetBaseDirFormatter->expects($this->never())
->method('resolve')
;
$assetBaseDirFormatter = new AssetBaseDirFormatter(new Filesystem(), self::FIXTURE_DIR, self::FIXTURE_DIR);

$builder = new HtmlPdfBuilder($client, $assetBaseDirFormatter, self::$twig);

Expand All @@ -151,9 +135,7 @@ public function testInvalidExtraHttpHeaders(): void
$this->expectExceptionMessage('Could not encode extra HTTP headers into JSON');

$client = $this->createMock(GotenbergClientInterface::class);
$filesystem = $this->createMock(Filesystem::class);

$assetBaseDirFormatter = new AssetBaseDirFormatter($filesystem, self::FIXTURE_DIR, self::FIXTURE_DIR);
$assetBaseDirFormatter = new AssetBaseDirFormatter(new Filesystem(), self::FIXTURE_DIR, self::FIXTURE_DIR);

$builder = new HtmlPdfBuilder($client, $assetBaseDirFormatter);
$builder->contentFile('content.html');
Expand Down
10 changes: 5 additions & 5 deletions tests/Builder/LibreOfficePdfBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\UsesClass;
use Sensiolabs\GotenbergBundle\Builder\LibreOfficePdfBuilder;
use Sensiolabs\GotenbergBundle\Client\GotenbergClientInterface;
use Sensiolabs\GotenbergBundle\Formatter\AssetBaseDirFormatter;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Mime\Part\DataPart;

#[CoversClass(LibreOfficePdfBuilder::class)]
#[UsesClass(AssetBaseDirFormatter::class)]
#[UsesClass(Filesystem::class)]
final class LibreOfficePdfBuilderTest extends AbstractBuilderTestCase
{
private const OFFICE_DOCUMENTS_DIR = 'assets/office';
Expand All @@ -30,11 +34,7 @@ public static function provideValidOfficeFiles(): iterable
public function testOfficeFiles(string $filePath, string $contentType): void
{
$client = $this->createMock(GotenbergClientInterface::class);
$assetBaseDirFormatter = $this->createMock(AssetBaseDirFormatter::class);
$assetBaseDirFormatter->expects($this->any())
->method('resolve')
->willReturn(self::FIXTURE_DIR.'/'.$filePath)
;
$assetBaseDirFormatter = new AssetBaseDirFormatter(new Filesystem(), self::FIXTURE_DIR, self::FIXTURE_DIR);

$builder = new LibreOfficePdfBuilder($client, $assetBaseDirFormatter);
$builder->files($filePath);
Expand Down
10 changes: 5 additions & 5 deletions tests/Builder/MarkdownPdfBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
namespace Sensiolabs\GotenbergBundle\Tests\Builder;

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\UsesClass;
use Sensiolabs\GotenbergBundle\Builder\MarkdownPdfBuilder;
use Sensiolabs\GotenbergBundle\Client\GotenbergClientInterface;
use Sensiolabs\GotenbergBundle\Formatter\AssetBaseDirFormatter;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Mime\Part\DataPart;

#[CoversClass(MarkdownPdfBuilder::class)]
#[UsesClass(AssetBaseDirFormatter::class)]
#[UsesClass(Filesystem::class)]
final class MarkdownPdfBuilderTest extends AbstractBuilderTestCase
{
public function testMarkdownFile(): void
{
$client = $this->createMock(GotenbergClientInterface::class);
$assetBaseDirFormatter = $this->createMock(AssetBaseDirFormatter::class);
$assetBaseDirFormatter->expects($this->any())
->method('resolve')
->willReturnOnConsecutiveCalls(self::FIXTURE_DIR.'/templates/template.html', self::FIXTURE_DIR.'/assets/file.md', self::FIXTURE_DIR.'/assets/file.md')
;
$assetBaseDirFormatter = new AssetBaseDirFormatter(new Filesystem(), self::FIXTURE_DIR, self::FIXTURE_DIR);

$builder = new MarkdownPdfBuilder($client, $assetBaseDirFormatter);
$builder
Expand Down
9 changes: 5 additions & 4 deletions tests/Builder/UrlPdfBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@
namespace Sensiolabs\GotenbergBundle\Tests\Builder;

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\UsesClass;
use Sensiolabs\GotenbergBundle\Builder\HtmlPdfBuilder;
use Sensiolabs\GotenbergBundle\Builder\UrlPdfBuilder;
use Sensiolabs\GotenbergBundle\Client\GotenbergClientInterface;
use Sensiolabs\GotenbergBundle\Formatter\AssetBaseDirFormatter;
use Symfony\Component\Filesystem\Filesystem;

#[CoversClass(HtmlPdfBuilder::class)]
#[UsesClass(AssetBaseDirFormatter::class)]
#[UsesClass(Filesystem::class)]
final class UrlPdfBuilderTest extends AbstractBuilderTestCase
{
public function testUrl(): void
{
$client = $this->createMock(GotenbergClientInterface::class);
$assetBaseDirFormatter = $this->createMock(AssetBaseDirFormatter::class);
$assetBaseDirFormatter->expects($this->never())
->method('resolve')
;
$assetBaseDirFormatter = new AssetBaseDirFormatter(new Filesystem(), self::FIXTURE_DIR, self::FIXTURE_DIR);

$builder = new UrlPdfBuilder($client, $assetBaseDirFormatter);
$builder->url('https://google.com');
Expand Down
27 changes: 8 additions & 19 deletions tests/Pdf/GotenbergTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,24 @@
namespace Sensiolabs\GotenbergBundle\Tests\Pdf;

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\UsesClass;
use PHPUnit\Framework\TestCase;
use Sensiolabs\GotenbergBundle\Client\GotenbergClientInterface;
use Sensiolabs\GotenbergBundle\Formatter\AssetBaseDirFormatter;
use Sensiolabs\GotenbergBundle\Pdf\Gotenberg;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Mime\Part\DataPart;
use Twig\Environment;

#[CoversClass(Gotenberg::class)]
#[UsesClass(AssetBaseDirFormatter::class)]
#[UsesClass(Filesystem::class)]
final class GotenbergTest extends TestCase
{
public function testUrlBuilderFactory(): void
{
$gotenbergClient = $this->createMock(GotenbergClientInterface::class);
$assetBaseDirFormatter = $this->createMock(AssetBaseDirFormatter::class);
$assetBaseDirFormatter->expects($this->never())
->method('resolve')
;
$assetBaseDirFormatter = new AssetBaseDirFormatter(new Filesystem(), __DIR__.'/../Fixtures', __DIR__.'/../Fixtures');

$gotenberg = new Gotenberg(
$gotenbergClient,
Expand All @@ -36,11 +37,7 @@ public function testHtmlBuilderFactory(): void
{
$gotenbergClient = $this->createMock(GotenbergClientInterface::class);
$twig = $this->createMock(Environment::class);
$assetBaseDirFormatter = $this->createMock(AssetBaseDirFormatter::class);
$assetBaseDirFormatter->expects($this->exactly(1))
->method('resolve')
->willReturn(__DIR__.'/..Fixtures/templates/content.html')
;
$assetBaseDirFormatter = new AssetBaseDirFormatter(new Filesystem(), __DIR__.'/../Fixtures', __DIR__.'/../Fixtures');

$gotenberg = new Gotenberg(
$gotenbergClient,
Expand Down Expand Up @@ -72,11 +69,7 @@ public function testMarkdownBuilderFactory(): void
{
$gotenbergClient = $this->createMock(GotenbergClientInterface::class);
$twig = $this->createMock(Environment::class);
$assetBaseDirFormatter = $this->createMock(AssetBaseDirFormatter::class);
$assetBaseDirFormatter->expects($this->any())
->method('resolve')
->willReturnOnConsecutiveCalls(__DIR__.'/../Fixtures/assets/file.md', __DIR__.'/../Fixtures/assets/file.md', __DIR__.'/../Fixtures/templates/wrapper.html')
;
$assetBaseDirFormatter = new AssetBaseDirFormatter(new Filesystem(), __DIR__.'/../Fixtures', __DIR__.'/../Fixtures');

$gotenberg = new Gotenberg(
$gotenbergClient,
Expand Down Expand Up @@ -108,11 +101,7 @@ public function testOfficeBuilderFactory(): void
{
$gotenbergClient = $this->createMock(GotenbergClientInterface::class);
$twig = $this->createMock(Environment::class);
$assetBaseDirFormatter = $this->createMock(AssetBaseDirFormatter::class);
$assetBaseDirFormatter->expects($this->any())
->method('resolve')
->willReturn(__DIR__.'/../Fixtures/assets/office/document.odt')
;
$assetBaseDirFormatter = new AssetBaseDirFormatter(new Filesystem(), __DIR__.'/../Fixtures', __DIR__.'/../Fixtures');

$gotenberg = new Gotenberg(
$gotenbergClient,
Expand Down

0 comments on commit 50bd0a1

Please sign in to comment.