Skip to content

Commit

Permalink
Test mailable can have attachments
Browse files Browse the repository at this point in the history
  • Loading branch information
unclexo committed Jan 6, 2023
1 parent 7e48526 commit e80c698
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
6 changes: 5 additions & 1 deletion app/Mail/OrderShipped.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Attachment;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;
Expand Down Expand Up @@ -48,6 +49,9 @@ public function content()
*/
public function attachments()
{
return [];
return [
Attachment::fromPath(storage_path('app/public/some.pdf')),
Attachment::fromStorageDisk('public', 'other.pdf'),
];
}
}
14 changes: 14 additions & 0 deletions tests/Feature/MailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Illuminate\Contracts\Mail\Mailable;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Mail\Mailables\Attachment;
use Tests\TestCase;

class MailTest extends TestCase
Expand Down Expand Up @@ -108,4 +109,17 @@ public function content_can_be_set_to_mailable_at_runtime()

$mailable->assertSeeInHtml('Order Shipped');
}

/** @test */
public function mailable_can_have_attachments()
{
$this->actingAs($user = User::factory()->create());

$order = Order::factory()->create(['user_id' => $user->id]);

$mailable = new OrderShipped($order);

$mailable->assertHasAttachment(Attachment::fromPath(storage_path('app/public/some.pdf')));
$mailable->assertHasAttachment(Attachment::fromStorageDisk('public', 'other.pdf'));
}
}

0 comments on commit e80c698

Please sign in to comment.