-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAttributeTest.php
63 lines (41 loc) · 1.8 KB
/
AttributeTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
declare(strict_types=1);
namespace Rammewerk\Router\Tests;
use PHPUnit\Framework\TestCase;
use Rammewerk\Router\Router;
use Rammewerk\Router\Error\InvalidRoute;
use Rammewerk\Router\Tests\Fixtures\Attributes\DashboardRoute;
use Rammewerk\Router\Tests\Fixtures\RouterTestClass;
class AttributeTest extends TestCase {
private Router $router;
protected function setUp(): void {
// Create a router with a basic dependency handler
$this->router = new Router(fn(string $class) => new $class());
// Register routes
$this->router->add('/dashboard', DashboardRoute::class);
$this->router->add('/test', RouterTestClass::class);
}
public function testStatsRouteWithParameters(): void {
// Dispatch and check response for /dashboard/stats/123/details
$response = $this->router->dispatch('/dashboard/stats/123/details/456');
$this->assertSame('123456', $response);
// Dispatch and check response for /dashboard/stats/123/details/extra
$response = $this->router->dispatch('/dashboard/stats/123/details/456/Extra');
$this->assertSame('123456Extra', $response);
}
public function testProfileRoute(): void {
// Dispatch and check response for /dashboard/profile
$response = $this->router->dispatch('/dashboard/profile');
$this->assertSame('Profile page', $response);
}
public function testInvalidRoute(): void {
// Attempt to dispatch an invalid route
$this->expectException(InvalidRoute::class);
$this->router->dispatch('/dashboard/unknown');
}
public function testMissingClassRouteAttribute(): void {
// Attempt to dispatch an invalid route
$this->expectException(InvalidRoute::class);
$this->router->dispatch('/test/invalid');
}
}