-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix implementation, PHP 7.4 minimum, tests
- Loading branch information
1 parent
3ad7cf2
commit a22f919
Showing
7 changed files
with
201 additions
and
96 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 |
---|---|---|
@@ -1 +1,3 @@ | ||
/vendor/ | ||
composer.lock | ||
.phpunit.result.cache |
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
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,20 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit | ||
backupGlobals="false" | ||
backupStaticAttributes="false" | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnError="false" | ||
stopOnFailure="false" | ||
verbose="true" | ||
> | ||
<testsuites> | ||
<testsuite name="Package Test Suite"> | ||
<directory suffix="Test.php">./tests/</directory> | ||
</testsuite> | ||
</testsuites> | ||
</phpunit> |
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
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
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 |
---|---|---|
@@ -1,14 +1,12 @@ | ||
<?php | ||
|
||
if (! function_exists('flash')) { | ||
|
||
/** | ||
* @param string $message | ||
* @param string $type | ||
* @param bool $session | ||
*/ | ||
function flash($message = null, $type = 'success', $session = true) | ||
function flash(string $message = null, string $type = 'success', bool $session = true) | ||
{ | ||
(new \MasterRO\Flash\Flash($message, $type, $session))->push(); | ||
if (!$message) { | ||
return \MasterRO\Flash\Flash::make(); | ||
} | ||
|
||
return \MasterRO\Flash\Flash::make($message, $type, $session)->push(); | ||
} | ||
} |
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,110 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MasterRO\Flash\Tests; | ||
|
||
use Flash; | ||
use MasterRO\Flash\FlashFacade; | ||
use Orchestra\Testbench\TestCase; | ||
|
||
class FlashTest extends TestCase | ||
{ | ||
protected function getPackageAliases($app) | ||
{ | ||
return [ | ||
'Flash' => FlashFacade::class, | ||
]; | ||
} | ||
|
||
/** @test */ | ||
public function it_puts_message_to_session() | ||
{ | ||
flash('Test'); | ||
|
||
[$sessionMessage] = session('flash_messages', [null]); | ||
|
||
$this->assertEquals('Test', $sessionMessage['message']); | ||
$this->assertEquals('success', $sessionMessage['type']); | ||
} | ||
|
||
/** @test */ | ||
public function it_puts_success_message_to_session() | ||
{ | ||
flash('Success message', 'success'); | ||
|
||
[$sessionMessage] = session('flash_messages', [null]); | ||
|
||
$this->assertEquals('Success message', $sessionMessage['message']); | ||
$this->assertEquals('success', $sessionMessage['type']); | ||
|
||
session()->flush(); | ||
|
||
flash()->success('Success message 2'); | ||
|
||
[$sessionMessage] = session('flash_messages', [null]); | ||
|
||
$this->assertEquals('Success message 2', $sessionMessage['message']); | ||
$this->assertEquals('success', $sessionMessage['type']); | ||
|
||
session()->flush(); | ||
|
||
Flash::success('Success message 3'); | ||
|
||
[$sessionMessage] = session('flash_messages', [null]); | ||
|
||
$this->assertEquals('Success message 3', $sessionMessage['message']); | ||
$this->assertEquals('success', $sessionMessage['type']); | ||
} | ||
|
||
/** @test */ | ||
public function it_puts_error_message_to_session() | ||
{ | ||
flash('Error message', 'error'); | ||
|
||
[$sessionMessage] = session('flash_messages', [null]); | ||
|
||
$this->assertEquals('Error message', $sessionMessage['message']); | ||
$this->assertEquals('error', $sessionMessage['type']); | ||
|
||
session()->flush(); | ||
|
||
flash()->error('Error message 2'); | ||
|
||
[$sessionMessage] = session('flash_messages', [null]); | ||
|
||
$this->assertEquals('Error message 2', $sessionMessage['message']); | ||
$this->assertEquals('error', $sessionMessage['type']); | ||
|
||
session()->flush(); | ||
|
||
Flash::error('Error message 3'); | ||
|
||
[$sessionMessage] = session('flash_messages', [null]); | ||
|
||
$this->assertEquals('Error message 3', $sessionMessage['message']); | ||
$this->assertEquals('error', $sessionMessage['type']); | ||
} | ||
|
||
public function it_puts_multiple_flash_messages() | ||
{ | ||
flash('Error message', 'error'); | ||
flash('Success message'); | ||
flash()->info('Info message'); | ||
Flash::warning('Warning message'); | ||
|
||
$tests = [ | ||
['Error message', 'error'], | ||
['Success message', 'success'], | ||
['Info message', 'info'], | ||
['Warning message', 'warning'], | ||
]; | ||
|
||
foreach ($tests as $key => $test) { | ||
$sessionMessage = session('flash_messages', [])[$key] ?? null; | ||
|
||
$this->assertEquals($test[0], $sessionMessage['message']); | ||
$this->assertEquals($test[1], $sessionMessage['type']); | ||
} | ||
} | ||
} |