I'm trying to test my application built in Symfony with PhpUnit (in local). In my homepage, I have a simple form to submit. I follow all the steps in various documentation (Symfony, phpUnit) and I've tested a lot of different solution from various forum but I'm still stuck...
Here is my test class :
namespace tests\FormBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class FormControllerTest extends WebTestCase
{
public function testReservationAction()
{
$client = static::createClient();
$crawler = $client->request('GET', '/tp4_louvres/web/app.php/info_reservation');
$bouton = $crawler->selectButton('Valider');
$form = $bouton->form(); //Here is the line 18 of the error
$validationFormulaire = $client->submit($form, array(
'#form_jour_jour' => '12/12/2017',
'#form_nom_reservation' => 'Robert',
'#form_prenom_reservation' => 'Paul',
'#form_email' => 'paul.robert@gmail.com'
));
$this->assertTrue($client->getResponse()->isRedirect('/tp4_louvres/web/app.php/info_billet'));
} // End of testReservationAction()
} // End class
and here is the form of my html page :
<form name="form" method="post">
<div class="form-group">
<label class="control-label required">Date de visite</label>
<div id="form_jour" class="col-3 p-0">
<div class="form-group">
<input type="text" id="form_jour_jour" name="form[jour][jour]" required="required" class="datepicker form-control" readonly="readonly" value="14/12/2017" />
</div>
</div>
</div>
<div class="form-group">
<label class="control-label required" for="form_nom_reservation">Nom de la réservation</label>
<input type="text" id="form_nom_reservation" name="form[nom_reservation]" required="required" class="form-control" value="FIACRE" />
</div>
<div class="form-group">
<label class="control-label required" for="form_prenom_reservation">Prénom de la réservation</label>
<input type="text" id="form_prenom_reservation" name="form[prenom_reservation]" required="required" class="form-control" value="Thibault" />
</div>
<div class="form-group">
<label class="control-label required" for="form_email">Email de la réservation</label>
<input type="email" id="form_email" name="form[email]" required="required" class="form-control" value="thibault.fiacre@gmail.com" />
</div>
<div class="form-group">
<button type="submit" id="bouton-valider" name="form[submit]" value="Valider" class="bg-info bouton-formulaire btn">Valider</button>
</div>
</form>
When I execute the test in the console I have this error :
1) tests\FormBundle\Controller\FormControllerTest::testReservationAction
InvalidArgumentException: The current node list is empty.
C:\wamp64\www\tp4_louvres\vendor\symfony\symfony\src\Symfony\Component\DomCrawler\Crawler.php:849
C:\wamp64\www\tp4_louvres\tests\FormBundle\Controller\FormControllerTest.php:18
It seams like the function form()
in $form=$bouton->form();
don't find the form on the page but the button is found...I tried to do var_dump($client->getResponse()->getContent());
And I have this error from Symfony :
Uncaught PHP Exception Symfony\Component\Config\Exception\FileLoaderLoadException:
"Cannot load resource ".". Make sure there is a loader supporting the "extra" type."
at C:\wamp64\www\tp4_louvres\vendor\symfony\symfony\src\Symfony\Component\Config\Loader\Loader.php line 73
I'm lost on this problem for 2 days...if anyone can help me it will be very appreciate ! Thanks a lot !