mardi 19 mai 2015

PHPUnit The current node list is empty

I am creating some functional tests to test my controller. I have 2 functions at the moment. 1 for loggin in and 1 for the entity life cycle.

both should run normally (I guess). Yet I am getting the following error:

The current node list is empty

I tried removing all my code from the test class with no result. I also tried adding an empty method to see if it also happens there. And yes it does. That test also crashes.

So I googled for a solution. I tried a few things, like:

($client = static::createClient(array(), array('HTTP_HOST' => 'symfony.dev'));)

var_dump($client->getResponse()->getContent()); (which gets the page where the test should be)

Change the header:

$response = $this->render('CMSBundle:Front:test.html.twig',);
$response->headers->set('Content-Type', 'text/html');       

return $response;

And some other things. None of them worked. I cannot seem to figure out what the problem is.

Does anyone has any suggestions on this problem?

My test code:

public function testLogin()
{
    $client = $this->client;

    $crawler = $client->request('GET', '/admin/login');
    $this->assertEquals(200, $client->getResponse()->getStatusCode(), "Unexpected HTTP status code for GET /admin/login");

    // Fill in the form and submit it
    $form = $crawler->selectButton('Inloggen')->form(array(
        '_username'  => 'erik',
        '_password'  => 'erik'
    ));
    $client->submit($form);
}

Thanks in advance!

Aucun commentaire:

Enregistrer un commentaire