adrema/tests/Feature/Letter/LetterSendActionTest.php

61 lines
1.7 KiB
PHP
Raw Normal View History

2022-11-07 16:18:11 +01:00
<?php
namespace Tests\Feature\Letter;
use App\Letter\Actions\LetterSendAction;
use App\Letter\BillDocument;
use App\Member\Member;
use App\Payment\Payment;
use App\Payment\PaymentMail;
use Illuminate\Foundation\Testing\DatabaseTransactions;
2022-11-09 01:33:31 +01:00
use Illuminate\Support\Facades\Artisan;
2023-02-18 01:22:58 +01:00
use Illuminate\Support\Facades\Mail;
2022-11-07 16:18:11 +01:00
use Illuminate\Support\Facades\Storage;
2022-12-13 23:11:32 +01:00
use Tests\RequestFactories\Child;
2022-11-07 16:18:11 +01:00
use Tests\TestCase;
use Zoomyboy\Tex\Tex;
class LetterSendActionTest extends TestCase
{
use DatabaseTransactions;
public Member $member;
public function setUp(): void
{
parent::setUp();
2023-02-18 01:22:58 +01:00
Storage::fake('temp');
2022-11-07 16:18:11 +01:00
$this->withoutExceptionHandling();
$this->login()->loginNami();
$this->member = Member::factory()
->defaults()
2022-12-13 23:11:32 +01:00
->has(Payment::factory()->notPaid()->nr('1997')->subscription('tollerbeitrag', [
new Child('a', 5400),
]))
2022-11-07 16:18:11 +01:00
->emailBillKind()
->create(['firstname' => 'Lah', 'lastname' => 'Mom', 'email' => 'peter@example.com']);
}
public function testItCanCreatePdfPayments(): void
{
Mail::fake();
2022-11-09 01:33:31 +01:00
Artisan::call('letter:send');
2022-11-07 16:18:11 +01:00
2023-02-18 01:22:58 +01:00
Mail::assertSent(PaymentMail::class, fn ($mail) => Storage::disk('temp')->path('rechnung-fur-mom.pdf') === $mail->filename && Storage::disk('temp')->exists('rechnung-fur-mom.pdf'));
2022-11-07 16:18:11 +01:00
}
public function testItCanCompileAttachment(): void
{
Mail::fake();
Tex::spy();
LetterSendAction::run();
Tex::assertCompiled(BillDocument::class, fn ($document) => 'Mom' === $document->pages->first()->familyName
2022-12-14 00:23:03 +01:00
&& $document->pages->first()->getPositions() === ['tollerbeitrag 1997 für Lah Mom' => '54.00']
2022-11-07 16:18:11 +01:00
);
}
}