Skip to content

Instantly share code, notes, and snippets.

@sandervanhooft
Last active January 27, 2020 18:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save sandervanhooft/bb745d1440434830109ca72bc52dc604 to your computer and use it in GitHub Desktop.
Save sandervanhooft/bb745d1440434830109ca72bc52dc604 to your computer and use it in GitHub Desktop.
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