Forms PhpUnit表单未提交,无错误

Forms PhpUnit表单未提交,无错误,forms,symfony,phpunit,functional-testing,Forms,Symfony,Phpunit,Functional Testing,我正在PhpUnit中进行功能测试,以测试只有一个字段和两个按钮的简单模式窗口功能(我尝试了各种方法,因此代码可能不干净,我粘贴只是为了展示这个想法): 我还尝试对表单进行var_转储,这表明该值已添加到表单中: 字符串(25)“appbundle\u classinfo[名称]” [“值”:受保护]=> 串(2)“5a” 因此,表格未提交。你能帮我找出原因吗?你检查过API了吗?form()是否返回数组?$crawler对象没有submit方法。 <?php namespace App

我正在PhpUnit中进行功能测试,以测试只有一个字段和两个按钮的简单模式窗口功能(我尝试了各种方法,因此代码可能不干净,我粘贴只是为了展示这个想法):

我还尝试对表单进行var_转储,这表明该值已添加到表单中: 字符串(25)“appbundle\u classinfo[名称]” [“值”:受保护]=> 串(2)“5a”


因此,表格未提交。你能帮我找出原因吗?

你检查过API了吗?
form()
是否返回数组?
$crawler
对象没有
submit
方法。
<?php

namespace AppBundle\Tests\Controller;

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class PostTest extends WebTestCase
{
    public function testShowPost()
    {
        //returns a Client, your browser use your web site
        $client = static::createClient();

         // The request() method (read more about the request method) returns a Crawler object which can be used to select elements in the response, click on links and submit forms.
        $crawler = $client->request('GET', '/your/route/controller/action');

        // select button by name or id
         $form = $crawler->selectButton('Login')->submit();

         //submit the form
         $crawler->submit($form);

         $this->assertGreaterThan(
             0,
             $crawler->filter('html:contains("hello world")')->count()
         );

        // get HTML content returned
        dump($client->getResponse()->getContent());

    }
<?php

namespace AppBundle\Tests\Controller;

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class PostTest extends WebTestCase
{
    public function testShowPost()
    {
        //returns a Client, your browser use your web site
        $client = static::createClient();

         // The request() method (read more about the request method) returns a Crawler object which can be used to select elements in the response, click on links and submit forms.
        $crawler = $client->request('GET', '/your/route/controller/action');

        // select button by name or id
         $form = $crawler->selectButton('Login')->submit();

         //submit the form
         $crawler->submit($form);

         $this->assertGreaterThan(
             0,
             $crawler->filter('html:contains("hello world")')->count()
         );

        // get HTML content returned
        dump($client->getResponse()->getContent());

    }