SKILL.md
Backend Testing PHPUnit
When to use this skill
- Writing tests
- TDD development
- CI/CD pipelines
- Code quality
Workflow
Instructions
Test Class
<?php
namespace Tests\Unit;
use CodeIgniter\Test\CIUnitTestCase;
class UserServiceTest extends CIUnitTestCase
{
protected $service;
protected function setUp(): void
{
parent::setUp();
$this->service = new UserService();
}
public function testCreateUserWithValidData()
{
$data = ['name' => 'John', 'email' => '[email protected]'];
$user = $this->service->createUser($data);
$this->assertInstanceOf(User::class, $user);
$this->assertEquals('John', $user->name);
}
public function testCreateUserThrowsExceptionWithInvalidEmail()
{
$this->expectException(ValidationException::class);
$this->service->createUser(['email' => 'invalid']);
}
}
Run Tests
vendor/bin/phpunit
Resources
- Test business logic
- Mock external dependencies
- Use descriptive test names