Reputation: 9
I'm trying to execute a simple test with PHPUnit on Symfony 2.8 application. This is the 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);
}
And the TWIG file:
{% 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 %}
When I execute this test, I get the following error:
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.
This is the line number 24: $link = $crawler->filter('a:contains("Cancel")')->link();
Furthermore, I tried to check the $crawler content with var_dump, and this is the result:
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 version: 5.3.2 PHP Version: 5.6.18 Symfony version: 2.8.4 OS: Fedora 23
Can someone help me?
EDIT
I tried to check my YAML file, and I get this error:
ERROR:
while scanning for the next token found character '@' that cannot start any token in "", line 22, column 15: resource: @MaestroBundle/Controller/ ^
This is my YAML file:
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"
I also tried to check the client response with:
$this->assertTrue($client->getResponse()->isSuccessful());
But PHPUnit shows this error:
Failed asserting that false is true
Hope that someone can help me.
Upvotes: 0
Views: 687
Reputation: 9
Finally I solved the problem!! Thank you @A.L and @Matteo for your comments; the problem was that I have no "" in the YAML before the @Bundle, now it's working!
My final version of YAML file is:
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"
Thank you very much! Isaac.
Upvotes: 0