mirror of
https://github.com/nothingworksinc/ticketbeast.git
synced 2026-01-26 11:14:06 +00:00
153 - Testing a Console Command
This commit is contained in:
14
app/Facades/InvitationCode.php
Normal file
14
app/Facades/InvitationCode.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Facades;
|
||||
|
||||
use Illuminate\Support\Facades\Facade;
|
||||
use App\InvitationCodeGenerator;
|
||||
|
||||
class InvitationCode extends Facade
|
||||
{
|
||||
protected static function getFacadeAccessor()
|
||||
{
|
||||
return InvitationCodeGenerator::class;
|
||||
}
|
||||
}
|
||||
8
app/InvitationCodeGenerator.php
Normal file
8
app/InvitationCodeGenerator.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
interface InvitationCodeGenerator
|
||||
{
|
||||
public function generate();
|
||||
}
|
||||
@@ -4,6 +4,7 @@ namespace App\Providers;
|
||||
|
||||
use App\TicketCodeGenerator;
|
||||
use App\Billing\PaymentGateway;
|
||||
use App\InvitationCodeGenerator;
|
||||
use App\HashidsTicketCodeGenerator;
|
||||
use App\Billing\StripePaymentGateway;
|
||||
use Laravel\Dusk\DuskServiceProvider;
|
||||
@@ -44,6 +45,7 @@ class AppServiceProvider extends ServiceProvider
|
||||
|
||||
$this->app->bind(PaymentGateway::class, StripePaymentGateway::class);
|
||||
$this->app->bind(OrderConfirmationNumberGenerator::class, RandomOrderConfirmationNumberGenerator::class);
|
||||
$this->app->bind(InvitationCodeGenerator::class, RandomOrderConfirmationNumberGenerator::class);
|
||||
$this->app->bind(TicketCodeGenerator::class, HashidsTicketCodeGenerator::class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace App;
|
||||
|
||||
class RandomOrderConfirmationNumberGenerator implements OrderConfirmationNumberGenerator
|
||||
class RandomOrderConfirmationNumberGenerator implements OrderConfirmationNumberGenerator, InvitationCodeGenerator
|
||||
{
|
||||
public function generate()
|
||||
{
|
||||
|
||||
@@ -80,5 +80,8 @@ $factory->define(App\Order::class, function (Faker\Generator $faker) {
|
||||
});
|
||||
|
||||
$factory->define(App\Invitation::class, function (Faker\Generator $faker) {
|
||||
return [];
|
||||
return [
|
||||
'email' => 'somebody@example.com',
|
||||
'code' => 'TESTCODE1234',
|
||||
];
|
||||
});
|
||||
|
||||
@@ -16,6 +16,7 @@ class CreateInvitationsTable extends Migration
|
||||
Schema::create('invitations', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->unsignedInteger('user_id')->nullable();
|
||||
$table->string('email');
|
||||
$table->string('code');
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
use App\Invitation;
|
||||
use App\Facades\InvitationCode;
|
||||
use Illuminate\Foundation\Inspiring;
|
||||
|
||||
/*
|
||||
@@ -13,6 +15,9 @@ use Illuminate\Foundation\Inspiring;
|
||||
|
|
||||
*/
|
||||
|
||||
Artisan::command('inspire', function () {
|
||||
$this->comment(Inspiring::quote());
|
||||
})->describe('Display an inspiring quote');
|
||||
Artisan::command('invite-promoter {email}', function ($email) {
|
||||
$invitation = Invitation::create([
|
||||
'email' => $email,
|
||||
'code' => InvitationCode::generate(),
|
||||
]);
|
||||
})->describe('Invite a new promoter to create an account.');
|
||||
|
||||
27
tests/Feature/InvitePromoterTest.php
Normal file
27
tests/Feature/InvitePromoterTest.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Invitation;
|
||||
use Tests\TestCase;
|
||||
use App\Facades\InvitationCode;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
class InvitePromoterTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/** @test */
|
||||
function inviting_a_promoter_via_the_cli()
|
||||
{
|
||||
InvitationCode::shouldReceive('generate')->andReturn('TESTCODE1234');
|
||||
|
||||
$this->artisan('invite-promoter', ['email' => 'john@example.com']);
|
||||
|
||||
$this->assertEquals(1, Invitation::count());
|
||||
$invitation = Invitation::first();
|
||||
$this->assertEquals('john@example.com', $invitation->email);
|
||||
$this->assertEquals('TESTCODE1234', $invitation->code);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user