尽管内容存在,但功能测试失败

时间:2014-05-14 17:31:24

标签: symfony functional-testing liipfunctionaltestbundle

在下面的功能测试中,断言文本' Glenshire'即使echo $client->getResponse()->getContent();的输出包括

,存在也会失败
<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();
   }

1 个答案:

答案 0 :(得分:1)

奇怪的是,更换线路 $this->assertTrue($crawler->filter('li:contains("Glenshire")')->count() > 0, 'Glenshire not found');

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

提供了成功的测试!