2016-04-28 14 views
0

symfony 2.8アプリケーションでPHPUnitを使用して簡単なテストを実行しようとしています。 これはテストです:Symfony 2.8でPHPUnit Testを実行しようとするとエラーが発生する

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); 

    } 

そしてTWIGファイル:

{% 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 OS:Fedora 23

誰かが私を助けることができますか?

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" 

私もチェックしてみました、私は私のYAMLファイルをチェックしてみました、そして、私はこのエラーを取得する

EDIT

クライアントレスポンス:

$this->assertTrue($client->getResponse()->isSuccessful()); 

しかし、PHPUnitがこのエラーを示しています。誰かが私を助けることができることを

Failed asserting that false is true

希望。

+0

エラーメッセージに記載されているように、あなたは 'app/config/routing.yml'にエラーがあります。あなたはオンラインのYAMLバリデーターでそれをチェックすることができます:http://yaml-online-parser.appspot.com/ –

+1

メモとして、他のものをチェックする前に、クライアントのリクエストが '$ this-> assertTrue $ client-> getResponse() - > isSuccessful()); ' – Matteo

+0

ありがとうございます、私はあなたのソリューションを試して、その結果で質問を編集しました。 –

答えて

0

最後に問題を解決しました。 コメントありがとうございます@A.Lと@Matteo;問題は、@バンドルの前のYAMLには ""ありませんでした。今は動作しています!

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" 

はどうもありがとうございました! アイザック。

関連する問題