我跟着Symfony documentation關於功能測試,以寫我的第一個,但我有一些問題。我通過瀏覽器得到響應做工不錯:Symfony功能測試失敗,但相同的請求在瀏覽器中工作
但是,當我在shell中運行phpunit -c app/
我得到一個失敗。
1) 的appbundle \測試\控制器\ 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'
)
);
編輯
當我在app/logs/test.log
運行phpunit
我得到一個PHP異常:
[2016年3月31日15點25分21秒] request.CRITICAL:未捕獲的PHP例外 Doctrine \ Common \ Persistence \ Mapping \ MappingException:「無效映射 文件'AppBundle.Entity.EM2Meter.orm.yml'對於類 'AppBundle \ Entity \ EM2Meter'。」 at /Applications/MAMP/htdocs/iso50k1_tst_symfony/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/MappingException.php line 86 {「exception」:「[object] (Doctrine \ Common \ Persistence \ Mapping \ MappingException(code:0): 'AppBundle.Entity.EM2Meter.orm.yml'類映射文件'012' common/lib/Doctrine/Common/Persistence/Mapping/MappingException.php:86)「} []
我該如何解決這個問題?
你確定你的請求到正確的端口? – DevDonkey
@DevDonkey是的,請求是正確的。 – Francesco
你確定嗎?我想你會發現,除非你指定當你實例化一個新的客戶端,它會默認爲端口80. – DevDonkey