mirror of
https://github.com/php-flasher/php-flasher.git
synced 2026-03-31 15:07:47 +01:00
Standardize exception message format and add exception tests
This commit is contained in:
@@ -54,7 +54,7 @@ final class PresetListenerTest extends TestCase
|
||||
PresetNotFoundException::class
|
||||
);
|
||||
$this->expectExceptionMessage(
|
||||
'Preset "entity_deleted" not found, did you forget to register it? Available presets: "entity_saved"'
|
||||
'Preset "entity_deleted" not found, did you forget to register it? Available presets: [entity_saved]'
|
||||
);
|
||||
|
||||
$eventDispatcher = new EventDispatcher();
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Flasher\Tests\Prime\Exception;
|
||||
|
||||
use Flasher\Prime\Exception\CriteriaNotRegisteredException;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class CriteriaNotRegisteredExceptionTest extends TestCase
|
||||
{
|
||||
public function testCreateWithAliasOnly(): void
|
||||
{
|
||||
$exception = CriteriaNotRegisteredException::create('custom_criteria');
|
||||
|
||||
$this->assertSame('Criteria "custom_criteria" not found, did you forget to register it?', $exception->getMessage());
|
||||
}
|
||||
|
||||
public function testCreateWithAvailableCriteria(): void
|
||||
{
|
||||
$exception = CriteriaNotRegisteredException::create('custom_criteria', ['limit', 'order_by', 'filter']);
|
||||
|
||||
$this->assertSame('Criteria "custom_criteria" not found, did you forget to register it? Available criteria: [limit, order_by, filter]', $exception->getMessage());
|
||||
}
|
||||
|
||||
public function testCreateWithEmptyAvailableCriteria(): void
|
||||
{
|
||||
$exception = CriteriaNotRegisteredException::create('custom_criteria', []);
|
||||
|
||||
$this->assertSame('Criteria "custom_criteria" not found, did you forget to register it?', $exception->getMessage());
|
||||
}
|
||||
|
||||
public function testIsException(): void
|
||||
{
|
||||
$exception = CriteriaNotRegisteredException::create('test');
|
||||
|
||||
$this->assertInstanceOf(\Exception::class, $exception);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Flasher\Tests\Prime\Exception;
|
||||
|
||||
use Flasher\Prime\Exception\PresenterNotFoundException;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class PresenterNotFoundExceptionTest extends TestCase
|
||||
{
|
||||
public function testCreateWithAliasOnly(): void
|
||||
{
|
||||
$exception = PresenterNotFoundException::create('xml');
|
||||
|
||||
$this->assertSame('Presenter "xml" not found, did you forget to register it?', $exception->getMessage());
|
||||
}
|
||||
|
||||
public function testCreateWithAvailablePresenters(): void
|
||||
{
|
||||
$exception = PresenterNotFoundException::create('xml', ['html', 'json', 'array']);
|
||||
|
||||
$this->assertSame('Presenter "xml" not found, did you forget to register it? Available presenters: [html, json, array]', $exception->getMessage());
|
||||
}
|
||||
|
||||
public function testCreateWithEmptyAvailablePresenters(): void
|
||||
{
|
||||
$exception = PresenterNotFoundException::create('xml', []);
|
||||
|
||||
$this->assertSame('Presenter "xml" not found, did you forget to register it?', $exception->getMessage());
|
||||
}
|
||||
|
||||
public function testIsException(): void
|
||||
{
|
||||
$exception = PresenterNotFoundException::create('test');
|
||||
|
||||
$this->assertInstanceOf(\Exception::class, $exception);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Flasher\Tests\Prime\Exception;
|
||||
|
||||
use Flasher\Prime\Exception\PresetNotFoundException;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class PresetNotFoundExceptionTest extends TestCase
|
||||
{
|
||||
public function testCreateWithPresetOnly(): void
|
||||
{
|
||||
$exception = PresetNotFoundException::create('custom_preset');
|
||||
|
||||
$this->assertSame('Preset "custom_preset" not found, did you forget to register it?', $exception->getMessage());
|
||||
}
|
||||
|
||||
public function testCreateWithAvailablePresets(): void
|
||||
{
|
||||
$exception = PresetNotFoundException::create('custom_preset', ['created', 'updated', 'deleted']);
|
||||
|
||||
$this->assertSame('Preset "custom_preset" not found, did you forget to register it? Available presets: [created, updated, deleted]', $exception->getMessage());
|
||||
}
|
||||
|
||||
public function testCreateWithEmptyAvailablePresets(): void
|
||||
{
|
||||
$exception = PresetNotFoundException::create('custom_preset', []);
|
||||
|
||||
$this->assertSame('Preset "custom_preset" not found, did you forget to register it?', $exception->getMessage());
|
||||
}
|
||||
|
||||
public function testIsException(): void
|
||||
{
|
||||
$exception = PresetNotFoundException::create('test');
|
||||
|
||||
$this->assertInstanceOf(\Exception::class, $exception);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user