目前,我正在为 Symfony2 应用程序编写验收测试用例。我正在关注。
namespace my\Bundle\ProjectBundle\Tests\Controller;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class DefaultControllerTest extends WebTestCase
{
public function testIndex()
{
$client = static::createClient();
$client->request('GET', '/');
$this->assertEquals(200, $client->getResponse()->getStatusCode());
}
}
但是它无法查看以下日志文件。
app/logs/test.log
看起来
[2016-09-06 12:56:58] request.CRITICAL: Uncaught PHP Exception PHPUnit_Framework_Error_Notice: "Undefined index: SERVER_PROTOCOL" at /var/www/src/my/Bundle/projectBundle/Helper/DataHelper.php line 139 {"exception":"[object] (PHPUnit_Framework_Error_Notice(code: 8): Undefined index: SERVER_PROTOCOL at /var/www/src/my/Bundle/projectBundle/Helper/DataHelper.php:139)"} []
似乎$_SERVER
变量中缺少一些值。任何线索或是否有更好的方法来编写测试用例。
数据助手.php
public function getCanonicalUrl()
{
$router = $this->container->get('router');
$req = $this->container->get('request');
$route = $req->get('_route');
if (!$route) {
return 'n/a';
}
$url = $router->generate($route, $req->get('_route_params'));
$protocol = stripos($_SERVER['SERVER_PROTOCOL'], 'https') === true ? 'https://' : 'http://';
return $protocol . ($this->getHostname() . $url);
}