matrix-api/tests/Unit/MessageTest.php

84 lines
1.9 KiB
PHP
Raw Normal View History

2024-03-16 00:08:24 +01:00
<?php
namespace Zoomyboy\MatrixApi\Tests\Unit;
use Exception;
use Illuminate\Http\Client\HttpClientException;
use Zoomyboy\MatrixApi\Matrix;
use Zoomyboy\MatrixApi\ReportsToMatrix;
use Zoomyboy\MatrixApi\Tests\TestCase;
class MessageTest extends TestCase
{
/**
* @covers Matrix
*/
public function testItSendsMessageViaMethod(): void
{
$this->httpFake->sendsMessage();
app(Matrix::class)->message('lalatt');
$this->httpFake->assertMessageSent('lalatt');
}
/**
* @covers Matrix
*/
public function testItSendsMessageWithException(): void
{
$this->httpFake->sendsMessage();
app(Matrix::class)->exception(new TestException('The error Message'));
$this->httpFake->assertMessageSent('<p>The error Message</p>');
}
/**
* @covers Matrix
*/
public function testItSendsExceptionWhenExceptionIsReported(): void
{
$this->httpFake->sendsMessage();
try {
throw new MatrixException('This is the error');
} catch (MatrixException $e) {
$e->report();
}
$this->httpFake->assertMessageSent('<p>This is the error</p>');
}
/**
* @covers Matrix
*/
public function testItSendsExceptionsWithStringParameters(): void
{
$this->httpFake->sendsMessage();
app(Matrix::class)->exception((new StringPropertyException('This is the error', '::param content::', 'third param')));
$this->httpFake->assertMessageSent('<p>This is the error</p><ul><li><b>testParam:</b> ::param content::</li><li><b>thirdParam:</b> third param</li></ul>');
}
}
class TestException extends Exception
{
}
class MatrixException extends Exception
{
use ReportsToMatrix;
}
class StringPropertyException extends HttpClientException
{
public function __construct(public $message, public string $testParam, public string $thirdParam)
{
parent::__construct($message);
}
}