Symfony – How to click on a button in PHPUnit (Symfony2)

button, click, functional-testing, phpunit, symfony

Hi, I'm writing a functional test and I want to know how to perform a simple click on a button, I have a hidden form that is shown after the button click

I tried doing a normal click like that :

$button  = $crawler->filter('button:contains("Add")');$crawler = $client->click($button);

but it seems the click() function take a Link Object not a Crawler Object.

how can I do something like that ?

Best Solution

I assume you use JS to show your hidden form.This will not work since the crawler doesn't support JS, you better look up CasperJs or some other crawler if you want to test the click and visibility of your form.

Symfony2 Functional Testing - Click on elements with jQuery interaction

Otherwise if testing the submit of the form is what you want to achieve, then you can use :

$form = $crawler->filter('button#idofyourbutton')->form(array(            'firstname' => 'Blabla',            'lastname' => 'Blabla',            'address' => 'BlablaBlablaBlablaBlabla',            'zipcode' => '302404',            'phone' => '30030130269'        ),'POST');        $client->submit($form);