Skip to content
This repository was archived by the owner on Oct 11, 2024. It is now read-only.

Commit d7d66f7

Browse files
committed
test: add new tests
1 parent f679491 commit d7d66f7

1 file changed

Lines changed: 46 additions & 0 deletions

File tree

tests/core.test.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,49 @@
5858

5959
ob_end_clean();
6060
});
61+
62+
test('get route data + group', function () {
63+
$_SERVER['REQUEST_METHOD'] = 'GET';
64+
$_SERVER['REQUEST_URI'] = '/thatpath';
65+
66+
$lr = new Router;
67+
68+
$lr->group('/', function () use($lr) {
69+
$lr->get('/thatpath', ['name' => 'thatroutename', function () use ($lr) {
70+
echo json_encode($lr->getRoute());
71+
}]);
72+
});
73+
74+
ob_start();
75+
$lr->run();
76+
77+
$data = json_decode(ob_get_contents(), true);
78+
79+
expect($data['path'])->toBe('/thatpath');
80+
expect($data['name'])->toBe('thatroutename');
81+
expect($data['method'])->toBe('GET');
82+
83+
ob_end_clean();
84+
});
85+
86+
test('get route data + dynamic routes', function () {
87+
$_SERVER['REQUEST_METHOD'] = 'GET';
88+
$_SERVER['REQUEST_URI'] = '/myusers/2';
89+
90+
$lr = new Router;
91+
92+
$lr->get('/myusers/{id}', ['name' => 'myusersroutename', function () use($lr) {
93+
echo json_encode($lr->getRoute());
94+
}]);
95+
96+
ob_start();
97+
$lr->run();
98+
99+
$data = json_decode(ob_get_contents(), true);
100+
101+
expect($data['path'])->toBe('/myusers/2');
102+
expect($data['name'])->toBe('myusersroutename');
103+
expect($data['method'])->toBe('GET');
104+
105+
ob_end_clean();
106+
});

0 commit comments

Comments
 (0)