Test Failed
Pull Request — main (#6)
by Chema
05:22 queued 03:08
created

RoutingRedirectTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
nc 1
nop 0
dl 0
loc 2
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace GacelaTest\Unit\Router;
6
7
use Gacela\Router\Routing;
8
use Gacela\Router\RoutingConfigurator;
9
use GacelaTest\Unit\Router\Fixtures\HeadersTearDown;
10
use PHPUnit\Framework\TestCase;
11
12
include_once __DIR__ . '/Fake/header.php';
13
14
class RoutingRedirectTest extends TestCase
15
{
16
    use HeadersTearDown;
17
18
    /**
19
     * @runInSeparateProcess
20
     */
21
    protected function setUp(): void
22
    {
23
    }
24
25
    /**
26
     * @dataProvider provideSimpleRedirect
27
     */
28
    public function test_default_redirect(string $destination): void
29
    {
30
        global $testHeaders;
31
32
        $_SERVER['REQUEST_URI'] = 'https://example.org/optional/uri';
33
        $_SERVER['REQUEST_METHOD'] = 'GET';
34
35
        Routing::configure(static function (RoutingConfigurator $routes) use ($destination): void {
36
            $routes->redirect('optional/uri', $destination);
37
        });
38
39
        self::assertSame([
40
            [
41
                'header' => 'Location: ' . $destination,
42
                'replace' => true,
43
                'response_code' => 302,
44
            ],
45
        ], $testHeaders);
46
    }
47
48
    /**
49
     * @dataProvider provideSimpleRedirect
50
     */
51
    public function test_simple_redirect(string $destination, int $statusCode): void
52
    {
53
        global $testHeaders;
54
55
        $_SERVER['REQUEST_URI'] = 'https://example.org/optional/uri';
56
        $_SERVER['REQUEST_METHOD'] = 'GET';
57
58
        Routing::configure(static function (RoutingConfigurator $routes) use ($destination, $statusCode): void {
59
            $routes->redirect('optional/uri', $destination, $statusCode);
60
        });
61
62
        self::assertSame([
63
            [
64
                'header' => 'Location: ' . $destination,
65
                'replace' => true,
66
                'response_code' => $statusCode,
67
            ],
68
        ], $testHeaders);
69
    }
70
71
    public function provideSimpleRedirect(): iterable
72
    {
73
        yield ['https://gacela-project.com/', 301];
74
        yield ['https://chemaclass.com/', 308];
75
        yield ['https://katarn.es/', 302];
76
        yield ['https://jesusvalera.github.io/', 303];
77
        yield ['https://github.com/ImanolRP', 307];
78
    }
79
}
80