我在symfony应用程序上运行phpunit测试时遇到问题。
我使用以下断言代码:
namespace Main\MyBundle\Tests\Controller;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class DefaultControllerTest extends WebTestCase
{
public function testIndex()
{
$client = static::createClient();
$crawler = $client->request('GET', '/');
var_dump( $client->getInternalResponse());
//checking home page availability
$this->assertEquals(200, $client->getResponse()->getStatusCode());
}
}
但是我从下面的结果中看到了一直失败:
mcp@mcp-buildbox:/var/www/my.app.com$ phpunit -c app src/Main/MyBundle
PHPUnit 3.6.10 by Sebastian Bergmann.
Configuration read from /var/www/my.app.com/app/phpunit.xml.dist
Fclass Symfony\Component\BrowserKit\Response#182 (3) {
protected $content =>
string(138299) "<!DOCTYPE html>\n<html>\n <head>\n <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>\n <meta name="robots" content="noindex,nofollow" />\n <title> Undefined index: SERVER_PORT (500 Internal Server Error)\n</title>\n <link href="/bundles/framework/css/structure.css" rel="stylesheet" type="text/css" media="all" />\n <link href="/bundles/framework/css/body.css" rel="stylesheet" type="text/css" media="all" />\n <link href="/bundles/framework"...
protected $status =>
int(500)
protected $headers =>
array(3) {
'cache-control' =>
array(1) {
[0] =>
string(8) "no-cache"
}
'date' =>
array(1) {
[0] =>
string(29) "Thu, 08 May 2014 15:32:16 GMT"
}
'content-type' =>
array(1) {
[0] =>
string(24) "text/html; charset=UTF-8"
}
}
}
Time: 0 seconds, Memory: 22.25Mb
There was 1 failure:
1) Main\MyBundle\Tests\Controller\DefaultControllerTest::testIndex
Failed asserting that 500 matches expected 200.
/var/www/my.app.com/src/Main/MyBundle/Tests/Controller/DefaultControllerTest.php:25
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
这是我在config.yml中的框架设置:
framework:
#esi: ~
translator: { fallback: %locale% }
secret: %secret%
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: ~
http_port: 80
https_port: 443
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
templating:
engines: ['twig']
#assets_version: SomeVersionScheme
default_locale: "%locale%"
trusted_proxies: "%trusted_proxies%"
session: ~
fragments: ~
trusted_hosts: ~
另请注意,当我这样做时:
curl -I http://my.app.com
我明白了:
HTTP/1.1 200 OK
我也在使用PHP 5.4.9并在ubuntu机器上。有人可以帮忙吗?我看了堆栈,看到其他人有相同的问题,但解决方案对我来说并不清楚,答案不是真正的解决方案: