For example, I have a controller function Home::index that redirect to route "product-index":
<?php namespace App\Controllers;
class Home extends BaseController
{
public function index()
{
return redirect()->route('product-index');
}
}
On Test part, I create test with:
<?php namespace AppTest\Controller;
use App\Controllers\Home;
use CodeIgniter\Test\CIDatabaseTestCase;
use CodeIgniter\Test\ControllerTester;
class HomeTest extends CIDatabaseTestCase
{
use ControllerTester;
public function testIndexRedirectToProduct()
{
$result = $this->controller(Home::class)
->execute('index');
$this->assertTrue($result->isRedirect());
}
}
and it got error:
vendor/bin/phpunit tests/Controller/HomeTest.php
PHPUnit 8.5.2 by Sebastian Bergmann and contributors.
E 1 / 1 (100%)
Time: 284 ms, Memory: 12.00 MB
There was 1 error:
1) AppTest\Controller\HomeTest::testIndexRedirectToProduct
CodeIgniter\HTTP\Exceptions\HTTPException:
/Users/samsonasik/www/ci4/vendor/codeigniter4/framework/system/HTTP/Exceptions/HTTPException.php:168
/Users/samsonasik/www/ci4/vendor/codeigniter4/framework/system/HTTP/Response.php:314
/Users/samsonasik/www/ci4/vendor/codeigniter4/framework/system/Test/ControllerTester.php:191
/Users/samsonasik/www/ci4/tests/Controller/HomeTest.php:14
If I change the code with redirect()->to(base_url('product')).
<?php namespace App\Controllers;
class Home extends BaseController
{
public function index()
{
return redirect()->to(base_url('product'));
}
}
It working:
vendor/bin/phpunit tests/Controller/HomeTest.php
PHPUnit 8.5.2 by Sebastian Bergmann and contributors.
. 1 / 1 (100%)
Time: 258 ms, Memory: 12.00 MB
OK (1 test, 1 assertion)
CodeIgniter 4 version
4.0.2
Expected behavior, and steps to reproduce if appropriate
Working with redirect()->route()
Describe the bug
For example, I have a controller function
Home::index
that redirect to route "product-index":On Test part, I create test with:
and it got error:
If I change the code with
redirect()->to(base_url('product'))
.It working:
CodeIgniter 4 version 4.0.2
Expected behavior, and steps to reproduce if appropriate Working with
redirect()->route()
Context