mirror of
https://github.com/php-flasher/php-flasher.git
synced 2026-03-31 15:07:47 +01:00
Refactor code and update tests for improved DX
This commit is contained in:
@@ -89,7 +89,7 @@ final class FlasherContainerTest extends TestCase
|
||||
public function testFromWithClosureReturningInvalidTypeThrowsException(): void
|
||||
{
|
||||
// Pass a closure that returns something other than ContainerInterface
|
||||
FlasherContainer::from(fn () => 'not a container');
|
||||
FlasherContainer::from(fn () => 'not a container'); // @phpstan-ignore argument.type
|
||||
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('Expected an instance of "Psr\Container\ContainerInterface"');
|
||||
|
||||
@@ -23,19 +23,37 @@ final class TypeTest extends TestCase
|
||||
$this->assertSame($expected, Type::all());
|
||||
}
|
||||
|
||||
public function testIsValidWithValidTypes(): void
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('validTypesProvider')]
|
||||
public function testIsValidWithValidTypes(string $type): void
|
||||
{
|
||||
$this->assertTrue(Type::isValid('success'));
|
||||
$this->assertTrue(Type::isValid('error'));
|
||||
$this->assertTrue(Type::isValid('info'));
|
||||
$this->assertTrue(Type::isValid('warning'));
|
||||
$this->assertTrue(Type::isValid($type));
|
||||
}
|
||||
|
||||
public function testIsValidWithInvalidTypes(): void
|
||||
/**
|
||||
* @return iterable<string, array{string}>
|
||||
*/
|
||||
public static function validTypesProvider(): iterable
|
||||
{
|
||||
$this->assertFalse(Type::isValid('invalid'));
|
||||
$this->assertFalse(Type::isValid(''));
|
||||
$this->assertFalse(Type::isValid('SUCCESS'));
|
||||
$this->assertFalse(Type::isValid('notice'));
|
||||
yield 'success' => ['success'];
|
||||
yield 'error' => ['error'];
|
||||
yield 'info' => ['info'];
|
||||
yield 'warning' => ['warning'];
|
||||
}
|
||||
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('invalidTypesProvider')]
|
||||
public function testIsValidWithInvalidTypes(string $type): void
|
||||
{
|
||||
$this->assertFalse(Type::isValid($type));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return iterable<string, array{string}>
|
||||
*/
|
||||
public static function invalidTypesProvider(): iterable
|
||||
{
|
||||
yield 'invalid' => ['invalid'];
|
||||
yield 'empty' => [''];
|
||||
yield 'uppercase SUCCESS' => ['SUCCESS'];
|
||||
yield 'notice' => ['notice'];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,12 +7,14 @@ namespace Flasher\Tests\Symfony\EventListener;
|
||||
use Flasher\Prime\Http\Csp\ContentSecurityPolicyHandlerInterface;
|
||||
use Flasher\Symfony\EventListener\WorkerListener;
|
||||
use Flasher\Symfony\Storage\FallbackSession;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Contracts\Service\ResetInterface;
|
||||
|
||||
final class WorkerListenerTest extends TestCase
|
||||
{
|
||||
private ContentSecurityPolicyHandlerInterface $cspHandler;
|
||||
/** @var MockObject&ContentSecurityPolicyHandlerInterface */
|
||||
private MockObject $cspHandler;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user