企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
# C.77 PHPUnitTask This task runs testcases using the [PHPUnit](http://www.phpunit.de/) framework. It is a functional port of the Ant [JUnit](http://ant.apache.org/manual/OptionalTasks/junit.html) task. **NB:** if you want to use the PHPUnit .phar file, please make sure you download the library version (`phpunit-library.phar`) and you set the `pharlocation` attribute! Table C.104:聽Attributes NameTypeDescriptionDefaultRequired`printsummary``Boolean`Print one-line statistics for each testcase.`false`No`bootstrap``String`The name of a bootstrap file that is run before executing the tests.noneNo`codecoverage``Boolean`Gather code coverage information while running tests (requires Xdebug).`false`No`haltonerror``Boolean`Stop the build process if an error occurs during the test run.`false`No`haltonfailure``Boolean`Stop the build process if a test fails (errors are considered failures as well).`false`No`haltonincomplete``Boolean`Stop the build process if any incomplete tests are encountered.`false`No`haltonskipped``Boolean`Stop the build process if any skipped tests are encountered.`false`No`failureproperty``String`Name of property to set (to true) on failure.n/aNo`errorproperty``String`Name of property to set (to true) on error.n/aNo`incompleteproperty``String`Name of property to set (to true) on incomplete tests.n/aNo`skippedproperty``String`Name of property to set (to true) on skipped tests.n/aNo`usecustomerrorhandler``Boolean`Use a custom Phing/PHPUnit error handler to process PHP errors.`true`No`processisolation``Boolean`Enable process isolation when executing tests.`false`No`configuration``String`Path to a PHPUnit configuration file (such as `phpunit.xml`). Supported elements are: `bootstrap`, `processIsolation`, `stopOnFailure`, `stopOnError`, `stopOnIncomplete` and `stopOnSkipped`. Values provided **overwrite** other attributes!n/aNo`groups``String`Only run tests from the specified group(s).n/aNo`excludeGroups``String`Exclude tests from the specified group(s).n/aNo`pharlocation``String`Location of the PHPUnit PHAR package.n/aNo C.77.1 Supported Nested Tags - `formatter` The results of the tests can be printed in different formats. Output will always be sent to a file, unless you set the `usefile` attribute to `false`. The name of the file is predetermined by the formatter and can be changed by the `outfile` attribute. There are four predefined formatters - `xml`, `clover`, and `crap4j` print the test results in the JUnit, Clover, and Crap4J XML formats respectively. The `plain` formatter emits a short statistics line for all test cases. Custom formatters that implement phing.tasks.ext.phpunit.formatter.PHPUnitResultFormatter can be specified. Table C.105:聽Attributes NameTypeDescriptionDefaultRequired`type``String`Use a predefined formatter (either `xml`, `plain`, `clover`, `crap4j`, or `summary`).n/aOne of these is required.`classname``String`Name of a custom formatter class.n/a`usefile``Boolean`Boolean that determines whether output should be sent to a file.`true`No`todir``String`Directory to write the file to.n/aNo`outfile``String`Filename of the result.Depends on formatterNo - `batchtest` Define a number of tests based on pattern matching. `batchtest` collects the included files from any number of nested <fileset>s. It then generates a lists of classes that are (in)directly defined by each PHP file. Table C.106:聽Attributes NameTypeDescriptionDefaultRequired`exclude``String`A list of classes to exclude from the pattern matching. For example, when you have two baseclasses `BaseWebTest` and `BaseMathTest`, which are included a number of testcases (and thus added to the list of testclasses), you can exclude those classes from the list by typing ``` exclude="BaseWebTest BaseMathTest" ``` .n/aNo`classpath``String`Used to define more paths on which - besides the PHP include\_path - to look for the test files.n/aNo`name``String`The name that is used to create a testsuite from this batchtest.Phing BatchtestNo C.77.2 Example ``` <phpunit> <formatter todir="reports" type="xml"/> <batchtest> <fileset dir="tests"> <include name="**/*Test*.php"/> <exclude name="**/Abstract*.php"/> </fileset> </batchtest> </phpunit> ``` Runs all matching testcases in the directory `tests`, writing XML results to the directory `reports`. ``` <phpunit codecoverage="true" haltonfailure="true" haltonerror="true"> <formatter type="plain" usefile="false"/> <batchtest> <fileset dir="tests"> <include name="**/*Test*.php"/> </fileset> </batchtest> </phpunit> ``` Runs all matching testcases in the directory `tests`, gathers code coverage information, writing plain text results to the console. The build process is aborted if a test fails. ``` <phpunit bootstrap="src/autoload.php"> <formatter type="plain" usefile="false"/> <batchtest> <fileset dir="tests"> <include name="**/*Test*.php"/> </fileset> </batchtest> </phpunit> ``` Runs all matching testcases in the directory `tests`, writing plain text results to the console. Additionally, before executing the tests, the bootstrap file `src/autoload.php` is loaded. **Important note:** using a mechanism such as an "AllTests.php" file to execute testcases will bypass the Phing hooks used for reporting and counting, and could possibly lead to strange results. Instead, use one of more fileset's to provide a list of testcases to execute. C.77.3 Supported Nested Tags - `fileset`