Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions system/CodeIgniter.php
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,8 @@ protected function handleRequest(?RouteCollectionInterface $routes, Cache $cache

// If a ResponseInterface instance is returned then send it back to the client and stop
if ($possibleResponse instanceof ResponseInterface) {
$this->outputBufferingEnd();

return $possibleResponse;
}

Expand Down
6 changes: 5 additions & 1 deletion system/Test/FeatureTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ protected function withRoutes(?array $routes = null)
$collection->resetRoutes();

foreach ($routes as $route) {
$collection->{$route[0]}($route[1], $route[2]);
if (isset($route[3])) {
$collection->{$route[0]}($route[1], $route[2], $route[3]);
} else {
$collection->{$route[0]}($route[1], $route[2]);
}
}
}

Expand Down
6 changes: 5 additions & 1 deletion tests/_support/Config/Filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@

namespace Tests\Support\Config\Filters;

$filters->aliases['test-customfilter'] = \Tests\Support\Filters\Customfilter::class;
/**
* @psalm-suppress UndefinedGlobalVariable
*/
$filters->aliases['test-customfilter'] = \Tests\Support\Filters\Customfilter::class;
$filters->aliases['test-redirectfilter'] = \Tests\Support\Filters\RedirectFilter::class;
27 changes: 27 additions & 0 deletions tests/_support/Filters/RedirectFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

/**
* This file is part of CodeIgniter 4 framework.
*
* (c) CodeIgniter Foundation <[email protected]>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/

namespace Tests\Support\Filters;

use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;

class RedirectFilter implements \CodeIgniter\Filters\FilterInterface
{
public function before(RequestInterface $request, $arguments = null)
{
return redirect()->to('login');
}

public function after(RequestInterface $request, ResponseInterface $response, $arguments = null): void
{
}
}
15 changes: 15 additions & 0 deletions tests/system/Test/FeatureTestTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,21 @@ public function testCallGetAndUriString(): void
$this->assertSame('http://example.com/index.php/foo/bar/1/2/3', current_url());
}

public function testCallGetAndFilterReturnsResponse(): void
{
$this->withRoutes([
[
'get',
'admin',
static fn () => 'Admin Area',
['filter' => 'test-redirectfilter'],
],
]);
$response = $this->get('admin');

$response->assertRedirectTo('login');
}

public function testClosureWithEcho()
{
$this->withRoutes([
Expand Down