Agent SkillsDolibarr/dolibarr › skill-doli-test-phpunit

skill-doli-test-phpunit

GitHub

为Dolibarr ERP/CRM项目生成或修改PHP PHPUnit单元测试。支持创建新测试或完善现有代码,遵循项目规范,确保测试独立、确定且无外部依赖。

.agents/skills/skill-doli-test-phpunit/SKILL.md Dolibarr/dolibarr

Trigger Scenarios

用户要求为特定函数、方法或类编写单元测试 需要添加、创建或补全PHPUnit测试用例

Install

npx skills add Dolibarr/dolibarr --skill skill-doli-test-phpunit -g -y
More Options

Non-standard path

npx skills add https://github.com/Dolibarr/dolibarr/tree/develop/.agents/skills/skill-doli-test-phpunit -g -y

Use without installing

npx skills use Dolibarr/dolibarr@skill-doli-test-phpunit

指定 Agent (Claude Code)

npx skills add Dolibarr/dolibarr --skill skill-doli-test-phpunit -a claude-code -g -y

安装 repo 全部 skill

npx skills add Dolibarr/dolibarr --all -g -y

预览 repo 内 skill

npx skills add Dolibarr/dolibarr --list

SKILL.md

Frontmatter
{
    "name": "skill-doli-test-phpunit",
    "license": "MIT",
    "description": "Creates or modify 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.",
    "allowed-tools": [
        "read_file",
        "write_file",
        "grep"
    ],
    "user-invocable": true
}

Skill: Add or modify a PHP Unit Test for Dolibarr

When to Use This Skill

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.

Inputs

The user request should contain, when available:

  • a name of the function to test
  • or the class method name to test

General Rules

  • follow the coding style already used in files in the test/phpunit/ directory
  • modify the minimum amount of existing code
  • prefer adding new test methods instead of modifying existing ones
  • tests must be deterministic and independent
  • avoid dependencies on external services
  • clean up every object created during the test

Test Location

Locate the most appropriate existing PHPUnit test file in test/phpunit/.

If no suitable test file exists, create one using the naming convention FeatureTest.php.

Naming

A test method should describe the expected behavior.

Examples:

public function testCreateObject()
public function testDeleteObject()
public function testFetchReturnsExpectedValues()
public function testInvalidInputThrowsException()

Assertions

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);

Output

When generating code:

  • provide only the relevant PHP code
  • preserve the existing file formatting
  • do not rewrite unrelated methods
  • explain briefly what is being tested

Examples

Input: "Add a unit test for the create() method of the Invoice class"

Action:

  1. locate or create test/phpunit/MyObjectTest.php
  2. add test method following Dolibarr conventions

Input: "Write tests for the calculateVAT() function in price.lib.php"

Action:

  1. locate or create appropriate test file in test/phpunit/
  2. add test methods for various VAT calculation scenarios
  3. you can test or suggest to test it by running the command: phpunit test/phpunit/TheTestFile.php

Error Handling

Common Failures and Validation

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:

  • verify the target function or method exists and is accessible
  • confirm the test directory structure matches Dolibarr conventions
  • ensure no external service dependencies exist in the code under test

Gotchas

  • Dolibarr global variables: Tests may need $conf, $db, $user mocks. Use DolibarrTestCase if available
  • Entity filtering: Add entity IN ('.getDolEntity('tablename').') to SQL in tests if needed
  • Permissions: Some methods check $user->hasRight(). Mock user permissions in tests
  • File paths: Use DOL_DOCUMENT_ROOT constant for paths, not hardcoded values
  • Legacy code: Older modules may not have test files. Create new ones following current conventions

Version History

  • fe37cd8 Current 2026-08-27 18:03

Same Skill Collection

.agents/skills/add-unit-test/SKILL.md
.agents/skills/code-review/SKILL.md
.agents/skills/dolibarr-dev/SKILL.md
.agents/skills/dolibarr-interactive-test/SKILL.md
.agents/skills/skill-doli-code-review/SKILL.md
.agents/skills/skill-doli-dev/SKILL.md
.agents/skills/skill-doli-devmodule/SKILL.md
.agents/skills/skill-doli-test-interactive/SKILL.md

Metadata

Files
0
Version
a07b7c9
Hash
b7544fa9
Indexed
2026-08-27 18:03

Accueil - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-08-28 17:44
浙ICP备14020137号-1 $Carte des visiteurs$