[PHPUnit]-01 使用

安装

composer require --dev phpunit/phpunit ^7

使用例子

  1. composer init -> composer.json

  2. 创建文件和命令
    touch phpunit.xml
    mkdir tests/Unit
    touch app/Email.php

    项目的编配信息: https://phpunit.readthedocs.io/zh_CN/latest/organizing-tests.html#xml

phpunit.xml
colors="true" 表示测试结果会高亮显示,./tests/Unit 则用于指定测试用例存放目录

<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php" colors = "true" verbase="true" stopOnFailute="false">

<testsuites>
    <testsuite name="Unit">
        <directory>./tests/Unit</directory>
    </testsuite>
</testsuites>
</phpunit>

  1. psr4 自动加载
"autoload": {
    "psr-4": {
        "App\\": "app/"
    }
},
  1. demo 见 https://phpunit.readthedocs.io/zh_CN/latest/index.html
posted @ 2019-06-24 20:11  aocn  阅读(68)  评论(0)    收藏  举报