mirror of
https://github.com/danog/Valinor.git
synced 2024-12-02 17:48:14 +01:00
a805ba0442
A new class `NodeMessage` is used to wrap messages added to a node during the mapping. This class will allow further features by giving access to useful data related to the bound node. BREAKING CHANGE: as of now every message is wrapped into a `NodeMessage` it is therefore not possible to check whether the message is an instance of `Throwable` — a new method `$message->isError()` is now to be used for such cases.
41 lines
1.2 KiB
PHP
41 lines
1.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace CuyZ\Valinor\Tests\Unit\Mapper\Tree\Message;
|
|
|
|
use CuyZ\Valinor\Mapper\Tree\Message\Message;
|
|
use CuyZ\Valinor\Mapper\Tree\Message\ThrowableMessage;
|
|
use PHPUnit\Framework\TestCase;
|
|
use RuntimeException;
|
|
|
|
final class ThrowableMessageTest extends TestCase
|
|
{
|
|
public function test_properties_can_be_accessed(): void
|
|
{
|
|
$message = 'some message';
|
|
$code = 'some code';
|
|
|
|
$codedError = ThrowableMessage::new($message, $code);
|
|
|
|
self::assertSame($message, (string)$codedError);
|
|
self::assertSame($code, $codedError->code());
|
|
}
|
|
|
|
public function test_from_message_returns_message(): void
|
|
{
|
|
$message = new class ('some message') extends RuntimeException implements Message { };
|
|
|
|
self::assertSame($message, ThrowableMessage::from($message));
|
|
}
|
|
|
|
public function test_from_throwable_returns_message(): void
|
|
{
|
|
$message = new RuntimeException('some message', 1337);
|
|
$throwableMessage = ThrowableMessage::from($message);
|
|
|
|
self::assertSame('some message', (string)$throwableMessage);
|
|
self::assertSame('1337', $throwableMessage->code()); // @phpstan-ignore-line
|
|
}
|
|
}
|