55namespace phpDocumentor \Reflection \DocBlock \Tags ;
66
77use Exception ;
8+ use InvalidArgumentException ;
89use PHPUnit \Framework \TestCase ;
910
1011/**
@@ -28,6 +29,7 @@ public function testCreationWithoutError() : void
2829
2930 /**
3031 * @covers ::withError
32+ * @covers ::__toString
3133 */
3234 public function testCreationWithError () : void
3335 {
@@ -36,6 +38,59 @@ public function testCreationWithError() : void
3638
3739 self ::assertSame ('name ' , $ tag ->getName ());
3840 self ::assertSame ('@name Body ' , $ tag ->render ());
41+ self ::assertSame ('Body ' , (string )$ tag );
3942 self ::assertSame ($ exception , $ tag ->getException ());
4043 }
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+ }
4196}
0 commit comments