Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Remove deprecated RedirectException #9399

Merged
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
6 changes: 1 addition & 5 deletions system/CodeIgniter.php
Original file line number Diff line number Diff line change
@@ -29,7 +29,6 @@
use CodeIgniter\HTTP\ResponsableInterface;
use CodeIgniter\HTTP\ResponseInterface;
use CodeIgniter\HTTP\URI;
use CodeIgniter\Router\Exceptions\RedirectException as DeprecatedRedirectException;
use CodeIgniter\Router\RouteCollectionInterface;
use CodeIgniter\Router\Router;
use Config\App;
@@ -353,11 +352,8 @@ public function run(?RouteCollectionInterface $routes = null, bool $returnRespon
} else {
try {
$this->response = $this->handleRequest($routes, config(Cache::class), $returnResponse);
} catch (DeprecatedRedirectException|ResponsableInterface $e) {
} catch (ResponsableInterface $e) {
$this->outputBufferingEnd();
if ($e instanceof DeprecatedRedirectException) {
$e = new RedirectException($e->getMessage(), $e->getCode(), $e);
}

$this->response = $e->getResponse();
} catch (PageNotFoundException $e) {
32 changes: 0 additions & 32 deletions system/Router/Exceptions/RedirectException.php

This file was deleted.

24 changes: 0 additions & 24 deletions tests/system/CodeIgniterTest.php
Original file line number Diff line number Diff line change
@@ -19,7 +19,6 @@
use CodeIgniter\Exceptions\PageNotFoundException;
use CodeIgniter\HTTP\Method;
use CodeIgniter\HTTP\Response;
use CodeIgniter\Router\Exceptions\RedirectException;
use CodeIgniter\Router\RouteCollection;
use CodeIgniter\Test\CIUnitTestCase;
use CodeIgniter\Test\Filters\CITestStreamFilter;
@@ -600,29 +599,6 @@ public function testRunRedirectionWithPOSTAndHTTPCode301(): void
$this->assertSame(301, $response->getStatusCode());
}

/**
* test for deprecated \CodeIgniter\Router\Exceptions\RedirectException for backward compatibility
*/
public function testRedirectExceptionDeprecated(): void
{
$_SERVER['argv'] = ['index.php', '/'];
$_SERVER['argc'] = 2;

// Inject mock router.
$routes = service('routes');
$routes->get('/', static function (): never {
throw new RedirectException('redirect-exception', 503);
});

$router = service('router', $routes, service('incomingrequest'));
Services::injectMock('router', $router);

$response = $this->codeigniter->run($routes, true);

$this->assertSame(503, $response->getStatusCode());
$this->assertSame('http://example.com/redirect-exception', $response->getHeaderLine('Location'));
}

public function testStoresPreviousURL(): void
{
$_SERVER['argv'] = ['index.php', '/'];
1 change: 1 addition & 0 deletions user_guide_src/source/changelogs/v4.6.0.rst
Original file line number Diff line number Diff line change
@@ -198,6 +198,7 @@ Removed Deprecated Items
- **Logger:** The deprecated ``CodeIgniter\Log\Logger::cleanFilenames()`` and
``CodeIgniter\Test\TestLogger::cleanup()`` have been removed. Use the
``clean_path()`` function instead.
**Router:** The deprecated ``CodeIgniter\Router\Exceptions\RedirectException`` has been removed. Use ``CodeIgniter\HTTP\Exceptions\RedirectException`` instead.

************
Enhancements
2 changes: 1 addition & 1 deletion user_guide_src/source/general/errors.rst
Original file line number Diff line number Diff line change
@@ -209,7 +209,7 @@ RedirectException

.. note:: Since v4.4.0, the namespace of ``RedirectException`` has been changed.
Previously it was ``CodeIgniter\Router\Exceptions\RedirectException``. The
previous class is deprecated.
previous class has been removed in v4.6.0.

This exception is a special case allowing for overriding of all other response routing and
forcing a redirect to a specific URI:
Original file line number Diff line number Diff line change
@@ -164,12 +164,12 @@ parameters:

-
message: '#^Assigning 2 directly on offset ''argc'' of \$_SERVER is discouraged\.$#'
count: 27
count: 26
path: ../../tests/system/CodeIgniterTest.php

-
message: '#^Assigning array\{''index\.php'', ''/''\} directly on offset ''argv'' of \$_SERVER is discouraged\.$#'
count: 12
count: 11
path: ../../tests/system/CodeIgniterTest.php

-
7 changes: 1 addition & 6 deletions utils/phpstan-baseline/property.phpDocType.neon
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# total 48 errors
# total 47 errors

parameters:
ignoreErrors:
@@ -172,11 +172,6 @@ parameters:
count: 1
path: ../../system/Images/Handlers/ImageMagickHandler.php

-
message: '#^PHPDoc type int of property CodeIgniter\\Router\\Exceptions\\RedirectException\:\:\$code is not the same as PHPDoc type mixed of overridden property Exception\:\:\$code\.$#'
count: 1
path: ../../system/Router/Exceptions/RedirectException.php

-
message: '#^PHPDoc type string of property CodeIgniter\\Session\\Handlers\\FileHandler\:\:\$savePath is not the same as PHPDoc type array\|string of overridden property CodeIgniter\\Session\\Handlers\\BaseHandler\:\:\$savePath\.$#'
count: 1

Unchanged files with check annotations Beta

$this->assertSame(200, $this->handler->getHeight());
}
public function testImageCreation(): void

Check warning on line 356 in tests/system/Images/ImageMagickHandlerTest.php

GitHub Actions / Others (8.2) / Sanity Tests

Took 0.9476s from 0.5000s limit to run CodeIgniter\\Images\\ImageMagickHandlerTest::testImageCreation
{
foreach (['gif', 'jpeg', 'png', 'webp'] as $type) {
if ($type === 'webp' && ! in_array('WEBP', Imagick::queryFormats(), true)) {
$this->assertSame(exif_imagetype($this->root . 'ci-logo.png'), IMAGETYPE_PNG);
}
public function testImageReorientLandscape(): void

Check warning on line 453 in tests/system/Images/ImageMagickHandlerTest.php

GitHub Actions / Others (8.2) / Sanity Tests

Took 0.5595s from 0.5000s limit to run CodeIgniter\\Images\\ImageMagickHandlerTest::testImageReorientLandscape
{
for ($i = 0; $i <= 8; $i++) {
$source = $this->origin . 'EXIFsamples/landscape_' . $i . '.jpg';
}
}
public function testImageReorientPortrait(): void

Check warning on line 472 in tests/system/Images/ImageMagickHandlerTest.php

GitHub Actions / Others (8.2) / Sanity Tests

Took 0.5336s from 0.5000s limit to run CodeIgniter\\Images\\ImageMagickHandlerTest::testImageReorientPortrait
{
for ($i = 0; $i <= 8; $i++) {
$source = $this->origin . 'EXIFsamples/portrait_' . $i . '.jpg';
$this->assertSame(0, Fabricator::getCount('giants'));
}
public function testUniqueSetsOutUniqueFieldValues(): void

Check warning on line 496 in tests/system/Test/FabricatorTest.php

GitHub Actions / Others (8.2) / Sanity Tests

Took 0.5139s from 0.5000s limit to run CodeIgniter\\Test\\FabricatorTest::testUniqueSetsOutUniqueFieldValues
{
$model = new class () extends Model {
protected $allowedFields = ['email'];
$this->forge->dropTable('', true);
}
public function testForeignKey(): void

Check warning on line 494 in tests/system/Database/Live/ForgeTest.php

GitHub Actions / DatabaseLive (8.2, OCI8, 8.0) / tests

Took 2.8014s from 0.5000s limit to run CodeIgniter\\Database\\Live\\ForgeTest::testForeignKey
{
$this->forge->dropTable('forge_test_invoices', true);
$this->forge->dropTable('forge_test_users', true);
$this->forge->dropTable('forge_test_1', true);
}
public function testSetKeyNames(): void

Check warning on line 1236 in tests/system/Database/Live/ForgeTest.php

GitHub Actions / DatabaseLive (8.2, OCI8, 8.0) / tests

Took 1.0299s from 0.5000s limit to run CodeIgniter\\Database\\Live\\ForgeTest::testSetKeyNames
{
$this->forge->dropTable('forge_test_1', true);
$this->forge->dropTable('forge_test_four', true);
}
public function testDropKey(): void

Check warning on line 1583 in tests/system/Database/Live/ForgeTest.php

GitHub Actions / DatabaseLive (8.2, OCI8, 8.0) / tests

Took 0.8182s from 0.5000s limit to run CodeIgniter\\Database\\Live\\ForgeTest::testDropKey
{
$this->forge->dropTable('key_test_users', true);
$keyName = 'key_test_users_id';
$this->forge->dropTable('forge_test_users', true);
}
public function testProcessIndexes(): void

Check warning on line 1676 in tests/system/Database/Live/ForgeTest.php

GitHub Actions / DatabaseLive (8.2, OCI8, 8.0) / tests

Took 1.4329s from 0.5000s limit to run CodeIgniter\\Database\\Live\\ForgeTest::testProcessIndexes
{
// make sure tables don't exist
$this->forge->dropTable('actions', true);
$this->assertSame('MySQLi', $this->getPrivateProperty($db1, 'DBDriver'));
}
public function testConnectWithFailover(): void

Check warning on line 97 in tests/system/Database/Live/ConnectTest.php

GitHub Actions / DatabaseLive (8.2, OCI8, 8.0) / tests

Took 1.0939s from 0.5000s limit to run CodeIgniter\\Database\\Live\\ConnectTest::testConnectWithFailover
{
$this->tests['failover'][] = $this->tests;
unset($this->tests['failover'][0]['failover']);
$this->createModel(EventModel::class);
}
public function testInsertEvent(): void

Check warning on line 37 in tests/system/Models/EventsModelTest.php

GitHub Actions / DatabaseLive (8.2, OCI8, 8.0) / tests

Took 0.8340s from 0.5000s limit to run CodeIgniter\\Models\\EventsModelTest::testInsertEvent
{
$data = [
'name' => 'Foo',
#[Group('DatabaseLive')]
final class WhenWhenNotModelTest extends LiveModelTestCase
{
public function testWhenWithTrueCondition(): void

Check warning on line 25 in tests/system/Models/WhenWhenNotModelTest.php

GitHub Actions / DatabaseLive (8.2, OCI8, 8.0) / tests

Took 0.8283s from 0.5000s limit to run CodeIgniter\\Models\\WhenWhenNotModelTest::testWhenWithTrueCondition
{
$secondaryData = [
[
$this->seeInDatabase('job', ['name' => 'Grocery Sales']);
}
public function testInsertBatch(): void

Check warning on line 53 in tests/system/Database/Live/InsertTest.php

GitHub Actions / DatabaseLive (8.2, OCI8, 8.0) / tests

Took 0.8281s from 0.5000s limit to run CodeIgniter\\Database\\Live\\InsertTest::testInsertBatch
{
$table = 'type_test';
CLI::init();
}
public function testMigrateAllWithWithTwoNamespaces(): void

Check warning on line 77 in tests/system/Commands/Database/MigrateStatusTest.php

GitHub Actions / DatabaseLive (8.2, OCI8, 8.0) / tests

Took 0.7709s from 0.5000s limit to run CodeIgniter\\Commands\\Database\\MigrateStatusTest::testMigrateAllWithWithTwoNamespaces
{
command('migrate --all');
$this->resetStreamFilterBuffer();
$this->createModel(UserModel::class)->insert([]);
}
public function testInsertPermitInsertNoData(): void

Check warning on line 239 in tests/system/Models/InsertModelTest.php

GitHub Actions / DatabaseLive (8.2, OCI8, 8.0) / tests

Took 0.7226s from 0.5000s limit to run CodeIgniter\\Models\\InsertModelTest::testInsertPermitInsertNoData
{
$forge = Database::forge();
$forge->addField([
$this->assertStringContainsString('Filename', $this->getBuffer());
}
public function testSeed(): void

Check warning on line 103 in tests/system/Commands/DatabaseCommandsTest.php

GitHub Actions / DatabaseLive (8.2, MySQLi, 8.0) / tests

Took 0.5524s from 0.5000s limit to run CodeIgniter\\Commands\\DatabaseCommandsTest::testSeed
{
command('migrate --all');
$this->clearBuffer();
return $this->getStreamFilterBuffer();
}
public function testCreateDatabase(): void

Check warning on line 72 in tests/system/Commands/CreateDatabaseTest.php

GitHub Actions / DatabaseLive (8.2, SQLSRV, 8.0) / tests

Took 0.5026s from 0.5000s limit to run CodeIgniter\\Commands\\CreateDatabaseTest::testCreateDatabase
{
if ($this->connection instanceof OCI8Connection) {
$this->markTestSkipped('Needs to run on non-OCI8 drivers.');