Standardize exception message format and add exception tests

This commit is contained in:
Younes ENNAJI
2026-03-02 04:06:51 +00:00
parent e126813835
commit d4abef58eb
7 changed files with 122 additions and 3 deletions
+2
View File
@@ -28,6 +28,8 @@
* fix [Flasher] Add type validation for callable presenter return values in ResponseManager with descriptive error messages
* fix [Flasher] Fix FlasherPlugin::normalizePlugins() losing scripts/styles when both top-level and plugin-level configs are provided - replaced array union operator with array_merge
* fix [Flasher] Simplify FlasherPlugin::normalizeFlashBag() by replacing redundant array union with direct array_merge
* fix [Flasher] Standardize exception message format in PresetNotFoundException to use brackets like other exceptions
* fix [Flasher] Standardize exception message wording in CriteriaNotRegisteredException to use "not found" instead of "is not found"
## [v2.1.3](https://github.com/php-flasher/php-flasher/compare/v2.1.2...v2.1.3) - 2025-01-25
@@ -11,7 +11,7 @@ final class CriteriaNotRegisteredException extends \Exception
*/
public static function create(string $alias, array $availableCriteria = []): self
{
$message = \sprintf('Criteria "%s" is not found, did you forget to register it?', $alias);
$message = \sprintf('Criteria "%s" not found, did you forget to register it?', $alias);
if ([] !== $availableCriteria) {
$message .= \sprintf(' Available criteria: [%s]', implode(', ', $availableCriteria));
@@ -14,7 +14,7 @@ final class PresetNotFoundException extends \Exception
$message = \sprintf('Preset "%s" not found, did you forget to register it?', $preset);
if ([] !== $availablePresets) {
$message .= \sprintf(' Available presets: "%s"', implode('", "', $availablePresets));
$message .= \sprintf(' Available presets: [%s]', implode(', ', $availablePresets));
}
return new self($message);
@@ -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);
}
}