Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/246.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测试中正确启动PHPCLI脚本?_Php_Phpunit_Command Line Interface - Fatal编程技术网

如何在phpunit测试中正确启动PHPCLI脚本?

如何在phpunit测试中正确启动PHPCLI脚本?,php,phpunit,command-line-interface,Php,Phpunit,Command Line Interface,我需要测试一些使用stdout、stderr和返回错误代码的PHPCLI脚本 似乎它没有返回stderr 不返回标准输出(仅最后一行),标准输出 可以使用proc\u open 文件:script.php echo 'Standart output'; //stdout error_log('Error output'); //stderr exit(1); //return 文件:test.php <?php $descriptorspec = array( 1 =&g

我需要测试一些使用stdout、stderr和返回错误代码的PHPCLI脚本

  • 似乎它没有返回stderr
  • 不返回标准输出(仅最后一行),标准输出

可以使用proc\u open

文件:script.php
echo 'Standart output'; //stdout

error_log('Error output'); //stderr

exit(1); //return
文件:test.php

<?php

$descriptorspec = array(
    1 => array("pipe", "w"), // stdout is a pipe that the child will write to
    2 => array("pipe", "w") // stderr is a pipe that the child will write to
);

$process = proc_open('php script.php', $descriptorspec, $pipes);
if (is_resource($process))
    {
    echo 'stdout: ' . stream_get_contents($pipes[1]) . PHP_EOL;
    fclose($pipes[1]);

    echo 'stderr: ' . stream_get_contents($pipes[2]) . PHP_EOL;
    fclose($pipes[2]);

    $return_value = proc_close($process);
    echo 'return: ' . $return_value . PHP_EOL;
    }
那我就给你提建议。不过有点笨拙:)重复的?