vimuth
vimuth

Reputation: 5612

symfony 4 - InvalidArgumentException: The current node list is empty

Hi I'm trying to add symfony unit test for a form. This is my code...

$crawler = $this->client->request('GET', '/admin/user/new');

        $form = $crawler->selectButton('Save')->form(array(
            'user[displayName]' => 'user',
            'user[username]' => '[email protected]',
            'user[password]' => 'user123',
            'user[phoneNumber]' => '1234789',
            'user[roles]' => 'ROLE_USER',
        ));
        $crawler = $this->client->submit($form);

        $crawler = $this->client->followRedirect();

        $this->assertGreaterThan(
                0, $crawler->filter('html:contains("Le tue modifiche sono state salvate!")')->count()
        );

But I only ends up with this error,

InvalidArgumentException: The current node list is empty.

It works when I try with language English but only fail when I change my default language to Italian in my app.

Upvotes: 0

Views: 3179

Answers (1)

vimuth
vimuth

Reputation: 5612

It appears to be I need italian translation for the button. The current node list is empty meant can't get $form = $crawler->selectButton('Save') node. since I have translated the interface to italy It had to be changed to italian wording.

$form = $crawler->selectButton('Salva')

And You can get by class or id so language will not matter.

$form = $crawler->filter('button.btn-success')

I'm keeping this in case anyone may lean something from it...

Upvotes: 2

Related Questions