2021-11-28 17:43:02 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace CuyZ\Valinor\Tests\Unit\Mapper\Tree\Message;
|
|
|
|
|
2021-12-31 13:10:20 +01:00
|
|
|
use CuyZ\Valinor\Mapper\Tree\Message\Message;
|
2021-11-28 17:43:02 +01:00
|
|
|
use CuyZ\Valinor\Mapper\Tree\Message\ThrowableMessage;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
2021-12-31 13:10:20 +01:00
|
|
|
use RuntimeException;
|
2021-11-28 17:43:02 +01:00
|
|
|
|
|
|
|
final class ThrowableMessageTest extends TestCase
|
|
|
|
{
|
|
|
|
public function test_properties_can_be_accessed(): void
|
|
|
|
{
|
|
|
|
$message = 'some message';
|
|
|
|
$code = 'some code';
|
|
|
|
|
2021-12-31 13:10:20 +01:00
|
|
|
$codedError = ThrowableMessage::new($message, $code);
|
2021-11-28 17:43:02 +01:00
|
|
|
|
|
|
|
self::assertSame($message, (string)$codedError);
|
|
|
|
self::assertSame($code, $codedError->code());
|
|
|
|
}
|
2021-12-31 13:10:20 +01:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
2021-11-28 17:43:02 +01:00
|
|
|
}
|