Skip to content

Commit

Permalink
test: add new tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mychidarko committed Jun 30, 2023
1 parent f679491 commit d7d66f7
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions tests/core.test.php
Expand Up @@ -58,3 +58,49 @@

ob_end_clean();
});

test('get route data + group', function () {
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = '/thatpath';

$lr = new Router;

$lr->group('/', function () use($lr) {
$lr->get('/thatpath', ['name' => 'thatroutename', function () use ($lr) {
echo json_encode($lr->getRoute());
}]);
});

ob_start();
$lr->run();

$data = json_decode(ob_get_contents(), true);

expect($data['path'])->toBe('/thatpath');
expect($data['name'])->toBe('thatroutename');
expect($data['method'])->toBe('GET');

ob_end_clean();
});

test('get route data + dynamic routes', function () {
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = '/myusers/2';

$lr = new Router;

$lr->get('/myusers/{id}', ['name' => 'myusersroutename', function () use($lr) {
echo json_encode($lr->getRoute());
}]);

ob_start();
$lr->run();

$data = json_decode(ob_get_contents(), true);

expect($data['path'])->toBe('/myusers/2');
expect($data['name'])->toBe('myusersroutename');
expect($data['method'])->toBe('GET');

ob_end_clean();
});

0 comments on commit d7d66f7

Please sign in to comment.