php - sibling ()错误: InvalidArgumentException: The current node list is empty

标签 php symfony phpunit

我在 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/

相关文章:

php - 通过XAMPP使用PHP连接到MySQL时,即使授予所有特权,访问也会被拒绝

php - 如何正确格式化 SQL 日期时间

mongodb - 如何对集合中的数组进行排序

php - CreateQuery Doctrine Symfony 2 StateFieldPathExpression

symfony - 为表单生成器添加方法创建自定义选项

php - 使用 PHPUnit 测试触发错误的方法的返回值

php - 将 Crypt 与 Laravel phpunit 测试一起使用

php - Magento 1.9 - 模块中的多个助手

php - 从 php 网站检索数据到 Android 应用程序

php - PHPUnit 中需要可变参数列表