Skip to content

Commit c0b3226

Browse files
author
Sven Reichel
authored
PhpUnit: added test, ref #4518 (#4524)
* Added test * reset
1 parent ddec006 commit c0b3226

File tree

3 files changed

+83
-0
lines changed

3 files changed

+83
-0
lines changed

.phpunit.dist.xml

+3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
<testsuite name="Base">
2626
<directory>tests/unit/Base</directory>
2727
</testsuite>
28+
<testsuite name="Error">
29+
<directory>tests/unit/Error</directory>
30+
</testsuite>
2831
<testsuite name="Mage">
2932
<directory>tests/unit/Mage</directory>
3033
</testsuite>

tests/bootstrap.php

+2
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@
44
require_once __DIR__ . '/../vendor/autoload.php';
55

66
require_once __DIR__ . '/../app/Mage.php';
7+
require_once __DIR__ . '/../errors/processor.php';
8+
79
ini_set('error_reporting', -1);

tests/unit/Error/ProcessorTest.php

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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

Comments
 (0)