我跟着Symfony 文档 http://symfony.com/doc/current/book/testing.html#functional-tests关于功能测试,以便编写我的第一个测试,但我有一些问题。我通过浏览器得到的响应效果很好:
但当我跑步时phpunit -c app/
在 shell 中我失败了。
1)
AppBundle\Tests\Controller\MeterAPIControllerTest::testGetAllVariables
无法断言 500 与预期 200 匹配。
这是代码:
<?php
namespace AppBundle\Tests\Controller;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class MeterAPIControllerTest extends WebTestCase
{
public function testGetAllVariables()
{
$client = static::createClient();
$crawler = $client->request(
'GET',
'/meters/121/120/variables'
);
// Assert a specific 200 status code
$this->assertEquals(200, $client->getResponse()->getStatusCode());
}
}
如果我尝试另一个测试断言,我也会失败。
// Assert that the "Content-Type" header is "application/json"
$this->assertTrue(
$client->getResponse()->headers->contains(
'Content-Type',
'application/json'
)
);
EDIT
当我跑步时phpunit
in app/logs/test.log
我收到 PHP 异常:
[2016-03-31 15:25:21] request.CRITICAL:未捕获的 PHP 异常
Doctrine\Common\Persistence\Mapping\MappingException:“无效映射
类的文件“AppBundle.Entity.EM2Meter.orm.yml”
'AppBundle\Entity\EM2Meter'。”位于
/Applications/MAMP/htdocs/iso50k1_tst_symfony/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/MappingException.php
第 86 行 {"异常":"[对象]
(Doctrine\Common\Persistence\Mapping\MappingException(代码:0):
类的映射文件“AppBundle.Entity.EM2Meter.orm.yml”无效
'AppBundle\Entity\EM2Meter'。在
/Applications/MAMP/htdocs/iso50k1_tst_symfony/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/MappingException.php:86)"}
[]
我怎样才能解决这个问题?
您还没有告诉 symfony 客户端在端口 8000 上联系本地主机服务器,它仍然默认为 80。
当您实例化客户端时,请像这样指定主机。
$client = static::createClient([], [
'HTTP_HOST' => 'localhost:8000',
] );
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)