douhao5280 2017-12-05 11:43
浏览 62

使用Symfony中的Phpunit测试form():InvalidArgumentException:当前节点列表为空

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 !

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥60 求一个简单的网页(标签-安全|关键词-上传)
    • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
    • ¥15 基于卷积神经网络的声纹识别
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图