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
使用Kohana 3.2运行PHPUnit时抑制请求_Phpunit_Kohana 3.2 - Fatal编程技术网

使用Kohana 3.2运行PHPUnit时抑制请求

使用Kohana 3.2运行PHPUnit时抑制请求,phpunit,kohana-3.2,Phpunit,Kohana 3.2,在Kohana 3.2中正确设置单元测试时遇到问题 我安装了PHPUnit。我更改了引导以激活Kohana的unittest模块。我还将index.php文件更改为如下所示: if ( ! defined('SUPPRESS_REQUEST')) { echo Request::factory() ->execute() ->send_headers() ->body(); } <phpunit colors="t

在Kohana 3.2中正确设置单元测试时遇到问题

我安装了PHPUnit。我更改了引导以激活Kohana的unittest模块。我还将index.php文件更改为如下所示:

if ( ! defined('SUPPRESS_REQUEST'))
{
    echo Request::factory()
        ->execute()
        ->send_headers()
        ->body();
}
<phpunit colors="true" bootstrap="../../index.php">
<testsuites>
    <testsuite name="Kohana Tests">
        <directory>./</directory>
    </testsuite>
</testsuites>
我在我的应用程序文件夹中创建了一个测试文件夹。在其中,我插入了一个phpunit.xml文件,如下所示:

if ( ! defined('SUPPRESS_REQUEST'))
{
    echo Request::factory()
        ->execute()
        ->send_headers()
        ->body();
}
<phpunit colors="true" bootstrap="../../index.php">
<testsuites>
    <testsuite name="Kohana Tests">
        <directory>./</directory>
    </testsuite>
</testsuites>

这实际上现在还不是一个大问题,因为尽管如此,测试似乎仍在运行,但我想知道是否有人知道我是否应该在某个特定的地方设置这个变量。

在modules/unittest中有一个名为bootstrap.php的文件,它与phpunit配合得非常好

我的phpunit.xml引用的引导是:

<?xml version="1.0" encoding="UTF-8"?>
<phpunit colors="true" bootstrap="../../modules/unittest/bootstrap.php">
    <testsuites>
        <testsuite name="Kohana Tests">
            <directory>./</directory>
        </testsuite>
    </testsuites>
</phpunit>

./
另外,对于REMOTE_ADDR问题,当phpunit运行PHP的CLI版本时,我认为它没有访问REMOTE_ADDR变量的权限。如果查看unittest中的引导,它不会使用http相关的全局变量


我不知道为什么必须在引导程序中运行Request::factory代码。在我的香草3.2安装中,Request::factory代码位于index.php中,而不是bootstrap.php中,并且没有对superss请求的任何引用。您可能有一些3.2版本之前安装的文件需要清理。

谢谢,您说得对,这确实是问题所在。我遵循的是一个教程,其中提到指向index.php(这实际上就是我的Request::factory所在的位置——如果不清楚的话,很抱歉)。将它指向测试引导解决了问题!