2929
3030class ApplicationTest extends \PHPUnit_Framework_TestCase
3131{
32- /**
33- *
34- */
35- protected function tearDown ()
32+ public function testAppInstanceAccessInClosure ()
3633 {
37- restore_error_handler ();
38- restore_exception_handler ();
34+
35+ $ app = new Application (true );
36+
37+ $ appInstanceInClosure = false ;
38+
39+ $ app ->get (
40+ '/ ' ,
41+ function (ServerRequestInterface $ request , ResponseInterface $ response , array $ args = [])
42+ use (&$ appInstanceInClosure ){
43+ $ that = $ this ;
44+ $ appInstanceInClosure = $ this instanceof Application \ApplicationInterface;
45+ return $ response ;
46+ }
47+ );
48+
49+ $ request = ServerRequestFactory::fromGlobals ();
50+ $ response = $ app ->handle ($ request );
51+
52+ $ this ->assertTrue ($ appInstanceInClosure );
53+ $ this ->assertEquals (200 , $ response ->getStatusCode ());
54+
3955 }
4056
4157
@@ -508,7 +524,8 @@ public function testAjaxRequestRecogniseHTML()
508524 $ this ->assertEquals ('application/json ' , $ app ->getContentType ());
509525 }
510526
511- public function testRootRequestWithoutPublicAsDocumentRoot (){
527+ public function testRootRequestWithoutPublicAsDocumentRoot ()
528+ {
512529 $ app = new Application ();
513530 $ app ->get ('/ ' , function (ServerRequestInterface $ request , ResponseInterface $ response ) {
514531 $ response ->getBody ()->write ('<h1>HELLO</h1> ' );
@@ -525,7 +542,9 @@ public function testRootRequestWithoutPublicAsDocumentRoot(){
525542 $ this ->assertEquals ('text/html ' , $ app ->getContentType ());
526543 $ _SERVER = $ tmpServer ;
527544 }
528- public function testExampleRequestWithoutPublicAsDocumentRoot (){
545+
546+ public function testExampleRequestWithoutPublicAsDocumentRoot ()
547+ {
529548 $ app = new Application ();
530549
531550 $ app ->get ('/ ' , function (ServerRequestInterface $ request , ResponseInterface $ response ) {
@@ -549,4 +568,15 @@ public function testExampleRequestWithoutPublicAsDocumentRoot(){
549568 $ this ->assertEquals ('text/html ' , $ app ->getContentType ());
550569 $ _SERVER = $ tmpServer ;
551570 }
571+
572+ /**
573+ *
574+ */
575+ protected function tearDown ()
576+ {
577+ restore_error_handler ();
578+ restore_exception_handler ();
579+ }
580+
581+
552582}
0 commit comments