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