|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Selective\BasePath\Test; |
| 4 | + |
| 5 | +use PHPUnit\Framework\TestCase; |
| 6 | +use Selective\BasePath\BasePathDetector; |
| 7 | + |
| 8 | +/** |
| 9 | + * Test. |
| 10 | + */ |
| 11 | +class ApacheTest extends TestCase |
| 12 | +{ |
| 13 | + /** |
| 14 | + * @var array |
| 15 | + */ |
| 16 | + private $server; |
| 17 | + |
| 18 | + /** |
| 19 | + * Set Up. |
| 20 | + * |
| 21 | + * @return void |
| 22 | + */ |
| 23 | + protected function setUp(): void |
| 24 | + { |
| 25 | + $this->server = [ |
| 26 | + 'REQUEST_METHOD' => 'GET', |
| 27 | + 'REQUEST_SCHEME' => 'http', |
| 28 | + 'HTTP_HOST' => 'localhost', |
| 29 | + 'SERVER_PORT' => '80', |
| 30 | + 'REQUEST_URI' => '/', |
| 31 | + 'SERVER_PROTOCOL' => 'HTTP/1.1', |
| 32 | + 'SCRIPT_NAME' => '', |
| 33 | + 'REQUEST_TIME_FLOAT' => microtime(true), |
| 34 | + 'REQUEST_TIME' => microtime(), |
| 35 | + ]; |
| 36 | + } |
| 37 | + |
| 38 | + /** |
| 39 | + * Create instance. |
| 40 | + * |
| 41 | + * @return BasePathDetector The detector |
| 42 | + */ |
| 43 | + private function createInstance(): BasePathDetector |
| 44 | + { |
| 45 | + return new BasePathDetector($this->server, 'apache2handler'); |
| 46 | + } |
| 47 | + |
| 48 | + /** |
| 49 | + * Test. |
| 50 | + * |
| 51 | + * @return void |
| 52 | + */ |
| 53 | + public function testDefault(): void |
| 54 | + { |
| 55 | + $detector = $this->createInstance(); |
| 56 | + $basePath = $detector->getBasePath(); |
| 57 | + |
| 58 | + static::assertSame('', $basePath); |
| 59 | + } |
| 60 | + |
| 61 | + /** |
| 62 | + * Test. |
| 63 | + * |
| 64 | + * @return void |
| 65 | + */ |
| 66 | + public function testUnknownServer(): void |
| 67 | + { |
| 68 | + $detector = new BasePathDetector($this->server, ''); |
| 69 | + $basePath = $detector->getBasePath(); |
| 70 | + |
| 71 | + static::assertSame('', $basePath); |
| 72 | + } |
| 73 | + |
| 74 | + /** |
| 75 | + * Test. |
| 76 | + * |
| 77 | + * @return void |
| 78 | + */ |
| 79 | + public function testSubdirectory(): void |
| 80 | + { |
| 81 | + $this->server['REQUEST_URI'] = '/public'; |
| 82 | + |
| 83 | + $detector = $this->createInstance(); |
| 84 | + $basePath = $detector->getBasePath(); |
| 85 | + |
| 86 | + static::assertSame('/public', $basePath); |
| 87 | + } |
| 88 | + |
| 89 | + /** |
| 90 | + * Test. |
| 91 | + * |
| 92 | + * @return void |
| 93 | + */ |
| 94 | + public function testWithoutRequestUri(): void |
| 95 | + { |
| 96 | + unset($this->server['REQUEST_URI']); |
| 97 | + |
| 98 | + $detector = $this->createInstance(); |
| 99 | + $basePath = $detector->getBasePath(); |
| 100 | + |
| 101 | + static::assertSame('', $basePath); |
| 102 | + } |
| 103 | +} |
0 commit comments