A Visual Studio Code extension for generating PHPUnit tests for CodeIgniter 4 applications. This extension helps you quickly create test files for your controllers and models, following best practices for unit testing in CodeIgniter 4.
Features
Test Generation
Generate tests for controllers
Automatic method detection and test generation
Support for CodeIgniter 4's namespace system
Integration with CodeIgniter 4's testing framework
Tests are generated in the tests/unit directory
Testing Framework Integration
One-click installation of PHPUnit
Database testing support
UI Features
Easy-to-use interface for test generation
Configuration settings for test directory and AI model
Installation
Install the extension from the VS Code marketplace
Open your CodeIgniter 4 project in VS Code
Install PHPUnit using the command palette (Ctrl+Shift+P):
Select "Install PHPUnit"
Wait for the installation to complete
Usage
Generating Tests
Open the command palette (Ctrl+Shift+P)
Choose one of the following options:
"Generate Test" - Generate a test for the current file
"Generate Test with AI" - Generate a test using AI assistance
"Generate Test Suite" - Generate tests for multiple files
"Open Test Generator UI" - Open the interactive test generator
Running Tests
Open the command palette (Ctrl+Shift+P)
Select "Run Tests"
View the test results in the terminal
Configuration
Open the command palette (Ctrl+Shift+P)
Select "Configure Path Settings"
Adjust the following settings:
Test Directory: Where test files will be generated (default: tests/unit)
AI Model: Choose between different AI models for test generation
Test Templates
Controller Tests
namespace Tests\Unit\Controllers;
use CodeIgniter\Test\CIUnitTestCase;
use CodeIgniter\Test\DatabaseTestTrait;
use CodeIgniter\Test\FeatureTestTrait;
use App\Controllers\ExampleController;
class ExampleControllerTest extends CIUnitTestCase
{
use DatabaseTestTrait;
use FeatureTestTrait;
protected function setUp(): void
{
parent::setUp();
$this->resetServices();
}
protected function tearDown(): void
{
parent::tearDown();
}
public function test_index()
{
$result = $this->withSession([
'user_id' => 1,
'email' => 'test@example.com'
])->get('/example/index');
$this->assertTrue($result->isOK());
}
}
Requirements
Visual Studio Code 1.60.0 or higher
CodeIgniter 4.x
PHP 7.4 or higher
Composer (for dependency management)
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.