adrema/tests/Feature/Invoice/ShowPdfTest.php

65 lines
1.9 KiB
PHP
Raw Permalink Normal View History

2023-12-17 22:33:29 +01:00
<?php
namespace Tests\Feature\Invoice;
use App\Invoice\BillDocument;
use App\Invoice\BillKind;
2023-12-18 00:16:58 +01:00
use App\Invoice\InvoiceSettings;
2023-12-17 22:33:29 +01:00
use App\Invoice\Models\Invoice;
use App\Invoice\Models\InvoicePosition;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\TestCase;
use Zoomyboy\Tex\Tex;
class ShowPdfTest extends TestCase
{
use DatabaseTransactions;
public function testItShowsAnInvoiceAsPdf(): void
{
Tex::spy();
2023-12-18 00:16:58 +01:00
InvoiceSettings::fake([
'from_long' => 'langer Stammesname',
'from' => 'Stammeskurz',
'mobile' => '+49 176 55555',
'email' => 'max@muster.de',
'website' => 'https://example.com',
'address' => 'Musterstr 4',
'place' => 'Münster',
'zip' => '12345',
'iban' => 'DE444',
'bic' => 'SOLSSSSS',
]);
2023-12-17 22:33:29 +01:00
$this->login()->loginNami();
$invoice = Invoice::factory()
->to(ReceiverRequestFactory::new()->name('Familie Lala'))
2023-12-18 00:16:58 +01:00
->has(InvoicePosition::factory()->withMember()->price(1500)->description('Beitrag12'), 'positions')
2023-12-17 22:33:29 +01:00
->via(BillKind::EMAIL)
2023-12-18 00:16:58 +01:00
->create(['usage' => 'Usa']);
2023-12-17 22:33:29 +01:00
$this->get(route('invoice.pdf', ['invoice' => $invoice]))
->assertOk()
->assertPdfPageCount(1)
->assertPdfName('rechnung-fur-familie-lala.pdf');
2023-12-18 00:16:58 +01:00
Tex::assertCompiled(BillDocument::class, fn ($document) => $document->hasAllContent([
'Beitrag12',
'Familie Lala',
'Rechnung',
'15.00',
'Usa',
'langer Stammesname',
'Stammeskurz',
'+49 176 55555',
'max@muster.de',
'https://example.com',
'Musterstr 4',
'Münster',
'12345',
'DE444',
'SOLSSSSS',
]));
2023-12-17 22:33:29 +01:00
}
}