PHP Testing

Establish unit and integration testing standards for PHP applications with Pest and PHPUnit.

51|6|Updated Mar 28, 2019
One-click install
npx skills add https://github.com/Mte90/dotfiles --skill php-testing
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: PHP Testing
Source: https://github.com/Mte90/dotfiles/tree/main/.config/opencode/skills/php/testing
Command: npx skills add https://github.com/Mte90/dotfiles --skill php-testing

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill provides a standardized approach to unit and integration testing for PHP applications, ensuring code reliability and maintainability.

Core Features & Use Cases

  • Testing Frameworks: Supports modern (Pest) and legacy (PHPUnit) testing frameworks.
  • TDD Workflow: Guides developers through the Red-Green-Refactor cycle for new feature development.
  • Isolation & Mocking: Emphasizes mocking dependencies for focused unit tests and using in-memory databases for integration tests.
  • Use Case: When developing a new authentication module, use this Skill to write unit tests for individual components and integration tests to verify database interactions, ensuring a secure and functional login process.

Quick Start

Write a new unit test for the UserService class using Pest, ensuring the create method correctly saves user data.

Frequently Asked Questions about PHP Testing

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I set up unit and integration testing for PHP applications?

Establish comprehensive PHP testing standards by using Pest or PHPUnit to write isolated unit tests and integration tests. Mock dependencies for focused unit testing and use in-memory databases to verify system boundaries and database interactions.

What is the best way to apply TDD principles when developing PHP features?

Apply TDD principles in PHP by following the Red-Green-Refactor cycle. Write failing tests first, implement the minimum code to pass them, and then refactor. This ensures code reliability and maintainability for new feature development.

Does Pest work with legacy PHPUnit testing workflows?

Yes, Pest works with legacy PHPUnit workflows. This testing approach supports both modern Pest and legacy PHPUnit frameworks, allowing you to maintain existing tests while establishing comprehensive testing standards for new PHP application development.

How do I mock dependencies for focused unit tests in PHP?

Mock dependencies in PHP to isolate and focus unit tests on specific business logic. Effective mocking strategies prevent over-mocking and avoid anti-patterns like testing private methods, ensuring isolated testing of system boundaries and individual components.

What PHP testing anti-patterns should I avoid when isolating business logic?

When isolating business logic, avoid testing private methods and over-mocking dependencies. These PHP testing anti-patterns reduce code reliability. Focus on testing public interfaces and using in-memory databases for integration tests instead of excessive mocking.