mirror of
https://github.com/nothingworksinc/ticketbeast.git
synced 2026-02-12 09:52:18 +00:00
143 - Testing Events
This commit is contained in:
23
app/Events/ConcertAdded.php
Normal file
23
app/Events/ConcertAdded.php
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Events;
|
||||||
|
|
||||||
|
use Illuminate\Broadcasting\Channel;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
use Illuminate\Broadcasting\PrivateChannel;
|
||||||
|
use Illuminate\Broadcasting\PresenceChannel;
|
||||||
|
use Illuminate\Foundation\Events\Dispatchable;
|
||||||
|
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||||
|
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||||
|
|
||||||
|
class ConcertAdded
|
||||||
|
{
|
||||||
|
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||||
|
|
||||||
|
public $concert;
|
||||||
|
|
||||||
|
public function __construct($concert)
|
||||||
|
{
|
||||||
|
$this->concert = $concert;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ namespace App\Http\Controllers\Backstage;
|
|||||||
use App\Concert;
|
use App\Concert;
|
||||||
use App\NullFile;
|
use App\NullFile;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use App\Events\ConcertAdded;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Validation\Rule;
|
use Illuminate\Validation\Rule;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
@@ -59,6 +60,8 @@ class ConcertsController extends Controller
|
|||||||
'poster_image_path' => request('poster_image', new NullFile)->store('posters', 'public'),
|
'poster_image_path' => request('poster_image', new NullFile)->store('posters', 'public'),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
ConcertAdded::dispatch($concert);
|
||||||
|
|
||||||
return redirect()->route('backstage.concerts.index');
|
return redirect()->route('backstage.concerts.index');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,9 @@ use App\User;
|
|||||||
use App\Concert;
|
use App\Concert;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
use App\Events\ConcertAdded;
|
||||||
use Illuminate\Http\Testing\File;
|
use Illuminate\Http\Testing\File;
|
||||||
|
use Illuminate\Support\Facades\Event;
|
||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||||
|
|
||||||
@@ -460,4 +462,20 @@ class AddConcertTest extends TestCase
|
|||||||
$this->assertNull($concert->poster_image_path);
|
$this->assertNull($concert->poster_image_path);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @test */
|
||||||
|
function an_event_is_fired_when_a_concert_is_added()
|
||||||
|
{
|
||||||
|
$this->disableExceptionHandling();
|
||||||
|
|
||||||
|
Event::fake([ConcertAdded::class]);
|
||||||
|
$user = factory(User::class)->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->post('/backstage/concerts', $this->validParams());
|
||||||
|
|
||||||
|
Event::assertDispatched(ConcertAdded::class, function ($event) {
|
||||||
|
$concert = Concert::firstOrFail();
|
||||||
|
return $event->concert->is($concert);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user