mirror of
https://github.com/flarum/framework.git
synced 2025-03-10 20:31:24 +08:00
Start testing Route extender
This commit is contained in:
parent
b2c3392a83
commit
12ff8dbcc3
58
framework/core/tests/integration/extenders/RoutesTest.php
Normal file
58
framework/core/tests/integration/extenders/RoutesTest.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* For detailed copyright and license information, please view the
|
||||
* LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Tests\integration\extenders;
|
||||
|
||||
use Flarum\Extend;
|
||||
use Flarum\Tests\integration\TestCase;
|
||||
use Laminas\Diactoros\Response\TextResponse;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Server\RequestHandlerInterface;
|
||||
|
||||
class RoutesTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function custom_route_does_not_exist_by_default()
|
||||
{
|
||||
$response = $this->send(
|
||||
$this->request('GET', '/custom')
|
||||
);
|
||||
|
||||
$this->assertEquals(404, $response->getStatusCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function custom_route_can_be_added_by_extender()
|
||||
{
|
||||
$this->extend(
|
||||
(new Extend\Routes('forum'))
|
||||
->get('/custom', 'custom', CustomRoute::class)
|
||||
);
|
||||
|
||||
$response = $this->send(
|
||||
$this->request('GET', '/custom')
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
$this->assertEquals('Hello Flarumites!', $response->getBody());
|
||||
}
|
||||
}
|
||||
|
||||
class CustomRoute implements RequestHandlerInterface
|
||||
{
|
||||
public function handle(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
return new TextResponse('Hello Flarumites!');
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user