| Total Complexity | 16 | 
| Total Lines | 225 | 
| Duplicated Lines | 0 % | 
| Changes | 0 | ||
| 1 | <?php  | 
            ||
| 22 | class HttpTest extends TestCase  | 
            ||
| 
                                                                                                    
                         1 ignored issue 
                            –
                            show
                         | 
                |||
| 23 | { | 
            ||
| 24 | /** @var App|MockInterface */  | 
            ||
| 25 | protected $app;  | 
            ||
| 26 | |||
| 27 | /** @var Http|MockInterface */  | 
            ||
| 28 | protected $http;  | 
            ||
| 29 | |||
| 30 | protected function tearDown(): void  | 
            ||
| 31 |     { | 
            ||
| 32 | m::close();  | 
            ||
| 33 | }  | 
            ||
| 34 | |||
| 35 | protected function setUp()  | 
            ||
| 36 |     { | 
            ||
| 37 | $this->app = m::mock(App::class)->makePartial();  | 
            ||
| 38 | |||
| 39 | $this->http = m::mock(Http::class, [$this->app])->shouldAllowMockingProtectedMethods()->makePartial();  | 
            ||
| 40 | }  | 
            ||
| 41 | |||
| 42 | protected function prepareApp($request, $response)  | 
            ||
| 67 | }  | 
            ||
| 68 | |||
| 69 | public function testRun()  | 
            ||
| 70 |     { | 
            ||
| 71 |         $root = vfsStream::setup('rootDir', null, [ | 
            ||
| 72 | 'app' => [  | 
            ||
| 73 | 'controller' => [],  | 
            ||
| 74 | 'middleware.php' => '<?php return [];',  | 
            ||
| 75 | ],  | 
            ||
| 76 | 'route' => [  | 
            ||
| 77 | 'route.php' => '<?php return [];',  | 
            ||
| 78 | ],  | 
            ||
| 79 | ]);  | 
            ||
| 80 | |||
| 81 | $this->http->multi(false);  | 
            ||
| 82 | |||
| 83 |         $this->app->shouldReceive('getBasePath')->andReturn($root->getChild('app')->url() . DIRECTORY_SEPARATOR); | 
            ||
| 84 |         $this->app->shouldReceive('getRootPath')->andReturn($root->url() . DIRECTORY_SEPARATOR); | 
            ||
| 85 | |||
| 86 | $request = m::mock(Request::class)->makePartial();  | 
            ||
| 87 | $response = m::mock(Response::class)->makePartial();  | 
            ||
| 88 | |||
| 89 | $this->prepareApp($request, $response);  | 
            ||
| 90 | |||
| 91 | $this->assertEquals($response, $this->http->run($request));  | 
            ||
| 92 | |||
| 93 | $this->assertFalse($this->http->isMulti());  | 
            ||
| 94 | }  | 
            ||
| 95 | |||
| 96 | /**  | 
            ||
| 97 | * @param $request  | 
            ||
| 
                                                                                                                                                        
                         1 ignored issue 
                            –
                            show
                         | 
                |||
| 98 | * @param $auto  | 
            ||
| 
                                                                                                                                                        
                         1 ignored issue 
                            –
                            show
                         | 
                |||
| 99 | * @param $name  | 
            ||
| 
                                                                                                                                                        
                         1 ignored issue 
                            –
                            show
                         | 
                |||
| 100 | * @dataProvider multiAppRunProvider  | 
            ||
| 101 | */  | 
            ||
| 102 | public function testMultiAppRun($request, $auto, $name, $path = null)  | 
            ||
