我試圖在Symfony 2.8應用程序上用PHPUnit執行一個簡單的測試。 這是測試:嘗試在Symfony 2.8中執行PHPUnit測試時出錯
public function testCreateContact(){
$client= static::createClient();
$client->followRedirects();
$crawler = $client->request('GET', '/contact_create');
$link = $crawler->filter('a:contains("Cancel")')->link();
$crawlerLink = $client->click($link);
}
而且樹枝文件:
{% extends '::layout.html.twig' %}
{% block title %}MaestroBundle:Contacto:alta{% endblock %}
{% block body %}
<h1>New Contacto</h1>
<div class="form_error"></div>
<div id="form_body">
<form id="createForm" method="POST" {{ form_enctype(form) }}>
{{ form_widget(formulario) }}
<input type="submit" value="create"/>
</form>
<a id="cancel" name="cancel" href="{{ path('contact_show') }}">Cancel</a>
</div>
{% endblock %}
當我執行這項測試中,我得到以下錯誤:
There was 1 error:
1) SisEvo\MaestroBundle\Tests\Controller\ContactoControllerTest::testCrearContacto InvalidArgumentException: The current node list is empty.
/var/www/html/evoIsaac/vendor/symfony/symfony/src/Symfony/Component/DomCrawler/Crawler.php:706 /var/www/html/evoIsaac/src/SisEvo/MaestroBundle/Tests/Controller/ContactoControllerTest.php:24
FAILURES! Tests: 2, Assertions: 1, Errors: 1.
這是行號24 : $ link = $ crawler-> filter('a:contains(「Cancel」)') - > link();
此外,我試着檢查$履帶含量的var_dump,這就是結果:
The file "/var/www/html/evoIsaac/app/config/routing.yml" does not contain valid YAML in /var/www/html/evoIsaac/app/config/routing.yml (which is being imported from "/var/www/html/evoIsaac/app/config/routing_dev.yml"). (500 Internal Server Error)
PHPUnit的版本:5.3.2 PHP版本:5.6.18 Symfony的版本:2.8.4 操作系統:Fedora 23
有人可以幫助我嗎?
編輯
我想檢查我的YAML文件,我得到這個錯誤:
ERROR:
while scanning for the next token found character '@' that cannot start any token in "", line 22, column 15: resource: @MaestroBundle/Controller/ ^
這是我的YAML文件:
cys:
resource: "@CysBundle/Controller/"
type: annotation
prefix: /
homepage:
path:/
defaults:
_controller: FrameworkBundle:Template:template
template: 'default/login.html.twig'
contrato_evolutia:
resource: "@ContratoEvolutiaBundle/Controller/"
type: annotation
api_maestro:
resource: "@ApiBundle/Controller/Maestro/"
type: annotation
maestro:
resource: @MaestroBundle/Controller/
type: annotation
default:
resource: @DefaultBundle/Controller/
type: annotation
fos_js_routing:
resource: "@FOSJsRoutingBundle/Resources/config/routing/routing.xml"
我也試圖檢查客戶迴應:
$this->assertTrue($client->getResponse()->isSuccessful());
但PHPUnit的顯示此錯誤:
Failed asserting that false is true
希望有人能幫助我。
如錯誤消息中所述,您在'app/config/routing.yml'中有錯誤。你可以用一個在線的YAML驗證器來檢查它:http://yaml-online-parser.appspot.com/ –
作爲一個註釋,在檢查其他東西之前,請驗證客戶端請求是否正確,例如'$ this-> assertTrue $ client-> getResponse() - > isSuccessful());' – Matteo
謝謝你,我試過你的解決方案,並用結果編輯問題。 –