我在 symfony2 单元测试中出错,symfony : 2.7.1
when I use siblings() I have a the error:
InvalidArgumentException: 当前节点列表为空。 Twig 文件:
<h1>ddd</h1>
<p>ahmedghgh</p>
<ul>
<li>dddd</li>
<li>eeee</li>
<li>ffff</li>
</ul>
</p>bye</p>
<form action ="" method="GET" name ="nameForm">
<input type="text" value ="name" name="name">
<input type="submit" value ="send" name="send">
</form>
BasicControllerTest.php
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
namespace TestingSymfony\BasicBundle\Tests\Controller;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class BasicControllerTest extends WebTestCase {
public function testHelloContent() {
$client = static::createClient();
$crawler = $client->request('GET', '/helloworld');
$h1 = $crawler->filter('h1')->eq(0);
$p1 = $crawler->filter('p')->first();
$ul = $p1->siblings()->eq(0);
$l1 = $ul->children()->first();
$l2 = $ul->children()->eq(1);
$l3 = $ul->children()->last();
$p2 = $crawler->filterXPath("//p")->last();
}
}
一旦我删除 sibling ,一切正常,没有出现错误
最佳答案
你在 Twig 文件中有一个拼写错误:检查 P 标签是否正确打开和关闭,如下所示:
<p>bye</p>
代替
</p>bye</p>
希望对你有帮助
关于php - sibling ()错误: InvalidArgumentException: The current node list is empty,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31559996/