首页 > yii > Yii Goutte功能测试覆盖范围未被记录

Yii Goutte功能测试覆盖范围未被记录 (Yii Goutte Functional Test Coverage Not Being Recorded)

问题

功能测试覆盖范围不记录Goutte网络爬虫调用的任何控制器。

<?php

use Goutte\Client;

class DummyTest extends PHPUnit_Framework_TestCase {

/**
 * Web Crawler
 * @var \Goutte\Client
 */
protected $client;

public function setUp() {
    parent::setUp();
    $this->client = new Client();
}

public function testActionIndex() {

    $call = yii::app()->params['siteUrl'] . 'site/index';
    $crawler = $this->client->request('POST', $call, array(), array(), array());
    $response = $this->client->getResponse()->getContent();

    $this->assertEquals(200, $this->client->getResponse()->getStatus());
}
//..

相反,覆盖率报告显示测试本身已被覆盖。我期待报告显示站点控制器中的索引操作也被覆盖。

测试工作并确定服务器响应是200 OK。我是否需要调整任何配置以允许phpunit将请求跟踪到控制器/操作中? - 我使用PHP yii框架并使用netbeans和jenkins进行测试

解决方法

在这种情况下无法计算代码覆盖率,因为您正在抓取您的网站。调试器看到正在执行的唯一代码是测试本身,PHPUnit和一些Goutte代码。你的控制器没有被运行phpunit的同一个进程执行。它由Web服务器执行,但PHPUnit无法注意到它。

问题

Functional test coverage is not recording any controllers being called by a Goutte web crawler.

<?php

use Goutte\Client;

class DummyTest extends PHPUnit_Framework_TestCase {

/**
 * Web Crawler
 * @var \Goutte\Client
 */
protected $client;

public function setUp() {
    parent::setUp();
    $this->client = new Client();
}

public function testActionIndex() {

    $call = yii::app()->params['siteUrl'] . 'site/index';
    $crawler = $this->client->request('POST', $call, array(), array(), array());
    $response = $this->client->getResponse()->getContent();

    $this->assertEquals(200, $this->client->getResponse()->getStatus());
}
//..

Instead the coverage report shows that the test itself has been covered. I was expecting the report to show the index action in the site controller to be also covered.

The test works and ascertaining that the server response is a 200 OK. Do I need to adjust any configuration to allow phpunit to follow the request into the controller/action? - Im Using the PHP yii framework and testing with netbeans and jenkins

解决方法

The code coverage cannot be computed in this case, because you are crawling yor website. The debugger sees that the only code being executed is the test itself, PHPUnit and some Goutte code. Your controller is not being executed by the same process that runs phpunit. It's being executed by the web server, but PHPUnit can't notice it.

相似信息