mirror of
https://github.com/barryvdh/ReflectionDocBlock.git
synced 2026-08-18 01:57:13 +00:00
Fix serialization issue of InvalidTag
This commit is contained in:
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace phpDocumentor\Reflection\DocBlock\Tags;
|
||||
|
||||
use Exception;
|
||||
use InvalidArgumentException;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
@@ -28,6 +29,7 @@ final class InvalidTagTest extends TestCase
|
||||
|
||||
/**
|
||||
* @covers ::withError
|
||||
* @covers ::__toString
|
||||
*/
|
||||
public function testCreationWithError() : void
|
||||
{
|
||||
@@ -36,6 +38,59 @@ final class InvalidTagTest extends TestCase
|
||||
|
||||
self::assertSame('name', $tag->getName());
|
||||
self::assertSame('@name Body', $tag->render());
|
||||
self::assertSame('Body', (string)$tag);
|
||||
self::assertSame($exception, $tag->getException());
|
||||
}
|
||||
|
||||
public function testCreationWithErrorContainingClosure() : void
|
||||
{
|
||||
try {
|
||||
$this->throwExceptionFromClosureWithClosureArgument();
|
||||
} catch (Exception $e) {
|
||||
$parentException = new Exception('test', 0, $e);
|
||||
$tag = InvalidTag::create('Body', 'name')->withError($parentException);
|
||||
self::assertSame('name', $tag->getName());
|
||||
self::assertSame('@name Body', $tag->render());
|
||||
self::assertSame($parentException, $tag->getException());
|
||||
self::assertStringStartsWith('(Closure at', $tag->getException()->getPrevious()->getTrace()[0]['args'][0]);
|
||||
self::assertStringContainsString(__FILE__, $tag->getException()->getPrevious()->getTrace()[0]['args'][0]);
|
||||
self::assertEquals($parentException, unserialize(serialize($parentException)));
|
||||
}
|
||||
}
|
||||
|
||||
private function throwExceptionFromClosureWithClosureArgument()
|
||||
{
|
||||
$function = function() {
|
||||
throw new InvalidArgumentException();
|
||||
};
|
||||
|
||||
$function($function);
|
||||
}
|
||||
|
||||
public function testCreationWithErrorContainingResource()
|
||||
{
|
||||
try {
|
||||
$this->throwExceptionWithResourceArgument();
|
||||
} catch (Exception $e) {
|
||||
$parentException = new Exception('test', 0, $e);
|
||||
$tag = InvalidTag::create('Body', 'name')->withError($parentException);
|
||||
self::assertSame('name', $tag->getName());
|
||||
self::assertSame('@name Body', $tag->render());
|
||||
self::assertSame($parentException, $tag->getException());
|
||||
self::assertStringStartsWith(
|
||||
'resource(stream)',
|
||||
$tag->getException()->getPrevious()->getTrace()[0]['args'][0])
|
||||
;
|
||||
self::assertEquals($parentException, unserialize(serialize($parentException)));
|
||||
}
|
||||
}
|
||||
|
||||
private function throwExceptionWithResourceArgument()
|
||||
{
|
||||
$function = function() {
|
||||
throw new InvalidArgumentException();
|
||||
};
|
||||
|
||||
$function(fopen(__FILE__, 'r'));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user