Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHPUnit单位发行_Php_Codeigniter_Jenkins_Phpunit - Fatal编程技术网

PHPUnit单位发行

PHPUnit单位发行,php,codeigniter,jenkins,phpunit,Php,Codeigniter,Jenkins,Phpunit,当我运行特定的测试套件时 phpunit --testsuite LibTests 我得到了预期的结果(通过测试)。但是,当我运行“phpunit”时,我得到一个错误,声称: Fatal error: Call to a member function rss_feed_url() on a non-object in /Users/Shared/Jenkins/Home/jobs/Fanpilot_CT_3.0/workspace/tests/libs/VoltampMediaRSSFeed

当我运行特定的测试套件时

phpunit --testsuite LibTests
我得到了预期的结果(通过测试)。但是,当我运行“phpunit”时,我得到一个错误,声称:

Fatal error: Call to a member function rss_feed_url() on a non-object in /Users/Shared/Jenkins/Home/jobs/Fanpilot_CT_3.0/workspace/tests/libs/VoltampMediaRSSFeedTest.php on line 20
其中rss_feed_url()是我在setup()中加载的类的方法

下面是我的phpunit.xml文件的一个片段

<testsuites>
    <testsuite name="LibTests">
      <directory suffix=".php">tests/libs</directory>
    </testsuite>
</testsuites>

测试/库

提前谢谢

在phpunit中,似乎大多数类变量在测试方法之间未设置。如果这是问题所在(听起来很像,有非对象错误)。我相信通过将这些变量设置为私有和/或静态,我自己解决了这个问题。

问题在于我没有将$this->CI重新初始化到适当的控制器。上次测试时,它已经过时了。在每个setUp()m中,您需要确保初始化$this CI,如下所示:

$this->CI = set_controller();
在我的例子中,我有一个自定义的my_控制器(applications/core/my_Controller.php)。因此,如果需要利用自定义控制器,我可以这样做

$this->CI = set_controller('MY_Controller');
作为补充说明,我最终通过在CIU_Loader方法(CIU ci_load_类)中转储get_类和get_parent_类找到了答案,我注意到这些值取决于我是作为单个测试还是作为所有测试运行