
- yhuxAvNbtxUM
0000-00-00 00:00:00
- 回帖
<?phpnamespaceapp\tests;usePHPUnit\Framework\TestCase;useGuzzleHttp\Client;classUserTestextendsTestCase{private$client;publicfunctionsetUp(){$this->client=new\GuzzleHttp\Client(['base_uri'=>'http://z.slim.com','http_errors'=>false,]);}publicfunctiontestUser(){$response=$this->client->get('/user/vilay');$this->assertEquals(200,$response->getStatusCode());$body=$response->getBody();$data=json_decode($body,true);$this->assertArrayHasKey('code',$data);$this->assertArrayHasKey('msg',$data);$this->assertArrayHasKey('data',$data);$this->assertEquals(0,$data['code']);}}写完测试代码之后,执行phpvendor/bin/phpunitapp/tests/UserTest.php没有执行到测试,直接把phpunit脚本输出了dir=$(d=${0%[/\\]*};cd"$d";cd"../phpunit/phpunit"&&pwd)#SeeifwearerunninginCygwinbycheckingforcygpathprogramifcommand-v'cygpath'>/dev/null2>&1;then#Cygwinpathsstartwith/cygdrive/whichwillbreakwindowsPHP,#soweneedtotranslatethedirpathtowindowsformat.However#wecouldbeusingcygwinPHPwhichdoesnotrequirethis,sowe#testifthepathtoPHPstartswith/cygdrive/ratherthan/usr/binif[[$(whichphp)==/cygdrive/*]];thendir=$(cygpath-m"$dir");fifidir=$(echo$dir|sed's//\/g')"${dir}/phpunit""$@"另外,我把单元测试配置到系统环境变量里面,执行测试phpunitapp/tests/UserTest.php需要在代码头部引入autoload.phprequire_once'vendor/autoload.php';没法自动加载的吗