phpunit InvalidArgumentException:当前节点列表为空

时间:2013-12-01 15:10:07

标签: symfony phpunit

运行具有以下行的测试:

$authorizeForm = $crawler->selectButton('Authorize')->form();

输出此错误:

There was 1 error:

1) Citiqa\ApiBundle\Tests\Controller\SecurityControllerTest::testLoginAndAuthorize
InvalidArgumentException: The current node list is empty.

/home/oris/src/citiqa-api/vendor/symfony/symfony/src/Symfony/Component/DomCrawler/Crawler.php:648
/home/oris/src/citiqa-api/src/Citiqa/ApiBundle/Tests/Controller/SecurityControllerTest.php:28

我看了Crawler.php并看到了有问题的功能:

  public function form(array $values = null, $method = null)
{
    //var_dump($this);
    if (!count($this)) {
        throw new \InvalidArgumentException('The current node list is empty.');
    }

    $form = new Form($this->getNode(0), $this->uri, $method);

    if (null !== $values) {
        $form->setValues($values);
    }

    return $form;
}
在这种情况下,

$this是扩展\SplObjectStorage的爬虫对象,它实现了Countable接口,所以我们应该没问题。我尝试var_dump($this); form(),我看到了这一点:

object(Symfony\Component\DomCrawler\Crawler)#1354 (2) {
  ["uri":"Symfony\Component\DomCrawler\Crawler":private]=>
  string(37) "https://localhost/oauth/v2/auth_login"
  ["storage":"SplObjectStorage":private]=>
  array(1) {
    ["0000000075b694bd000000002b32afe0"]=>
array(2) {
  ["obj"]=>
  object(DOMElement)#529 (18) {
    ["tagName"]=>
    string(6) "button"
    ["schemaTypeInfo"]=>
    NULL
    ["nodeName"]=>
    string(6) "button"
    ["nodeValue"]=>
    string(5) "login"
    ["nodeType"]=>
    int(1)
    ["parentNode"]=>
    string(22) "(object value omitted)"
    ["childNodes"]=>
    string(22) "(object value omitted)"
    ["firstChild"]=>
    string(22) "(object value omitted)"
    ["lastChild"]=>
    string(22) "(object value omitted)"
    ["previousSibling"]=>
    string(22) "(object value omitted)"
    ["nextSibling"]=>
    string(22) "(object value omitted)"
    ["attributes"]=>
    string(22) "(object value omitted)"
    ["ownerDocument"]=>
    string(22) "(object value omitted)"
    ["namespaceURI"]=>
    NULL
    ["prefix"]=>
    string(0) ""
    ["localName"]=>
    string(6) "button"
    ["baseURI"]=>
    NULL
    ["textContent"]=>
    string(5) "login"
  }
  ["inf"]=>
  NULL
   }
  }
 }
object(Symfony\Component\DomCrawler\Crawler)#1852 (2) {
  ["uri":"Symfony\Component\DomCrawler\Crawler":private]=>
  string(155) "https://localhost/oauth/v2/auth?client_id=1_5ndcb2XXXXX&redirect_uri=http%3A%2F%2Fwww.google.com&response_type=token"
  ["storage":"SplObjectStorage":private]=>
  array(0) {
 }
}
  • phpunit版本是3.6.10

  • 有趣的是,这个测试在另一台机器上成功完成,使用不同的phpunit版本(3.7.21)。这可能是版本/错误报告级别的问题吗?

0 个答案:

没有答案