Last active
January 27, 2020 18:01
-
-
Save sandervanhooft/bb745d1440434830109ca72bc52dc604 to your computer and use it in GitHub Desktop.
Assert flash for Laracasts/flash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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." | |
); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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