安装PHPUnit

安装PHPUnit

官网地址

虽然官网给了介绍,但是我还是根据自己的配置来讲一下。

环境配置

  • 首先使用brew安装phpunit

brew install phpunit

  • 使用composer安装phpunit

composer require phpunit/phpunit

测试

先随便写一个类:

class UserStore{
    public function sayHello(){
        print "hello world\r\n";
    }
}

再来写对应的测试类:

// 调用composer 中的 phpunit 
require_once __DIR__."/../../vendor/autoload.php";
// 路径根据你自己的需要来设置
require_once __DIR__."/../UserStore.php";

use PHPUnit\Framework\TestCase;

/**
 * Class UserStoreTest
 */
class UserStoreTest extends TestCase{
    /**
     * @test
     */
    public function testSayHello(){
        $userStore=new UserStore();
        $userStore->sayHello();
    }
}

$userStoreTest=new UserStoreTest();

最后来运行这个类,这里我的文件名是UserStoreTest.php

phpunit UserStoreTest.php

输出结果为这样:
在这里插入图片描述

出现这样的内容,你的环境基本上就配置好了。

发布了184 篇原创文章 · 获赞 72 · 访问量 40万+

猜你喜欢

转载自blog.csdn.net/YQXLLWY/article/details/89278574