|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * OpenMage |
| 5 | + * |
| 6 | + * This source file is subject to the Open Software License (OSL 3.0) |
| 7 | + * that is bundled with this package in the file LICENSE.txt. |
| 8 | + * It is also available at https://opensource.org/license/osl-3-0-php |
| 9 | + * |
| 10 | + * @category OpenMage |
| 11 | + * @package OpenMage_Tests |
| 12 | + * @copyright Copyright (c) 2024 The OpenMage Contributors (https://www.openmage.org) |
| 13 | + * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
| 14 | + */ |
| 15 | + |
| 16 | +declare(strict_types=1); |
| 17 | + |
| 18 | +namespace OpenMage\Tests\Unit\Error; |
| 19 | + |
| 20 | +use Error_Processor as Subject; |
| 21 | +use Generator; |
| 22 | +use PHPUnit\Framework\TestCase; |
| 23 | + |
| 24 | +class ProcessorTest extends TestCase |
| 25 | +{ |
| 26 | + public Subject $subject; |
| 27 | + public array $server; |
| 28 | + |
| 29 | + public function setUp(): void |
| 30 | + { |
| 31 | + $this->subject = new Subject(); |
| 32 | + $this->server = $_SERVER; |
| 33 | + } |
| 34 | + |
| 35 | + public function tearDown(): void |
| 36 | + { |
| 37 | + $_SERVER = $this->server; |
| 38 | + } |
| 39 | + |
| 40 | + /** |
| 41 | + * @dataProvider provideGetHostUrl |
| 42 | + * @group Error |
| 43 | + */ |
| 44 | + public function testGetHostUrl(string $expectedResult, array $serverVars): void |
| 45 | + { |
| 46 | + foreach ($serverVars as $serverVar => $value) { |
| 47 | + $_SERVER[$serverVar] = $value; |
| 48 | + } |
| 49 | + $this->assertSame($expectedResult, $this->subject->getHostUrl()); |
| 50 | + } |
| 51 | + |
| 52 | + public function provideGetHostUrl(): Generator |
| 53 | + { |
| 54 | + yield 'default' => [ |
| 55 | + 'http://localhost', |
| 56 | + [], |
| 57 | + ]; |
| 58 | + yield 'port 80' => [ |
| 59 | + 'http://localhost', |
| 60 | + [ |
| 61 | + 'SERVER_PORT' => 80, |
| 62 | + ], |
| 63 | + ]; |
| 64 | + yield 'port 8000' => [ |
| 65 | + 'http://localhost:8000', |
| 66 | + [ |
| 67 | + 'SERVER_PORT' => 8000, |
| 68 | + ], |
| 69 | + ]; |
| 70 | + yield 'name with port + port 8000' => [ |
| 71 | + 'http://localhost:8000', |
| 72 | + [ |
| 73 | + 'SERVER_NAME' => 'localhost:8000', |
| 74 | + 'SERVER_PORT' => 8000, |
| 75 | + ], |
| 76 | + ]; |
| 77 | + } |
| 78 | +} |
0 commit comments