phpunit单元测试问题
代言
代言 2017-06-26 10:49:13
[PHP讨论组]
client = new \GuzzleHttp\Client( [
            'base_uri' => 'http://z.slim.com',
            'http_errors' => false, 
        ]);
    }


    public function testUser()
    {
        $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']);
    }
}

写完测试代码之后,执行


php vendor/bin/phpunit app/tests/UserTest.php

没有执行到测试,直接把phpunit脚本输出了


dir=$(d=${0%[/\\]*}; cd "$d"; cd "../phpunit/phpunit" && pwd)

# See if we are running in Cygwin by checking for cygpath program
if command -v 'cygpath' >/dev/null 2>&1; then
    # Cygwin paths start with /cygdrive/ which will break windows PHP,
    # so we need to translate the dir path to windows format. However
    # we could be using cygwin PHP which does not require this, so we
    # test if the path to PHP starts with /cygdrive/ rather than /usr/bin
    if [[ $(which php) == /cygdrive/* ]]; then
        dir=$(cygpath -m "$dir");
    fi
fi

dir=$(echo $dir | sed 's/ /\ /g')
"${dir}/phpunit" "$@"

另外,我把单元测试配置到系统环境变量里面,执行测试


phpunit app/tests/UserTest.php

需要在代码头部引入autoload.php


require_once 'vendor/autoload.php';

没法自动加载的吗

代言
代言

全部回复(1)
世界只因有你

你可以在框架外,随便写一个单元测试文件,使用phpunit xxx.php 测试一下,这样就知道是否phpunit安装正常,是否引入autoload.php方式错了,逐一排查。

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号