🔥 CodeIgniter Intermediate

What is CodeIgniter 4's testing support?

Answer

CodeIgniter 4 has a solid built-in testing infrastructure built on PHPUnit. The CIUnitTestCase base class provides CI-specific helpers. Feature tests simulate HTTP requests without starting a real server: $result = $this->call("get", "/users") — test the response: $result->assertStatus(200)->assertSee("Alice")->assertHeaderEmitted("Content-Type", "application/json"). Database tests: use the DatabaseTestTrait with $seed = "UserSeeder" to populate data. Check database state: $this->seeInDatabase("users", ["email" => "alice@example.com"]). Session tests: $result->assertSessionHas("user_id"). Mock services: Services::injectMock("email", $mockEmail). Run tests: vendor/bin/phpunit or php spark test. Test files go in tests/.