Laravel 从Artisan命令调用PHPUnit将忽略XML文件

Laravel 从Artisan命令调用PHPUnit将忽略XML文件,laravel,testing,laravel-5,phpunit,laravel-artisan,Laravel,Testing,Laravel 5,Phpunit,Laravel Artisan,我有一个我认为不常见的问题,但我会尽量解释清楚。我已经创建了一个简单的artisan命令来执行此操作 /** * Execute the console command. */ public function handle() { $this->info("==> Cleaning up reports and docs..."); $command = new Process("rm -f tests/docs/* && rm -rf tes

我有一个我认为不常见的问题,但我会尽量解释清楚。我已经创建了一个简单的artisan命令来执行此操作

 /**
 * Execute the console command.
 */
public function handle()
{
    $this->info("==> Cleaning up reports and docs...");

    $command = new Process("rm -f tests/docs/* && rm -rf test/reports/*");
    $command->run();

    $this->warn("==> Reports and docs are clean");

    $this->info("==> Executing Tests Suite...");
    $command = new Process("vendor/bin/phpunit --coverage-html tests/reports --testdox-html tests/docs/reports.html -v --debug");
    $command->run();
    $this->info($command->getIncrementalOutput());

    $this->warn("==> report generated >> test/reports. Documentation generated >> test/docs/reports.html");
}
这看起来有点奇怪,但实际上非常有用,它启动了PHPUnit,提供了覆盖支持和其他功能。问题是,如果我像
php artisan ludo237:full test那样运行此命令,它将完全忽略
phpunit.xml
,实际上它将显示并错误地说MySQL数据库不存在,尽管我在我的
phpunit.xml
中设置了sqlite连接,但您可以清楚地看到这是正确的:

<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
         backupStaticAttributes="false"
         bootstrap="bootstrap/autoload.php"
         colors="true"
         convertErrorsToExceptions="true"
         convertNoticesToExceptions="true"
         convertWarningsToExceptions="true"
         processIsolation="false"
         stopOnFailure="false">
    <testsuites>
        <testsuite name="Application Test Suite">
            <directory suffix="Test.php">./tests</directory>
        </testsuite>
    </testsuites>
    <filter>
        <whitelist processUncoveredFilesFromWhitelist="true">
            <directory suffix=".php">./app</directory>
        </whitelist>
    </filter>
    <php>
        <env name="APP_ENV" value="testing"/>
        <env name="APP_DEBUG" value="true"/>
        <env name="APP_URL" value="http://localhost:8000"/>
        <env name="DB_CONNECTION" value="sqlite"/>
        <env name="DB_DATABASE" value=":memory:" />
        <env name="CACHE_DRIVER" value="array"/>
        <env name="SESSION_DRIVER" value="array"/>
        <env name="QUEUE_DRIVER" value="sync"/>
        <env name="MAIL_DRIVER" value="log"/>
        <env name="MAIL_PRETEND" value="true"/>
    </php>
</phpunit>

/测试
/应用
我知道我可以简单地为该命令行创建一个bash别名,事实上这是我当前的热修复程序,但在这一点上,我只是想了解为什么当我从artisan命令启动phpunit命令时,它会忽略XML文件


有人对此有线索吗?谢谢大家!

我花了很多时间调试它,但最终我发现了它不起作用的原因

首先,让我澄清一下,您的代码没有问题,即使
进程
类没有问题,您也会得到相同的行为,即使使用本机
exec
函数

其次,
phpunit.xml
文件完全被读取,没有任何问题

也就是说,真正的问题在于PHPUnit,它不允许您重新定义(或重写)任何env变量,因为

这是因为Laravel没有解析
phpunit.xml
文件本身,而在您调用它的那一刻,已经太晚了,或者通过
putenv
$\u服务器
和/或
$\u ENV

正因为如此,即使在最新版本中(截至今天),这个问题仍然存在,即使这样

不幸的是,我还没有为您提供解决方案,但让我们交叉手指,等待PHPUnit添加建议的
force
属性:)

致以最良好的祝愿,
朱利安

谢谢你的努力。让我们看看这个问题是否会有更新