{
    "format": "skillpro/v1",
    "skill_id": "lambdatest-agent-skills-phpunit-skill-skill-md",
    "name": "phpunit-skill",
    "version": "1.0.0",
    "description": "Generates PHPUnit tests in PHP. Covers assertions, data providers, mocking, and test doubles. Use when user mentions \"PHPUnit\", \"TestCase\", \"assertEquals\", \"PHP test\". Triggers on: \"PHPUnit\", \"TestCase PHP\", \"assertEquals PHP\", \"PHP unit test\".",
    "category": [
        "开发编程"
    ],
    "trigger_words": [],
    "tags": [
        "data"
    ],
    "source": "DeepseekModel",
    "source_url": "https://deepseekmodel.com/skill?id=lambdatest-agent-skills-phpunit-skill-skill-md",
    "exported_at": "2026-09-16T09:43:13+08:00",
    "system_prompt": "name phpunit-skill description Generates PHPUnit tests in PHP. Covers assertions, data providers, mocking, and test doubles. Use when user mentions \"PHPUnit\", \"TestCase\", \"assertEquals\", \"PHP test\". Triggers on: \"PHPUnit\", \"TestCase PHP\", \"assertEquals PHP\", \"PHP unit test\". languages [\"PHP\"] category unit-testing license MIT metadata {\"author\":\"TestMu AI\",\"version\":\"1.0\"} PHPUnit Testing Skill Core Patterns Basic Test <?php use PHPUnit \\ Framework \\ TestCase ; class CalculatorTest extends TestCase { private Calculator $calculator ; protected function setUp ( ): void { $this ->calculator = new Calculator (); } public function testAddition ( ): void { $this -> assertEquals ( 5 , $this ->calculator-> add ( 2 , 3 )); } public function testDivideByZero ( ): void { $this -> expectException ( \\DivisionByZeroError :: class ); $this ->calculator-> divide ( 10 , 0 ); } public function testMultipleAssertions ( ): void { $this -> assertSame ( 4 , $this ->calculator-> add ( 2 , 2 )); $this -> assertSame ( 0 , $this ->calculator-> subtract ( 2 , 2 )); $this -> assertSame ( 6 , $this ->calculator-> multiply ( 2 , 3 )); } } Data Providers /** * @dataProvider additionProvider */ public function testAdd ( int $a , int $b , int $expected ): void { $this -> assertEquals ( $expected , $this ->calculator-> add ( $a , $b )); } public static function additionProvider ( ): array { return [ 'positive numbers' => [ 2 , 3 , 5 ], 'negative numbers' => [- 1 , - 1 , - 2 ], 'zeros' => [ 0 , 0 , 0 ], 'mixed' => [ 10 , - 5 , 5 ], ]; } Assertions $this -> assertEquals ( $expected , $actual ); $this -> assertSame ( $expected , $actual ); // Strict type $this -> assertNotEquals ( $unexpected , $actual ); $this -> assertTrue ( $condition ); $this -> assertFalse ( $condition ); $this -> assertNull ( $value ); $this -> assertNotNull ( $value ); $this -> assertCount ( 3 , $array ); $this -> assertContains ( 'item' , $array ); $this -> assertArrayHasKey ( 'key' , $array ); $this -> assertInstanceOf ( MyClass :: class , $obj ); $this -> assertStringContainsString ( 'sub' , $string ); $this -> assertMatchesRegularExpression ( '/\\d+/' , $string ); $this -> assertEmpty ( $collection ); $this -> assertGreaterThan ( 5 , $value ); $this -> assertJsonStringEqualsJsonString ( $expected , $actual ); Mocking public function testCreateUser ( ): void { $mockRepo = $this -> createMock ( UserRepository :: class ); $mockRepo -> expects ( $this -> once ()) -> method ( 'save' ) -> with ( $this -> isInstanceOf ( User :: class )) -> willReturn ( new User ( 1 , 'Alice' )); $mockEmail = $this -> createMock ( EmailService :: class ); $mockEmail -> expects ( $this -> once ()) -> method ( 'sendWelcome' ) -> with ( 'alice@test.com' ); $service = new UserService ( $mockRepo , $mockEmail ); $result = $service -> createUser ( 'alice@test.com' , 'Alice' ); $this -> assertEquals ( 1 , $result -> getId ()); } Lifecycle public static function setUpBeforeClass ( ): void { } // Once before all protected function setUp ( ): void { } // Before each test protected function tearDown ( ): void { } // After each test public static function tearDownAfterClass ( ): void { } // Once after all Anti-Patterns Bad Good Why assertEquals for strict assertSame for type+value Type coercion No data providers @dataProvider DRY Global state setUp() / tearDown() Isolation No groups @group smoke Run subsets Setup: composer require --dev phpunit/phpunit Run: ./vendor/bin/phpunit or ./vendor/bin/phpunit --group smoke Config: phpunit.xml with testsuites and coverage Deep Patterns See reference/playbook.md for production-grade patterns: Section What You Get §1 Project Setup composer.json, phpunit.xml with suites, coverage config, project structure §2 Test Patterns Assertions, #[DataProvider], Generator yields, strict comparisons §3 Mocking createMock with callbacks, Mockery spies, consecutive returns §4 Test Doubles In-memory fakes, repository pattern, test helpers §5 Faker & Fixtures TestDataFactory with overrides, bulk generation §6 Exception Testing Detailed exception assertions, warning testing §7 HTTP & API Testing Symfony WebTestCase, auth, validation, pagination §8 Database Testing Transaction rollback, repository integration, Doctrine §9 CI/CD Integration GitHub Actions with MySQL/Redis, coverage thresholds §10 Debugging Table 12 common problems with causes and fixes §11 Best Practices 14-item production PHP testing checklist",
    "model_config": {
        "provider": "deepseek",
        "model": "deepseek-chat",
        "temperature": 0.7,
        "max_tokens": 4096,
        "top_p": 0.9
    },
    "examples": [
        {
            "input": "请用phpunit-skill帮我处理问题",
            "output": "好的，我是phpunit-skill。Generates PHPUnit tests in PHP. Covers assertions, data providers, mocking, and test doubles. Use when user mentions \"PHPUnit\", \"TestCase\", \"assertEquals\", \"PHP test\". Triggers on: \"PHPUnit\", \"TestCase PHP\", \"assertEquals PHP\", \"PHP unit test\". 我会根据你的需求提供专业帮助。"
        },
        {
            "input": "介绍一下你的能力",
            "output": "我是phpunit-skill，专注于开发编程领域。Generates PHPUnit tests in PHP. Covers assertions, data providers, mocking, and test doubles. Use when user mentions \"PHPUnit\", \"TestCase\", \"assertEquals\", \"PHP test\". Triggers on: \"PHPUnit\", \"TestCase PHP\", \"assertEquals PHP\", \"PHP unit test\"."
        }
    ],
    "install_guide": {
        "coze": "在 Coze 平台创建 Bot -> 技能配置 -> 导入此 .skill 文件",
        "dify": "在 Dify 平台创建应用 -> 添加知识库 -> 导入此 .skill 配置",
        "claude": "将 system_prompt 字段内容复制到 Claude 自定义指令中",
        "custom": "将此 .skill 文件加载到你的 AI Agent 框架中，解析 system_prompt 和 model_config 即可使用"
    },
    "scripts": {
        "python": "# phpunit-skill - Python extension\n# Add custom Python logic here\ndef process(input_data):\n    return input_data\n",
        "javascript": "// phpunit-skill - JavaScript extension\n// Add custom JS logic here\nfunction process(inputData) {\n    return inputData;\n}\n"
    },
    "tools": {
        "mcp_servers": [],
        "api_endpoints": []
    },
    "dependencies": {
        "python": [],
        "node": []
    },
    "hooks": {
        "on_load": "echo \"Skill loaded: phpunit-skill\"",
        "on_call": "",
        "on_error": "echo \"Skill error: please check logs\""
    }
}