This is a (multiple allowed):
What you did
- Create new project with
composer create-project --prefer-dist cakephp/app
- Create a DB with table "mytable"
- Bake controller
bin/cake bake controller Mytable
- Throw an exception in controller
class MytableController extends AppController
{
public function index()
{
throw new \Exception();
- Check for the exception in the test created by
bake
class MytableControllerTest extends TestCase
{
public function testIndex(): void
{
$this->disableErrorHandlerMiddleware();
$this->expectException(\Exception::class);
$this->get('/mytable/index');
- Run test
vendor/bin/phpunit tests/TestCase/Controller/MytableControllerTest.php --filter testIndex
What happened
There was 1 failure:
1) App\Test\TestCase\Controller\MytableControllerTest::testIndex
Failed asserting that exception of type "Exception" is thrown.
What you expected to happen
The test should not fail but detect the thrown exception.
Using disableErrorHandlerMiddleware() a exception was testable in Cake 3, but this isn't the case in CakePHP 4 (at the moment)?
This is a (multiple allowed):
bug
enhancement
feature-discussion (RFC)
CakePHP Version: 4.0.3
Platform and Target: PHP 7.2, apache 2.4, MySQL 5.7,
What you did
composer create-project --prefer-dist cakephp/appbin/cake bake controller MytablebakeWhat happened
What you expected to happen
The test should not fail but detect the thrown exception.
Using
disableErrorHandlerMiddleware()a exception was testable in Cake 3, but this isn't the case in CakePHP 4 (at the moment)?