【问题标题】:Functional test fails although content exists尽管存在内容,但功能测试失败
【发布时间】:2014-05-14 17:31:24
【问题描述】:

在下面的功能测试中,即使echo $client->getResponse()->getContent(); 的输出包含

,文本“Glenshire”存在的断言也会失败
<li>Glenshire...

前两个断言是正确的。没有重定向。

测试

class SearchTest extends WebTestCase
{

    public function setUp()
    {
        $classes = array(
            'Vol\VolBundle\DataFixtures\ORM\LoadFocusSkillData',
            'Vol\VolBundle\DataFixtures\ORM\LoadOpportunity',
        );
        $this->loadFixtures($classes);
    }

    public function testSearch()
    {
        $client = static::createClient();
        $crawler = $client->request('GET', '/search');
        $this->assertTrue($crawler->filter('html:contains("Focus")')->count() > 0);
        $this->assertTrue($crawler->filter('html:contains("Skill")')->count() > 0);
        $form = $crawler->selectButton('match_search[Submit]')->form();
        $form['match_search[focuses][0]'] = 1;
        $client->submit($form);
        echo $client->getResponse()->getContent();
        $this->assertTrue($crawler->filter('li:contains("Glenshire")')->count() > 0, 'Glenshire not found');
    }

夹具(使用 LiipFunctionalTestBundle)

    public function load(ObjectManager $manager)
    {
        $manager->clear();
        $org = new Organization();
        $org->setOrganization('Glenshire Marmot Fund');
        $foc1 = $manager->getRepository("VolVolBundle:Focus")->find(1);
        $foc3 = $manager->getRepository("VolVolBundle:Focus")->find(3);
        $foc4 = $manager->getRepository("VolVolBundle:Focus")->find(4);
        $org->addFocus($foc1);
        $org->addFocus($foc3);
        $org->addFocus($foc4);
        $opp = new Opportunity();
        $opp->setName('Feeder');
        $opp->setDescription("Beyond recourse");
        $opp->setExpireDate(date_add(new \DateTime(), new \DateInterval('P1Y')));
        $opp->setOrganization($org);

        $manager->persist($opp);
        $manager->flush();
   }

【问题讨论】:

    标签: symfony functional-testing liipfunctionaltestbundle


    【解决方案1】:

    奇怪的是,换行 $this-&gt;assertTrue($crawler-&gt;filter('li:contains("Glenshire")')-&gt;count() &gt; 0, 'Glenshire not found');

    $this->assertRegExp(
            '/Glenshire/', $client->getResponse()->getContent(), 'Glenshire not found'
    );
    

    提供成功的测试!

    【讨论】:

      猜你喜欢
      • 2019-08-26
      • 2019-05-12
      • 1970-01-01
      • 1970-01-01
      • 2015-11-15
      • 1970-01-01
      • 2016-03-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多