Instantly share code, notes, and snippets.

Embed
What would you like to do?
Assert flash for Laracasts/flash
<?php
namespace Tests;
trait CanAssertFlash
{
protected function assertFlash($level, $message, $important = false, $title = null, $overlay = false)
{
$expectedNotification = [
'title' => $title,
'message' => $message,
'level' => $level,
'important' => $important,
'overlay' => $overlay
];
$flashNotifications = json_decode(json_encode(session('flash_notification')), true);
if (! $flashNotifications) {
$this->fail('Failed asserting that a flash message was sent.');
}
$this->assertContains(
$expectedNotification,
$flashNotifications,
"Failed asserting that the flash message '$message' is present."
);
}
}
<?php
namespace Tests\Feature\FlashTest;
use Tests\TestCase;
use Tests\CanAssertFlash;
class FlashTest extends TestCase
{
use RefreshDatabase;
use CanAssertFlash;
/** @test */
public function a_flash_message_was_sent()
{
$this->get('/some-flash-page');
$this->assertFlash('success', "Thank you! We'll get back to you in 24 hours.");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment