Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PhpUnit: added test, ref #4518 #4524

Merged
merged 3 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .phpunit.dist.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
<testsuite name="Base">
<directory>tests/unit/Base</directory>
</testsuite>
<testsuite name="Error">
<directory>tests/unit/Error</directory>
</testsuite>
<testsuite name="Mage">
<directory>tests/unit/Mage</directory>
</testsuite>
Expand Down
2 changes: 2 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@
require_once __DIR__ . '/../vendor/autoload.php';

require_once __DIR__ . '/../app/Mage.php';
require_once __DIR__ . '/../errors/processor.php';

ini_set('error_reporting', -1);
78 changes: 78 additions & 0 deletions tests/unit/Error/ProcessorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

/**
* OpenMage
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available at https://opensource.org/license/osl-3-0-php
*
* @category OpenMage
* @package OpenMage_Tests
* @copyright Copyright (c) 2024 The OpenMage Contributors (https://www.openmage.org)
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

declare(strict_types=1);

namespace OpenMage\Tests\Unit\Error;

use Error_Processor as Subject;
use Generator;
use PHPUnit\Framework\TestCase;

class ProcessorTest extends TestCase
{
public Subject $subject;
public array $server;

public function setUp(): void
{
$this->subject = new Subject();
$this->server = $_SERVER;
}

public function tearDown(): void
{
$_SERVER = $this->server;
}

/**
* @dataProvider provideGetHostUrl
* @group Error
*/
public function testGetHostUrl(string $expectedResult, array $serverVars): void
{
foreach ($serverVars as $serverVar => $value) {
$_SERVER[$serverVar] = $value;
}
$this->assertSame($expectedResult, $this->subject->getHostUrl());
}

public function provideGetHostUrl(): Generator
{
yield 'default' => [
'http://localhost',
[],
];
yield 'port 80' => [
'http://localhost',
[
'SERVER_PORT' => 80,
],
];
yield 'port 8000' => [
'http://localhost:8000',
[
'SERVER_PORT' => 8000,
],
];
yield 'name with port + port 8000' => [
'http://localhost:8000',
[
'SERVER_NAME' => 'localhost:8000',
'SERVER_PORT' => 8000,
],
];
}
}
Loading