0

i'm a beginner with phpunit and i want to exectue vendor/bin/phpunit on a new symfony project. but i have this error :

PHPUnit 5.7.23 by Sebastian Bergmann and contributors.

E 1 / 1 (100%)

Time: 576 ms, Memory: 16.50MB

There was 1 error:

1) Tests\AppBundle\Controller\DefaultControllerTest::testIndex InvalidArgumentException: The current node list is empty.

C:\wamp64\www\testsunitairesexemple\vendor\symfony\symfony\src\Symfony\Component\DomCrawler\Crawler.php:568 C:\wamp64\www\testsunitairesexemple\tests\AppBundle\Controller\DefaultControllerTest.php:22

ERRORS! Tests: 1, Assertions: 1, Errors: 1.

my test class is :

<?php

namespace Tests\AppBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class DefaultControllerTest extends WebTestCase
{
    public function testIndex()
    {
        $client = static::createClient();

        $crawler = $client->request('GET', '/');

        $this->assertEquals(200, $client->getResponse()->getStatusCode());
        $this->assertContains('Welcome to Symfony', $crawler->filter('#container h1')->text());
    }
}

how can i resolve this problem.

log :

[2017-10-18 17:20:55] request.INFO: Matched route "homepage". {"route":"homepage","route_parameters":{"_controller":"AppBundle\Controller\DefaultController::indexAction","_route":"homepage"},"request_uri":"http://localhost/","method":"GET"} [] [2017-10-18 17:20:55] security.INFO: Populated the TokenStorage with an anonymous Token. [] [] [2017-10-19 08:13:33] request.INFO: Matched route "homepage". {"route":"homepage","route_parameters":{"_controller":"AppBundle\Controller\DefaultController::indexAction","_route":"homepage"},"request_uri":"http://localhost/","method":"GET"} [] [2017-10-19 08:13:34] security.INFO: Populated the TokenStorage with an anonymous Token. [] [] [2017-10-19 08:17:40] request.INFO: Matched route "homepage". {"route":"homepage","route_parameters":{"_controller":"AppBundle\Controller\DefaultController::indexAction","_route":"homepage"},"request_uri":"http://localhost/","method":"GET"} [] [2017-10-19 08:17:40] security.INFO: Populated the TokenStorage with an anonymous Token. [] [] [2017-10-19 08:25:24] request.INFO: Matched route "homepage". {"route":"homepage","route_parameters":{"_controller":"AppBundle\Controller\DefaultController::indexAction","_route":"homepage"},"request_uri":"http://localhost/","method":"GET"} [] [2017-10-19 08:25:24] security.INFO: Populated the TokenStorage with an anonymous Token. [] [] [2017-10-19 08:27:05] request.INFO: Matched route "homepage". {"route":"homepage","route_parameters":{"_controller":"AppBundle\Controller\DefaultController::indexAction","_route":"homepage"},"request_uri":"http://my.server.location/","method":"GET"} [] [2017-10-19 08:27:05] security.INFO: Populated the TokenStorage with an anonymous Token. [] [] [2017-10-19 08:42:49] request.INFO: Matched route "homepage". {"route":"homepage","route_parameters":{"_controller":"AppBundle\Controller\DefaultController::indexAction","_route":"homepage"},"request_uri":"http://127.0.0.1:8000/","method":"GET"} [] [2017-10-19 08:42:49] security.INFO: Populated the TokenStorage with an anonymous Token. [] [] [2017-10-19 08:43:03] request.INFO: Matched route "homepage". {"route":"homepage","route_parameters":{"_controller":"AppBundle\Controller\DefaultController::indexAction","_route":"homepage"},"request_uri":"http://127.0.0.1/","method":"GET"} [] [2017-10-19 08:43:03] security.INFO: Populated the TokenStorage with an anonymous Token. [] [] [2017-10-19 08:43:18] request.INFO: Matched route "homepage". {"route":"homepage","route_parameters":{"_controller":"AppBundle\Controller\DefaultController::indexAction","_route":"homepage"},"request_uri":"http://127.0.0.1:8000/","method":"GET"} [] [2017-10-19 08:43:18] security.INFO: Populated the TokenStorage with an anonymous Token. [] [] [2017-10-19 08:46:57] request.INFO: Matched route "homepage". {"route":"homepage","route_parameters":{"_controller":"AppBundle\Controller\DefaultController::indexAction","_route":"homepage"},"request_uri":"http://127.0.0.1:8000/","method":"GET"} [] [2017-10-19 08:46:57] security.INFO: Populated the TokenStorage with an anonymous Token. [] [] [2017-10-19 08:48:18] request.INFO: Matched route "homepage". {"route":"homepage","route_parameters":{"_controller":"AppBundle\Controller\DefaultController::indexAction","_route":"homepage"},"request_uri":"http://http/","method":"GET"} [] [2017-10-19 08:48:19] security.INFO: Populated the TokenStorage with an anonymous Token. [] [] [2017-10-19 08:54:42] request.INFO: Matched route "homepage". {"route":"homepage","route_parameters":{"_controller":"AppBundle\Controller\DefaultController::indexAction","_route":"homepage"},"request_uri":"http://http/","method":"GET"} [] [2017-10-19 08:54:42] security.INFO: Populated the TokenStorage with an anonymous Token. [] [] [2017-10-19 09:03:43] request.INFO: Matched route "homepage". {"route":"homepage","route_parameters":{"_controller":"AppBundle\Controller\DefaultController::indexAction","_route":"homepage"},"request_uri":"http://localhost/","method":"GET"} [] [2017-10-19 09:03:43] security.INFO: Populated the TokenStorage with an anonymous Token. [] [] [2017-10-19 09:04:19] request.INFO: Matched route "homepage". {"route":"homepage","route_parameters":{"_controller":"AppBundle\Controller\DefaultController::indexAction","_route":"homepage"},"request_uri":"http://localhost/","method":"GET"} [] [2017-10-19 09:04:19] security.INFO: Populated the TokenStorage with an anonymous Token. [] [] [2017-10-19 09:09:18] request.INFO: Matched route "homepage". {"route":"homepage","route_parameters":{"_controller":"AppBundle\Controller\DefaultController::indexAction","_route":"homepage"},"request_uri":"http://localhost/","method":"GET"} [] [2017-10-19 09:09:18] security.INFO: Populated the TokenStorage with an anonymous Token. [] [] [2017-10-19 09:13:19] request.INFO: Matched route "homepage". {"route":"homepage","route_parameters":{"_controller":"AppBundle\Controller\DefaultController::indexAction","_route":"homepage"},"request_uri":"http://localhost/","method":"GET"} [] [2017-10-19 09:13:19] security.INFO: Populated the TokenStorage with an anonymous Token. [] [] [2017-10-19 09:31:36] request.INFO: Matched route "homepage". {"route":"homepage","route_parameters":{"_controller":"AppBundle\Controller\DefaultController::indexAction","_route":"homepage"},"request_uri":"http://localhost/","method":"GET"} [] [2017-10-19 09:31:36] security.INFO: Populated the TokenStorage with an anonymous Token. [] [] [2017-10-19 09:32:06] request.INFO: Matched route "homepage". {"route":"homepage","route_parameters":{"_controller":"AppBundle\Controller\DefaultController::indexAction","_route":"homepage"},"request_uri":"http://localhost/","method":"GET"} [] [2017-10-19 09:32:07] security.INFO: Populated the TokenStorage with an anonymous Token. [] [] [2017-10-19 12:33:06] request.INFO: Matched route "homepage". {"route":"homepage","route_parameters":{"_controller":"AppBundle\Controller\DefaultController::indexAction","_route":"homepage"},"request_uri":"http://localhost/","method":"GET"} [] [2017-10-19 12:33:06] security.INFO: Populated the TokenStorage with an anonymous Token. [] [] [2017-10-19 12:33:36] request.INFO: Matched route "homepage". {"route":"homepage","route_parameters":{"_controller":"AppBundle\Controller\DefaultController::indexAction","_route":"homepage"},"request_uri":"http://localhost/","method":"GET"} [] [2017-10-19 12:33:36] security.INFO: Populated the TokenStorage with an anonymous Token. [] [] [2017-10-19 12:38:35] request.INFO: Matched route "homepage". {"route":"homepage","route_parameters":{"_controller":"AppBundle\Controller\DefaultController::indexAction","_route":"homepage"},"request_uri":"http://localhost/","method":"GET"} [] [2017-10-19 12:38:35] security.INFO: Populated the TokenStorage with an anonymous Token. [] [] [2017-10-19 12:39:31] request.INFO: Matched route "homepage". {"route":"homepage","route_parameters":{"_controller":"AppBundle\Controller\DefaultController::indexAction","_route":"homepage"},"request_uri":"http://localhost/","method":"GET"} [] [2017-10-19 12:39:31] security.INFO: Populated the TokenStorage with an anonymous Token. [] [] [2017-10-19 12:42:33] request.INFO: Matched route "homepage". {"route":"homepage","route_parameters":{"_controller":"AppBundle\Controller\DefaultController::indexAction","_route":"homepage"},"request_uri":"http://localhost/","method":"GET"} [] [2017-10-19 12:42:33] security.INFO: Populated the TokenStorage with an anonymous Token. [] [] [2017-10-19 12:42:57] request.INFO: Matched route "homepage". {"route":"homepage","route_parameters":{"_controller":"AppBundle\Controller\DefaultController::indexAction","_route":"homepage"},"request_uri":"http://localhost/","method":"GET"} [] [2017-10-19 12:42:57] security.INFO: Populated the TokenStorage with an anonymous Token. [] []

walidtlili
  • 840
  • 2
  • 13
  • 36
  • Possible duplicates of : https://stackoverflow.com/questions/9469802/symfony2-functional-testing-invalidargumentexception-the-current-node-list-is-e – teeyo Oct 19 '17 at 08:32
  • Possible duplicate of [Symfony2 functional testing InvalidArgumentException: The current node list is empty](https://stackoverflow.com/questions/9469802/symfony2-functional-testing-invalidargumentexception-the-current-node-list-is-e) – teeyo Oct 19 '17 at 08:32
  • You can check this one too https://stackoverflow.com/questions/30328653/phpunit-the-current-node-list-is-empty – teeyo Oct 19 '17 at 08:33
  • Can some one help me? i can't understand – walidtlili Oct 19 '17 at 08:53
  • can you give us var/logs/test.log – Mocrates Oct 19 '17 at 11:44
  • question updated – walidtlili Oct 19 '17 at 12:45
  • It is my guess that "$crawler->filter('#container h1')->text()" cannot find anything. trying doing a print_r( $crawler->filter('#container h1') ), if I 'm correct it will be null or an empty array.- – MEmerson Oct 20 '17 at 01:04

0 Answers0