-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace ActivismeBe\Toastr\Traits; | ||
|
||
/** | ||
* Trait WithToastr | ||
* ----- | ||
* Trait for checking the toastr session's in phpunit functions. | ||
* | ||
* @author Tim Joosten <[email protected]> | ||
* @copyright 2018 Tim Joosten <MIT license> | ||
* @package ActivismeBe\Toastr\Testing | ||
*/ | ||
trait WithToastr | ||
{ | ||
/** | ||
* Custom assertions for toastr flash messages. | ||
* | ||
* @param string $type The type of the toastr notification. | ||
* @param string $title The title of the toastr notification. | ||
* @param string $message The actual toastr message. | ||
* @param array $options The user defined configuration for the toastr message. | ||
* @return void | ||
*/ | ||
protected function assertHasToastr(string $type, string $title, string $message, array $options = []): void | ||
{ | ||
$expectedNotification = ['type' => $type, 'title' => $title, 'message' => $message, 'options' => $options]; | ||
$flashNotifications = json_decode(json_encode(session('toastr::notifications')), true); | ||
$assertMessage = 'Failed asserting that the toastr message '. $message .' is present'; | ||
|
||
if (! $flashNotifications) { | ||
$this->fail('Failed asserting that a flash message was sent.'); | ||
} | ||
|
||
$this->assertContains($expectedNotification, $flashNotifications, $assertMessage); | ||
} | ||
} |