1

在下面的功能测试中,文本“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();
   }
4

1 回答 1

1

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

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

提供了一个成功的测试!

于 2014-05-14T22:44:11.503 回答