Creates PHP unit tests for Dolibarr ERP/CRM functions and methods. Use when the user asks to add, write, create, or complete a PHPUnit test for Dolibarr, or mentions testing a specific function, method, or class in the Dolibarr codebase.
Use this skill whenever the user asks to create, modify, or complete a PHP unit test for the Dolibarr ERP/CRM project.
The goal is to produce a unit test that follows Dolibarr conventions and integrates cleanly into the existing PHPUnit test suite.
The user request should contain, when available:
test/phpunit/ directoryLocate the most appropriate existing PHPUnit test file in test/phpunit/.
If no suitable test file exists, create one using the naming convention FeatureTest.php.
A test method should describe the expected behavior.
Examples:
public function testCreateObject()
public function testDeleteObject()
public function testFetchReturnsExpectedValues()
public function testInvalidInputThrowsException()Prefer specific assertions over generic ones.
Good examples:
$this->assertTrue($result);
$this->assertFalse($result);
$this->assertEquals($expected, $actual);
$this->assertCount(3, $array);
$this->assertNull($value);
$this->assertNotNull($value);When generating code:
Action:
test/phpunit/InvoiceTest.phpAction:
test/phpunit/| Issue | Validation | Solution |
|---|---|---|
| Test file does not exist | Check test/phpunit/ directory | Create new test file with proper naming |
| Class or method not found | Verify namespace and file location | Use proper use statements and class paths |
| Database dependencies | Review test for external DB calls | Mock database interactions or use test fixtures |
| Non-deterministic behavior | Check for random values or timestamps | Use fixed seeds or mock time |
| Missing PHPUnit | Check project dependencies | Ensure PHPUnit is installed via Composer |
Before generating code:
$conf, $db, $user mocks. Use DolibarrTestCase if availableentity IN ('.getDolEntity('tablename').') to SQL in tests if needed$user->hasRight(). Mock user permissions in testsDOL_DOCUMENT_ROOT constant for paths, not hardcoded values1791120
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.