Symfony2 functional testing InvalidArgumentException: The current node list is empty

前端 未结 7 705
伪装坚强ぢ
伪装坚强ぢ 2020-12-18 23:41

I get \"InvalidArgumentException: The current node list is empty.\" running functional tests through PHPUnit. Here is test i wrote:

public function testAdd()         


        
7条回答
  •  攒了一身酷
    2020-12-19 00:40

    I was also struggling with this, and It appeared that the selectButton method triggered this error.

    After reading up on the DOM Crawler docs I found that the selectButton method takes the actual button text as a string argument. So if your button is 'submit my form please', that will be your text.

    It does take different parameters too, as shown below (taken from the docs)

    A selectButton() method is available on the Crawler which returns another 
    Crawler that matches a button (input[type=submit], input[type=image], 
    or a button) with the given text.
    

    EDIT

    After finally successfully completing the test I would also recommend you follow this example for testing forms:

    use Goutte\Client;
    
    $client = new Client();
    $crawler = $client->request('GET', 'https://github.com/login');
    
    $form = $crawler->selectButton('Log in')->form();
    $form['login'] = 'symfonyfan';
    $form['password'] = 'anypass';
    
    $crawler = $client->submit($form);
    $this->assertTrue($crawler->filter('html:contains("Welcome Back")')->count() > 0);
    

    The main difference being, I have used the Goutte bundle, which I installed with composer from the packagist (in my case I added "fabpot/goutte": "1.0.*@dev")

提交回复
热议问题