Skip to content

Commit

Permalink
test: add URIFactoryTest
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Feb 10, 2023
1 parent 49dbcd9 commit 516a76a
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions tests/system/HTTP/URIFactoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

/**
* This file is part of CodeIgniter 4 framework.
*
* (c) CodeIgniter Foundation <[email protected]>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/

namespace CodeIgniter\HTTP;

use CodeIgniter\Config\Factories;
use CodeIgniter\Test\CIUnitTestCase;
use Config\App;

/**
* @backupGlobals enabled
*
* @internal
*
* @group Others
*/
final class URIFactoryTest extends CIUnitTestCase
{
protected function setUp(): void
{
parent::setUp();

$_GET = $_SERVER = [];
}

protected function tearDown(): void
{
Factories::reset('config');
}

public function testCreateCurrentURI()
{
// http://localhost:8080/index.php/woot?code=good#pos
$_SERVER['REQUEST_URI'] = '/index.php/woot?code=good';
$_SERVER['SCRIPT_NAME'] = '/index.php';
$_SERVER['QUERY_STRING'] = 'code=good';
$_SERVER['HTTP_HOST'] = 'localhost:8080';
$_SERVER['PATH_INFO'] = '/woot';

$_GET['code'] = 'good';

$factory = new URIFactory($_SERVER, $_GET, new App());

$uri = $factory->createCurrentURI();

$this->assertInstanceOf(URI::class, $uri);
$this->assertSame('http://localhost:8080/woot?code=good', (string) $uri);
$this->assertSame('woot', $uri->getPath());
$this->assertSame('woot', $uri->getRoutePath());
}
}

0 comments on commit 516a76a

Please sign in to comment.