ldc-cocotte/tests/Integration/WithApp/App/Services/FlashMessageServiceTest.php

96 lines
2.6 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Integration\WithApp\App\Services;
use App\Services\FlashMessageService;
use Illuminate\Session\ArraySessionHandler;
use Illuminate\Session\Store;
use Illuminate\Support\Facades\Session;
covers(FlashMessageService::class);
describe('FlashMessageService', function (): void {
beforeEach(function (): void {
Session::swap(new Store('test', new ArraySessionHandler(120)));
});
describe('add()', function (): void {
it('adds a message without erasing previous', function (): void {
// GIVEN
Session::put('info', ['First message']);
$service = new FlashMessageService();
// WHEN
$service->add('info', 'Second message');
// THEN
expect(Session::get('info'))->toBe(['First message', 'Second message']);
});
it('adds a message when existing is not an array', function (): void {
// GIVEN
Session::put('info', 'First message');
$service = new FlashMessageService();
// WHEN
$service->add('info', 'Second message');
// THEN
expect(Session::get('info'))->toBe(['First message', 'Second message']);
});
});
describe('info()', function (): void {
it('adds an info message', function (): void {
// GIVEN
$service = new FlashMessageService();
// WHEN
$service->info('Info msg');
// THEN
expect(Session::get('info'))->toBe(['Info msg']);
});
});
describe('success()', function (): void {
it('adds a success message', function (): void {
// GIVEN
$service = new FlashMessageService();
// WHEN
$service->success('Success msg');
// THEN
expect(Session::get('success'))->toBe(['Success msg']);
});
});
describe('error()', function (): void {
it('adds an error message', function (): void {
// GIVEN
$service = new FlashMessageService();
// WHEN
$service->error('Error msg');
// THEN
expect(Session::get('error'))->toBe(['Error msg']);
});
});
describe('warning()', function (): void {
it('adds a warning message', function (): void {
// GIVEN
$service = new FlashMessageService();
// WHEN
$service->warning('Warning msg');
// THEN
expect(Session::get('warning'))->toBe(['Warning msg']);
});
});
});