| 103 |     { | 
            ||
| 104 |         $root = vfsStream::setup('rootDir', null, [ | 
            ||
| 105 | 'app' => [  | 
            ||
| 106 | 'middleware.php' => '<?php return [];',  | 
            ||
| 107 | 'app1' => [  | 
            ||
| 108 | 'common.php' => '',  | 
            ||
| 109 | 'event.php' => '<?php return ["bind"=>[],"listen"=>[],"subscribe"=>[]];',  | 
            ||
| 110 | 'provider.php' => '<?php return [];',  | 
            ||
| 111 | 'middleware.php' => '<?php return [];',  | 
            ||
| 112 | 'config' => [  | 
            ||
| 113 | 'app.php' => '<?php return [];',  | 
            ||
| 114 | ],  | 
            ||
| 115 | ],  | 
            ||
| 116 | ],  | 
            ||
| 117 | 'config' => [  | 
            ||
| 118 | 'app.php' => '<?php return [];',  | 
            ||
| 119 | 'app1' => [  | 
            ||
| 120 | 'app.php' => '<?php return [];',  | 
            ||
| 121 | ],  | 
            ||
| 122 | ],  | 
            ||
| 123 | 'route' => [  | 
            ||
| 124 | 'route.php' => '<?php return [];',  | 
            ||
| 125 | ],  | 
            ||
| 126 | ]);  | 
            ||
| 127 | |||
| 128 | $config = m::mock(Config::class)->makePartial();  | 
            ||
| 129 | |||
| 130 |         $config->shouldReceive('get')->with('app.auto_multi_app', false)->andReturn($auto); | 
            ||
| 131 | |||
| 132 |         $config->shouldReceive('get')->with('app.domain_bind', [])->andReturn([ | 
            ||
| 133 | 'www.domain.com' => 'app1',  | 
            ||
| 134 | 'app2' => 'app2',  | 
            ||
| 135 | ]);  | 
            ||
| 136 | |||
| 137 |         $config->shouldReceive('get')->with('app.app_map', [])->andReturn([ | 
            ||
| 138 | 'some1' => 'app3',  | 
            ||
| 139 | ]);  | 
            ||
| 140 | |||
| 141 |         $this->app->shouldReceive('get')->with('config')->andReturn($config); | 
            ||
| 142 | |||
| 143 |         $this->app->shouldReceive('getBasePath')->andReturn($root->getChild('app')->url() . DIRECTORY_SEPARATOR); | 
            ||
| 144 |         $this->app->shouldReceive('getRootPath')->andReturn($root->url() . DIRECTORY_SEPARATOR); | 
            ||
| 145 |         $this->app->shouldReceive('getConfigPath')->andReturn($root->getChild('config')->url() . DIRECTORY_SEPARATOR); | 
            ||
| 146 | |||
| 147 | $response = m::mock(Response::class)->makePartial();  | 
            ||
| 148 | |||
| 149 | $this->prepareApp($request, $response);  | 
            ||
| 150 | |||
| 151 | $this->assertTrue($this->http->isMulti());  | 
            ||
| 152 | |||
| 153 |         if ($name === null) { | 
            ||
| 154 |             $this->http->shouldReceive('reportException')->once(); | 
            ||
| 155 | |||
| 156 |             $this->http->shouldReceive('renderException')->once()->andReturn($response); | 
            ||
| 157 | }  | 
            ||
| 158 | |||
| 159 |         if (!$auto) { | 
            ||
| 160 | $this->http->name($name);  | 
            ||
| 161 | }  | 
            ||
| 162 | |||
| 163 |         if ($path) { | 
            ||
| 164 | $this->http->path($path);  | 
            ||
| 165 | }  | 
            ||
| 166 | |||
| 167 | $this->assertEquals($response, $this->http->run($request));  | 
            ||
| 168 | |||
| 169 |         if ($name !== null) { | 
            ||
| 170 | $this->assertEquals($name, $this->http->getName());  | 
            ||
| 171 | }  | 
            ||
| 172 | |||
| 173 |         if ($name === 'app1' || $name === 'app2') { | 
            ||
| 174 | $this->assertTrue($this->http->isBindDomain());  | 
            ||
| 175 | }  | 
            ||
| 176 |         if ($path) { | 
            ||
| 177 | $this->assertEquals($path, $this->app->getAppPath());  | 
            ||
| 178 | }  | 
            ||
| 179 | }  | 
            ||
| 180 | |||
| 181 | public function multiAppRunProvider()  | 
            ||
| 182 |     { | 
            ||
| 183 | $request1 = m::mock(Request::class)->makePartial();  | 
            ||
| 184 |         $request1->shouldReceive('subDomain')->andReturn('www'); | 
            ||
| 185 |         $request1->shouldReceive('host')->andReturn('www.domain.com'); | 
            ||
| 186 | |||
| 187 | $request2 = m::mock(Request::class)->makePartial();  | 
            ||
| 188 |         $request2->shouldReceive('subDomain')->andReturn('app2'); | 
            ||
| 189 |         $request2->shouldReceive('host')->andReturn('app2.domain.com'); | 
            ||
| 190 | |||
| 191 | $request3 = m::mock(Request::class)->makePartial();  | 
            ||
| 192 |         $request3->shouldReceive('pathinfo')->andReturn('some1/a/b/c'); | 
            ||
| 193 | |||
| 194 | $request4 = m::mock(Request::class)->makePartial();  | 
            ||
| 195 |         $request4->shouldReceive('pathinfo')->andReturn('app3/a/b/c'); | 
            ||
| 196 | |||
| 197 | $request5 = m::mock(Request::class)->makePartial();  | 
            ||
| 198 |         $request5->shouldReceive('pathinfo')->andReturn('some2/a/b/c'); | 
            ||
| 199 | |||
| 200 | return [  | 
            ||
| 201 | [$request1, true, 'app1'],  | 
            ||
| 202 | [$request2, true, 'app2'],  | 
            ||
| 203 | [$request3, true, 'app3'],  | 
            ||
| 204 | [$request4, true, null],  | 
            ||
| 205 | [$request5, true, 'some2', 'path'],  | 
            ||
| 206 | [$request1, false, 'some3'],  | 
            ||
| 207 | ];  | 
            ||
| 208 | }  | 
            ||
| 209 | |||
| 210 | public function testRunWithException()  | 
            ||
| 231 | }  | 
            ||
| 232 | |||
| 233 | public function testEnd()  | 
            ||
| 247 | }  | 
            ||
| 248 | |||
| 249 | }  | 
            ||
| 250 |