Skip to content

Commit da472a1

Browse files
committed
Add tests for global flash() helper function
1 parent 555331b commit da472a1

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed

src/BaseFlash.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,13 @@ public function __construct()
2727
* Flash a notification.
2828
*
2929
* @param string $message
30-
* @param string $level
30+
* @param string|null $level
3131
*
3232
* @return \CodeZero\Flash\Notification
3333
*/
34-
public function notification($message, $level = 'default')
34+
public function notification($message, $level = null)
3535
{
36+
$level = $level ?: 'default';
3637
$notification = new Notification($message, $level);
3738

3839
$notifications = $this->getFlashedNotificationsFromSession();

src/helpers.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
* Flash a message to the session.
66
*
77
* @param string|null $message
8-
* @param string $level
8+
* @param string|null $level
99
*
1010
* @return \CodeZero\Flash\Flash
1111
*/
12-
function flash($message = null, $level = 'info')
12+
function flash($message = null, $level = null)
1313
{
1414
$flash = app('flash');
1515

tests/HelperTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace CodeZero\Flash\Tests;
4+
5+
use CodeZero\Flash\Flash;
6+
use CodeZero\Flash\Notification;
7+
8+
class HelperTest extends TestCase
9+
{
10+
/** @test */
11+
public function it_returns_a_flash_instance()
12+
{
13+
$this->assertInstanceOf(Flash::class, flash());
14+
}
15+
16+
/** @test */
17+
public function it_flashes_a_notification()
18+
{
19+
$notification = flash('message');
20+
21+
$this->assertInstanceOf(Notification::class, $notification);
22+
$this->assertEquals('message', flash()->notifications()->first()->message);
23+
$this->assertEquals('default', flash()->notifications()->first()->level);
24+
}
25+
26+
/** @test */
27+
public function it_flashes_a_notification_with_custom_level()
28+
{
29+
$notification = flash('message', 'custom');
30+
31+
$this->assertInstanceOf(Notification::class, $notification);
32+
$this->assertEquals('message', flash()->notifications()->first()->message);
33+
$this->assertEquals('custom', flash()->notifications()->first()->level);
34+
}
35+
}

0 commit comments

Comments
 (0)