5
5
namespace phpDocumentor \Reflection \DocBlock \Tags ;
6
6
7
7
use Exception ;
8
+ use InvalidArgumentException ;
8
9
use PHPUnit \Framework \TestCase ;
9
10
10
11
/**
@@ -28,6 +29,7 @@ public function testCreationWithoutError() : void
28
29
29
30
/**
30
31
* @covers ::withError
32
+ * @covers ::__toString
31
33
*/
32
34
public function testCreationWithError () : void
33
35
{
@@ -36,6 +38,59 @@ public function testCreationWithError() : void
36
38
37
39
self ::assertSame ('name ' , $ tag ->getName ());
38
40
self ::assertSame ('@name Body ' , $ tag ->render ());
41
+ self ::assertSame ('Body ' , (string )$ tag );
39
42
self ::assertSame ($ exception , $ tag ->getException ());
40
43
}
44
+
45
+ public function testCreationWithErrorContainingClosure () : void
46
+ {
47
+ try {
48
+ $ this ->throwExceptionFromClosureWithClosureArgument ();
49
+ } catch (Exception $ e ) {
50
+ $ parentException = new Exception ('test ' , 0 , $ e );
51
+ $ tag = InvalidTag::create ('Body ' , 'name ' )->withError ($ parentException );
52
+ self ::assertSame ('name ' , $ tag ->getName ());
53
+ self ::assertSame ('@name Body ' , $ tag ->render ());
54
+ self ::assertSame ($ parentException , $ tag ->getException ());
55
+ self ::assertStringStartsWith ('(Closure at ' , $ tag ->getException ()->getPrevious ()->getTrace ()[0 ]['args ' ][0 ]);
56
+ self ::assertStringContainsString (__FILE__ , $ tag ->getException ()->getPrevious ()->getTrace ()[0 ]['args ' ][0 ]);
57
+ self ::assertEquals ($ parentException , unserialize (serialize ($ parentException )));
58
+ }
59
+ }
60
+
61
+ private function throwExceptionFromClosureWithClosureArgument ()
62
+ {
63
+ $ function = function () {
64
+ throw new InvalidArgumentException ();
65
+ };
66
+
67
+ $ function ($ function );
68
+ }
69
+
70
+ public function testCreationWithErrorContainingResource ()
71
+ {
72
+ try {
73
+ $ this ->throwExceptionWithResourceArgument ();
74
+ } catch (Exception $ e ) {
75
+ $ parentException = new Exception ('test ' , 0 , $ e );
76
+ $ tag = InvalidTag::create ('Body ' , 'name ' )->withError ($ parentException );
77
+ self ::assertSame ('name ' , $ tag ->getName ());
78
+ self ::assertSame ('@name Body ' , $ tag ->render ());
79
+ self ::assertSame ($ parentException , $ tag ->getException ());
80
+ self ::assertStringStartsWith (
81
+ 'resource(stream) ' ,
82
+ $ tag ->getException ()->getPrevious ()->getTrace ()[0 ]['args ' ][0 ])
83
+ ;
84
+ self ::assertEquals ($ parentException , unserialize (serialize ($ parentException )));
85
+ }
86
+ }
87
+
88
+ private function throwExceptionWithResourceArgument ()
89
+ {
90
+ $ function = function () {
91
+ throw new InvalidArgumentException ();
92
+ };
93
+
94
+ $ function (fopen (__FILE__ , 'r ' ));
95
+ }
41
96
}
0 commit comments