Fixes for PDFMock

This commit is contained in:
David Bomba 2023-02-28 18:05:08 +11:00
parent 505fafb147
commit 13881ac6e5
4 changed files with 40 additions and 15 deletions

View File

@ -197,7 +197,6 @@ class PreviewController extends BaseController
return response()->json(['message' => 'This server cannot handle this request.'], 400);
}
$company = auth()->user()->company();
MultiDB::setDb($company->db);

View File

@ -102,7 +102,12 @@ class PdfMock
return $entity;
}
/**
* getMergedSettings
*
* @return object
*/
public function getMergedSettings() :object
{
match ($this->request['settings_type']) {
@ -115,17 +120,32 @@ class PdfMock
return $settings;
}
/**
* getTaxMap
*
* @return void
*/
private function getTaxMap()
{
return collect([['name' => 'GST', 'total' => 10]]);
}
/**
* getTotalTaxMap
*
* @return void
*/
private function getTotalTaxMap()
{
return [['name' => 'GST', 'total' => 10]];
}
/**
* getStubVariables
*
* @return void
*/
public function getStubVariables()
{
return ['values' =>

View File

@ -61,18 +61,25 @@ class PdfService
$this->options = $options;
}
public function boot(): self
{
$this->init();
return $this;
}
/**
* Resolves the PDF generation type and
* attempts to generate a PDF from the HTML
* string.
*
*
* @return mixed | Exception
*
*/
public function getPdf()
{
try {
$pdf = $this->init()->resolvePdfEngine($this->getHtml());
$pdf = $this->resolvePdfEngine($this->getHtml());
$numbered_pdf = $this->pageNumbering($pdf, $this->company);
@ -95,7 +102,6 @@ class PdfService
*/
public function getHtml(): string
{
$this->init();
$html = $this->builder->getCompiledHTML();

View File

@ -38,7 +38,7 @@ class PdfServiceTest extends TestCase
$invitation = $this->invoice->invitations->first();
$service = new PdfService($invitation);
$service = (new PdfService($invitation))->boot();
$this->assertNotNull($service->getPdf());
@ -49,7 +49,7 @@ class PdfServiceTest extends TestCase
$invitation = $this->invoice->invitations->first();
$service = new PdfService($invitation);
$service = (new PdfService($invitation))->boot();
$this->assertIsString($service->getHtml());
@ -60,7 +60,7 @@ class PdfServiceTest extends TestCase
$invitation = $this->invoice->invitations->first();
$service = new PdfService($invitation);
$service = (new PdfService($invitation))->boot();
$this->assertInstanceOf(PdfService::class, $service);
@ -71,7 +71,7 @@ class PdfServiceTest extends TestCase
$invitation = $this->invoice->invitations->first();
$service = (new PdfService($invitation))->init();
$service = (new PdfService($invitation))->boot();
$this->assertInstanceOf(PdfConfiguration::class, $service->config);
@ -82,7 +82,7 @@ class PdfServiceTest extends TestCase
{
$invitation = $this->invoice->invitations->first();
$service = (new PdfService($invitation))->init();
$service = (new PdfService($invitation))->boot();
$this->assertEquals(2, $service->config->design->id);
@ -92,7 +92,7 @@ class PdfServiceTest extends TestCase
{
$invitation = $this->invoice->invitations->first();
$service = (new PdfService($invitation))->init();
$service = (new PdfService($invitation))->boot();
$this->assertIsArray($service->html_variables);
@ -102,7 +102,7 @@ class PdfServiceTest extends TestCase
{
$invitation = $this->invoice->invitations->first();
$service = (new PdfService($invitation))->init();
$service = (new PdfService($invitation))->boot();
$this->assertIsString($service->designer->template);