endtoend-test-psl/tests/Psl/Asio/WrapTest.php
2020-03-01 21:52:25 +01:00

43 lines
1.1 KiB
PHP

<?php
declare(strict_types=1);
namespace Psl\Tests\Asio;
use PHPUnit\Framework\TestCase;
use Psl\Asio;
use Psl\Exception\InvariantViolationException;
class WrapTest extends TestCase
{
public function testWrapException(): void
{
$exception = new \Exception('foo');
$wrapper = Asio\wrap(static function () use ($exception): void {
throw $exception;
});
$this->assertFalse($wrapper->isSucceeded());
$this->assertTrue($wrapper->isFailed());
$this->assertSame($exception, $wrapper->getException());
$this->expectExceptionObject($exception);
$wrapper->getResult();
}
public function testWrapResult(): void
{
$wrapper = Asio\wrap(static function (): string {
return 'foo';
});
$this->assertTrue($wrapper->isSucceeded());
$this->assertFalse($wrapper->isFailed());
$this->assertSame('foo', $wrapper->getResult());
$this->expectException(InvariantViolationException::class);
$this->expectExceptionMessage('No exception thrown');
$wrapper->getException();
}
}