Linux command
phpunit 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Run all tests
phpunit
Run specific test file
phpunit [tests/ExampleTest.php]
Run tests in directory
phpunit [tests/]
Run specific test
phpunit --filter [testMethodName]
Generate coverage report
phpunit --coverage-html [coverage/]
Use configuration
phpunit -c [phpunit.xml]
说明
phpunit is the de facto unit and integration testing framework for PHP, based on the xUnit family. It discovers and runs test classes that extend `PHPUnit\Framework\TestCase`, providing rich assertions, data providers, test doubles, and code coverage reporting. Tests are typically organized under a `tests/` directory and configured via a `phpunit.xml` file at the project root, which defines test suites, bootstrap files, and coverage filters. Results can be output in TestDox, JUnit XML, and other formats for CI integration.
参数
- --filter _PATTERN_
- Filter tests.
- --coverage-html _DIR_
- HTML coverage report.
- -c _FILE_
- Configuration file.
- --testdox
- TestDox output.
- --help
- Display help.
FAQ
What is the phpunit command used for?
phpunit is the de facto unit and integration testing framework for PHP, based on the xUnit family. It discovers and runs test classes that extend `PHPUnit\Framework\TestCase`, providing rich assertions, data providers, test doubles, and code coverage reporting. Tests are typically organized under a `tests/` directory and configured via a `phpunit.xml` file at the project root, which defines test suites, bootstrap files, and coverage filters. Results can be output in TestDox, JUnit XML, and other formats for CI integration.
How do I run a basic phpunit example?
Run `phpunit` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does --filter _PATTERN_ do in phpunit?
Filter tests.