wip
This commit is contained in:
parent
32c23dda9f
commit
8abac26b58
|
@ -11,5 +11,12 @@
|
|||
"email": "philipp@zoomyboy.de"
|
||||
}
|
||||
],
|
||||
"require": {}
|
||||
"require": {},
|
||||
"extra": {
|
||||
"laravel": {
|
||||
"providers": [
|
||||
"Zoomyboy\\Tex\\TexServiceProvider"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
|
||||
namespace Zoomyboy\Tex;
|
||||
|
||||
use Illuminate\View\Compilers\BladeCompiler;
|
||||
use Illuminate\View\Compilers\BladeCompiler as BaseBladeCompiler;
|
||||
|
||||
class TexCompiler extends BladeCompiler
|
||||
class BladeCompiler extends BaseBladeCompiler
|
||||
{
|
||||
protected $contentTags = ['<<<', '>>>'];
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace Zoomyboy\Tex;
|
||||
|
||||
class Compiler
|
||||
{
|
||||
public function compile(Document $document): string
|
||||
{
|
||||
return '/tmp/file.pdf';
|
||||
}
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
<?php
|
||||
|
||||
namespace Zoomyboy\Tex;
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
use PHPUnit\Framework\Assert;
|
||||
|
||||
class CompilerSpy
|
||||
{
|
||||
public static Compiler $actualCompiler;
|
||||
/**
|
||||
* @var array<int, Document>
|
||||
*/
|
||||
private array $compiledDocuments = [];
|
||||
|
||||
/**
|
||||
* @param class-string<Document> $documentClass
|
||||
* @param callable(Document): bool $check
|
||||
*/
|
||||
public function assertCompiled(string $documentClass, callable $check): void
|
||||
{
|
||||
$compilations = $this->getCompilations($documentClass);
|
||||
Assert::assertFalse(
|
||||
$compilations->isEmpty(),
|
||||
'The TeX Document "'.$documentClass.'" has not been compiled at all.'
|
||||
);
|
||||
|
||||
Assert::assertFalse(
|
||||
$compilations->isEmpty(),
|
||||
'The TeX Document "'.$documentClass.'" has not been compiled.'
|
||||
);
|
||||
|
||||
foreach ($compilations as $compilation) {
|
||||
}
|
||||
|
||||
Assert::assertFalse(
|
||||
$this->getCompilations($documentClass)->isEmpty(),
|
||||
'The TeX Document "'.$documentClass.'" has not been compiled.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param class-string<Document> $documentClass
|
||||
*
|
||||
* @return Collection<int, Document>
|
||||
*/
|
||||
protected function getCompilations(string $documentClass): Collection
|
||||
{
|
||||
return collect($this->compiledDocuments)->filter(fn ($rendered) => get_class($rendered) === $documentClass);
|
||||
}
|
||||
|
||||
public function compile(Document $document): string
|
||||
{
|
||||
$filename = static::$actualCompiler->compile($document);
|
||||
|
||||
$this->compiledDocuments[] = $document;
|
||||
|
||||
return $filename;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
namespace Zoomyboy\Tex;
|
||||
|
||||
use PHPUnit\Framework\Assert;
|
||||
|
||||
abstract class Document
|
||||
{
|
||||
public function assertHasContent(string $content): void
|
||||
{
|
||||
Assert::assertStringContainsString(
|
||||
$content,
|
||||
$this->renderBody(),
|
||||
);
|
||||
}
|
||||
|
||||
protected function renderBody(): string
|
||||
{
|
||||
return 'gggggMax';
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
namespace Zoomyboy\Tex;
|
||||
|
||||
use Illuminate\Support\Facades\Facade;
|
||||
|
||||
/**
|
||||
* @method static void assertCompiled(class-string<Document> $documentClass, callable(Document): bool $check)
|
||||
* @method static void compile(Document $document)
|
||||
*/
|
||||
class Tex extends Facade
|
||||
{
|
||||
public static function getFacadeAccessor(): string
|
||||
{
|
||||
return 'tex.compiler';
|
||||
}
|
||||
|
||||
public static function spy(): void
|
||||
{
|
||||
CompilerSpy::$actualCompiler = app(Compiler::class);
|
||||
static::swap(app(CompilerSpy::class));
|
||||
}
|
||||
|
||||
public static function fake(): void
|
||||
{
|
||||
static::swap(app(CompilerFake::class));
|
||||
}
|
||||
}
|
|
@ -19,6 +19,8 @@ class TexServiceProvider extends ServiceProvider
|
|||
|
||||
return new CompilerEngine($compiler, app('files'));
|
||||
});
|
||||
|
||||
app()->bind('tex.compiler', Compiler::class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue