1- <?php
1+ <?php declare (strict_types= 1 );
22
33/*
44 * This file is part of Polymorphine/App package.
1313
1414use PHPUnit \Framework \TestCase ;
1515use Polymorphine \App \AppHandler ;
16- use Polymorphine \App \Tests \Doubles \FakeMiddleware ;
17- use Polymorphine \App \Tests \Doubles \FakeUri ;
18- use Polymorphine \App \Tests \Fixtures \HeadersState ;
19- use Polymorphine \App \Tests \Fixtures \ShutdownState ;
2016use Polymorphine \Container ;
21- use Polymorphine \Container \Exception ;
22- use Psr \Http \Server \RequestHandlerInterface ;
23- use Psr \Http \Message \ResponseInterface ;
24- use Psr \Container \ContainerInterface ;
2517
2618require_once __DIR__ . '/Fixtures/shutdown-functions.php ' ;
2719require_once __DIR__ . '/Fixtures/header-functions.php ' ;
@@ -32,26 +24,25 @@ class AppHandlerIntegrationTest extends TestCase
3224 public function testInstantiation ()
3325 {
3426 $ this ->assertInstanceOf (AppHandler::class, $ this ->app ());
35- $ this ->assertInstanceOf (RequestHandlerInterface::class, $ this ->app ());
3627 }
3728
38- public function testConfig_ReturnsRegistryInput ()
29+ public function testConfig_ReturnsSetupEntry ()
3930 {
4031 $ app = $ this ->app ();
41- $ this ->assertInstanceOf (Container \RecordSetup ::class, $ app ->config ('test ' ));
32+ $ this ->assertInstanceOf (Container \Setup \Entry ::class, $ app ->config ('test ' ));
4233 }
4334
4435 public function testRoutingContainerIntegration ()
4536 {
46- $ app = $ this ->app (['test ' => new Container \Record \ValueRecord ('Hello World! ' )]);
37+ $ app = $ this ->app (['test ' => new Container \Records \ Record \ValueRecord ('Hello World! ' )]);
4738 $ response = $ app ->handle (new Doubles \FakeServerRequest ());
48- $ this ->assertSame ('//example.com/foo/bar: Hello World! ' , $ response ->body );
39+ $ this ->assertSame ('//example.com/foo/bar: Hello World! ' , ( string ) $ response ->getBody () );
4940 }
5041
5142 public function testRepeatedHandleCallsWithMiddlewareProcessing_ReturnsEqualResponse ()
5243 {
5344 $ app = $ this ->middlewareContextsApp ();
54- $ request = new Doubles \FakeServerRequest ('GET ' , FakeUri::fromString ('/test ' ));
45+ $ request = new Doubles \FakeServerRequest ('GET ' , Doubles \ FakeUri::fromString ('/test ' ));
5546 $ response = $ app ->handle ($ request );
5647
5748 $ expectedBody = 'outerContext innerContext /test: MAIN innerContext outerContext ' ;
@@ -61,8 +52,8 @@ public function testRepeatedHandleCallsWithMiddlewareProcessing_ReturnsEqualResp
6152
6253 public function testInstanceWithDefinedInternalContainerId_ThrowsException ()
6354 {
64- $ this ->expectException (Exception \InvalidIdException ::class);
65- $ this ->app ([AppHandler::ROUTER_ID => new Container \Record \ValueRecord ('Hello World! ' )]);
55+ $ this ->expectException (Container \ Setup \ Exception \OverwriteRuleException ::class);
56+ $ this ->app ([AppHandler::ROUTER_ID => new Container \Records \ Record \ValueRecord ('Hello World! ' )]);
6657 }
6758
6859 public function testFallbackNotFoundRoute ()
@@ -72,47 +63,46 @@ public function testFallbackNotFoundRoute()
7263 $ app ->notFoundResponse = new Doubles \FakeResponse ();
7364
7465 $ response = $ app ->handle (new Doubles \FakeServerRequest ());
75- $ this ->assertInstanceOf (ResponseInterface::class, $ response );
7666 $ this ->assertInstanceOf (Doubles \FakeResponse::class, $ response );
7767 $ this ->assertSame ($ app ->notFoundResponse , $ response );
7868 }
7969
8070 public function testShutdownRegisteredOnProduction ()
8171 {
82- ShutdownState::reset ();
83- ShutdownState::$ override = true ;
72+ Fixtures \ ShutdownState::reset ();
73+ Fixtures \ ShutdownState::$ override = true ;
8474 $ this ->assertFalse (getenv (AppHandler::DEV_ENVIRONMENT ));
8575 $ this ->app ();
86- $ this ->assertTrue (is_callable ($ callback = ShutdownState::$ callback ));
76+ $ this ->assertTrue (is_callable ($ callback = Fixtures \ ShutdownState::$ callback ));
8777 $ callback ();
88- $ this ->assertSame (503 , ShutdownState::$ status );
89- $ this ->assertSame ([], HeadersState::$ headers );
90- $ this ->assertTrue (ShutdownState::$ outputBufferCleared );
78+ $ this ->assertSame (503 , Fixtures \ ShutdownState::$ status );
79+ $ this ->assertSame ([], Fixtures \ HeadersState::$ headers );
80+ $ this ->assertTrue (Fixtures \ ShutdownState::$ outputBufferCleared );
9181 }
9282
9383 public function testShutdownNotRegisteredOnDevelopment ()
9484 {
95- ShutdownState::reset ();
96- ShutdownState::$ override = true ;
85+ Fixtures \ ShutdownState::reset ();
86+ Fixtures \ ShutdownState::$ override = true ;
9787 putenv (AppHandler::DEV_ENVIRONMENT . '=1 ' );
9888 $ this ->assertNotFalse (getenv (AppHandler::DEV_ENVIRONMENT ));
9989 $ this ->app ();
100- $ this ->assertFalse (is_callable (ShutdownState::$ callback ));
90+ $ this ->assertFalse (is_callable (Fixtures \ ShutdownState::$ callback ));
10191 }
10292
103- private function app (array $ records = [], bool $ secure = false )
93+ private function app (array $ records = [], bool $ secure = false ): Doubles \ MockedAppHandler
10494 {
105- $ setup = $ secure ? new Container \TrackingContainerSetup ($ records ) : new Container \ContainerSetup ($ records );
95+ $ setup = $ secure ? new Container \Setup \ Build \ ValidatedBuild ($ records ) : new Container \Setup \ Build ($ records );
10696 return new Doubles \MockedAppHandler ($ setup );
10797 }
10898
109- private function middlewareContextsApp ()
99+ private function middlewareContextsApp (): Doubles \ MockedAppHandler
110100 {
111101 $ app = $ this ->app ();
112- $ app ->config ('test ' )->set ('MAIN ' );
113- $ app ->middleware ('one ' )->set (new FakeMiddleware ('outerContext ' ));
114- $ app ->middleware ('two ' )->invoke (function (ContainerInterface $ c ) {
115- return new FakeMiddleware ($ c ->get ('one ' )->inContext ? 'innerContext ' : '--- error --- ' );
102+ $ app ->config ('test ' )->value ('MAIN ' );
103+ $ app ->middleware ('one ' )->value (new Doubles \ FakeMiddleware ('outerContext ' ));
104+ $ app ->middleware ('two ' )->callback (function ($ c ) {
105+ return new Doubles \ FakeMiddleware ($ c ->get ('one ' )->inContext ? 'innerContext ' : '--- error --- ' );
116106 });
117107
118108 return $ app ;
0 commit comments