110 lines
3.1 KiB
PHP
110 lines
3.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Services\FlashMessageService;
|
|
use Illuminate\Support\Facades\Facade;
|
|
use Illuminate\Support\Facades\Session;
|
|
|
|
covers(FlashMessageService::class);
|
|
|
|
afterEach(function () {
|
|
\Mockery::close();
|
|
Facade::clearResolvedInstances();
|
|
});
|
|
|
|
describe('FlashMessageService', function () {
|
|
describe('add()', function () {
|
|
it('adds a message without erasing previous', function () {
|
|
// GIVEN
|
|
Session::shouldReceive('get')->with('info', [])->andReturn(['First message']);
|
|
Session::shouldReceive('flash')->with('info', ['First message', 'Second message'])->once();
|
|
|
|
$service = new FlashMessageService();
|
|
|
|
// WHEN
|
|
$service->add('info', 'Second message');
|
|
|
|
// THEN
|
|
expect(true)->toBeTrue();
|
|
});
|
|
|
|
it('adds a message when existing is not an array', function () {
|
|
// GIVEN
|
|
Session::shouldReceive('get')->with('info', [])->andReturn('First message');
|
|
Session::shouldReceive('flash')->with('info', ['First message', 'Second message'])->once();
|
|
|
|
$service = new FlashMessageService();
|
|
|
|
// WHEN
|
|
$service->add('info', 'Second message');
|
|
|
|
// THEN
|
|
expect(true)->toBeTrue();
|
|
});
|
|
});
|
|
|
|
describe('info()', function () {
|
|
it('adds an info message', function () {
|
|
// GIVEN
|
|
Session::shouldReceive('get')->with('info', [])->andReturn([]);
|
|
Session::shouldReceive('flash')->with('info', ['Info msg'])->once();
|
|
|
|
$service = new FlashMessageService();
|
|
|
|
// WHEN
|
|
$service->info('Info msg');
|
|
|
|
// THEN
|
|
expect(true)->toBeTrue();
|
|
});
|
|
});
|
|
|
|
describe('success()', function () {
|
|
it('adds a success message', function () {
|
|
// GIVEN
|
|
Session::shouldReceive('get')->with('success', [])->andReturn([]);
|
|
Session::shouldReceive('flash')->with('success', ['Success msg'])->once();
|
|
|
|
$service = new FlashMessageService();
|
|
|
|
// WHEN
|
|
$service->success('Success msg');
|
|
|
|
// THEN
|
|
expect(true)->toBeTrue();
|
|
});
|
|
});
|
|
|
|
describe('error()', function () {
|
|
it('adds an error message', function () {
|
|
// GIVEN
|
|
Session::shouldReceive('get')->with('error', [])->andReturn([]);
|
|
Session::shouldReceive('flash')->with('error', ['Error msg'])->once();
|
|
|
|
$service = new FlashMessageService();
|
|
|
|
// WHEN
|
|
$service->error('Error msg');
|
|
|
|
// THEN
|
|
expect(true)->toBeTrue();
|
|
});
|
|
});
|
|
|
|
describe('warning()', function () {
|
|
it('adds a warning message', function () {
|
|
// GIVEN
|
|
Session::shouldReceive('get')->with('warning', [])->andReturn([]);
|
|
Session::shouldReceive('flash')->with('warning', ['Warning msg'])->once();
|
|
|
|
$service = new FlashMessageService();
|
|
|
|
// WHEN
|
|
$service->warning('Warning msg');
|
|
|
|
// THEN
|
|
expect(true)->toBeTrue();
|
|
});
|
|
});
|
|
});
|