mirror of
https://github.com/nothingworksinc/ticketbeast.git
synced 2026-02-16 07:53:38 +00:00
95 - Using a Fake to Intercept Email
This commit is contained in:
@@ -7,6 +7,8 @@ use App\Concert;
|
|||||||
use App\Reservation;
|
use App\Reservation;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use App\Billing\PaymentGateway;
|
use App\Billing\PaymentGateway;
|
||||||
|
use App\Mail\OrderConfirmationEmail;
|
||||||
|
use Illuminate\Support\Facades\Mail;
|
||||||
use App\Billing\PaymentFailedException;
|
use App\Billing\PaymentFailedException;
|
||||||
use App\Exceptions\NotEnoughTicketsException;
|
use App\Exceptions\NotEnoughTicketsException;
|
||||||
|
|
||||||
@@ -32,6 +34,9 @@ class ConcertOrdersController extends Controller
|
|||||||
try {
|
try {
|
||||||
$reservation = $concert->reserveTickets(request('ticket_quantity'), request('email'));
|
$reservation = $concert->reserveTickets(request('ticket_quantity'), request('email'));
|
||||||
$order = $reservation->complete($this->paymentGateway, request('payment_token'));
|
$order = $reservation->complete($this->paymentGateway, request('payment_token'));
|
||||||
|
|
||||||
|
Mail::to($order->email)->send(new OrderConfirmationEmail($order));
|
||||||
|
|
||||||
return response()->json($order, 201);
|
return response()->json($order, 201);
|
||||||
} catch (PaymentFailedException $e) {
|
} catch (PaymentFailedException $e) {
|
||||||
$reservation->cancel();
|
$reservation->cancel();
|
||||||
|
|||||||
35
app/Mail/OrderConfirmationEmail.php
Normal file
35
app/Mail/OrderConfirmationEmail.php
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Mail;
|
||||||
|
|
||||||
|
use Illuminate\Bus\Queueable;
|
||||||
|
use Illuminate\Mail\Mailable;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
|
||||||
|
class OrderConfirmationEmail extends Mailable
|
||||||
|
{
|
||||||
|
use Queueable, SerializesModels;
|
||||||
|
|
||||||
|
public $order;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new message instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct($order)
|
||||||
|
{
|
||||||
|
$this->order = $order;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build the message.
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function build()
|
||||||
|
{
|
||||||
|
return $this->view('view.name');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,6 +4,8 @@ use App\Concert;
|
|||||||
use App\Facades\TicketCode;
|
use App\Facades\TicketCode;
|
||||||
use App\Billing\PaymentGateway;
|
use App\Billing\PaymentGateway;
|
||||||
use App\Billing\FakePaymentGateway;
|
use App\Billing\FakePaymentGateway;
|
||||||
|
use App\Mail\OrderConfirmationEmail;
|
||||||
|
use Illuminate\Support\Facades\Mail;
|
||||||
use App\Facades\OrderConfirmationNumber;
|
use App\Facades\OrderConfirmationNumber;
|
||||||
use App\OrderConfirmationNumberGenerator;
|
use App\OrderConfirmationNumberGenerator;
|
||||||
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
||||||
@@ -53,6 +55,7 @@ class PurchaseTicketsTest extends TestCase
|
|||||||
function customer_can_purchase_tickets_to_a_published_concert()
|
function customer_can_purchase_tickets_to_a_published_concert()
|
||||||
{
|
{
|
||||||
$this->disableExceptionHandling();
|
$this->disableExceptionHandling();
|
||||||
|
Mail::fake();
|
||||||
|
|
||||||
OrderConfirmationNumber::shouldReceive('generate')->andReturn('ORDERCONFIRMATION1234');
|
OrderConfirmationNumber::shouldReceive('generate')->andReturn('ORDERCONFIRMATION1234');
|
||||||
TicketCode::shouldReceive('generateFor')->andReturn('TICKETCODE1', 'TICKETCODE2', 'TICKETCODE3');
|
TicketCode::shouldReceive('generateFor')->andReturn('TICKETCODE1', 'TICKETCODE2', 'TICKETCODE3');
|
||||||
@@ -80,7 +83,14 @@ class PurchaseTicketsTest extends TestCase
|
|||||||
|
|
||||||
$this->assertEquals(9750, $this->paymentGateway->totalCharges());
|
$this->assertEquals(9750, $this->paymentGateway->totalCharges());
|
||||||
$this->assertTrue($concert->hasOrderFor('john@example.com'));
|
$this->assertTrue($concert->hasOrderFor('john@example.com'));
|
||||||
$this->assertEquals(3, $concert->ordersFor('john@example.com')->first()->ticketQuantity());
|
|
||||||
|
$order = $concert->ordersFor('john@example.com')->first();
|
||||||
|
$this->assertEquals(3, $order->ticketQuantity());
|
||||||
|
|
||||||
|
Mail::assertSent(OrderConfirmationEmail::class, function ($mail) use ($order) {
|
||||||
|
return $mail->hasTo('john@example.com')
|
||||||
|
&& $mail->order->id == $order->id;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @test */
|
/** @test */
|
||||||
|
|||||||
Reference in New Issue
Block a user