mirror of
https://github.com/nothingworksinc/ticketbeast.git
synced 2026-02-10 13:51:29 +00:00
77 - Stubbing the Interface
This commit is contained in:
@@ -11,6 +11,7 @@ class Order extends Model
|
|||||||
public static function forTickets($tickets, $email, $amount)
|
public static function forTickets($tickets, $email, $amount)
|
||||||
{
|
{
|
||||||
$order = self::create([
|
$order = self::create([
|
||||||
|
'confirmation_number' => app(OrderConfirmationNumberGenerator::class)->generate(),
|
||||||
'email' => $email,
|
'email' => $email,
|
||||||
'amount' => $amount,
|
'amount' => $amount,
|
||||||
]);
|
]);
|
||||||
|
|||||||
8
app/OrderConfirmationNumberGenerator.php
Normal file
8
app/OrderConfirmationNumberGenerator.php
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App;
|
||||||
|
|
||||||
|
interface OrderConfirmationNumberGenerator
|
||||||
|
{
|
||||||
|
public function generate();
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
use App\Concert;
|
use App\Concert;
|
||||||
use App\Billing\PaymentGateway;
|
use App\Billing\PaymentGateway;
|
||||||
use App\Billing\FakePaymentGateway;
|
use App\Billing\FakePaymentGateway;
|
||||||
|
use App\OrderConfirmationNumberGenerator;
|
||||||
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
||||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||||
@@ -51,8 +52,10 @@ class PurchaseTicketsTest extends TestCase
|
|||||||
{
|
{
|
||||||
$this->disableExceptionHandling();
|
$this->disableExceptionHandling();
|
||||||
|
|
||||||
// The API we need in our app to be able to use a different generation strategy in our tests...
|
$orderConfirmationNumberGenerator = Mockery::mock(OrderConfirmationNumberGenerator::class, [
|
||||||
// $orderConfirmationNumberGenerator->generate(); // 'ORDERCONFIRMATION1234'
|
'generate' => 'ORDERCONFIRMATION1234',
|
||||||
|
]);
|
||||||
|
$this->app->instance(OrderConfirmationNumberGenerator::class, $orderConfirmationNumberGenerator);
|
||||||
|
|
||||||
$concert = factory(Concert::class)->states('published')->create(['ticket_price' => 3250])->addTickets(3);
|
$concert = factory(Concert::class)->states('published')->create(['ticket_price' => 3250])->addTickets(3);
|
||||||
|
|
||||||
@@ -65,7 +68,7 @@ class PurchaseTicketsTest extends TestCase
|
|||||||
$this->assertResponseStatus(201);
|
$this->assertResponseStatus(201);
|
||||||
|
|
||||||
$this->seeJsonSubset([
|
$this->seeJsonSubset([
|
||||||
// 'confirmation_number' => 'ORDERCONFIRMATION1234',
|
'confirmation_number' => 'ORDERCONFIRMATION1234',
|
||||||
'email' => 'john@example.com',
|
'email' => 'john@example.com',
|
||||||
'ticket_quantity' => 3,
|
'ticket_quantity' => 3,
|
||||||
'amount' => 9750,
|
'amount' => 9750,
|
||||||
|
|||||||
Reference in New Issue
Block a user