配置虚拟环境
建立目录引射关系
#配置phpuit
<phpunit bootstrap="./bootstrap.php">
<testsuites printerClass="PHPUnit_TextUI_ResultPrinter">
<testsuite name="money">
<directory>./cases</directory>
</testsuite>
</testsuites>
</phpunit>
#配置bootstrap初始化php运行环境
<?php
use app\common\Prediction;
use app\common\repositories\store\village\BuildingHouseRepository;
use app\common\tool\DateTool;
use Carbon\Carbon;
use think\App;
use app\common\repositories\user\UserRepository;
require __DIR__ . '/../vendor/autoload.php';
// 应用初始化
$app = new App();
$app->initialize();
#写个测试demo验证
<?php
namespace cases;
use app\common\dao\user\UserDao;
use app\common\model\user\UserStore;
use app\common\repositories\user\UserRepository;
use think\facade\Log;
use PHPUnit\Framework\TestCase;
class UserServiceTest extends TestCase
{
public function testAbs()
{
$model = UserRepository::getInstance()->get(1);
$this->assertEquals(1, $model['uid']);
}
}