【问题标题】:Laravel/Phpunit: is it possible to force DB connection via terminal?Laravel/Phpunit:是否可以通过终端强制连接数据库?
【发布时间】:2019-07-07 04:11:17
【问题描述】:

我有一个 Laravel 项目。

我想用 SQLite 在我的开发机器 + Travis/Scrutinizer 上测试它,另外我想用 MySQL 在另一台机器上测试。

这是我的 PHPUnit 文件,工作起来就像一个魅力

<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
         backupStaticAttributes="false"
         bootstrap="vendor/autoload.php"
         colors="true"
         convertErrorsToExceptions="true"
         convertNoticesToExceptions="true"
         convertWarningsToExceptions="true"
         processIsolation="false"
         stopOnFailure="false">
    <testsuites>
        <testsuite name="Unit">
            <directory suffix="Test.php">./tests/Unit</directory>
        </testsuite>

        <testsuite name="Feature">
            <directory suffix="Test.php">./tests/Feature</directory>
        </testsuite>
    </testsuites>
    <filter>
        <whitelist processUncoveredFilesFromWhitelist="true">
            <directory suffix=".php">./app</directory>
        </whitelist>
    </filter>
    <logging>
        <!-- and this is where your report will be written -->
        <log type="coverage-clover" target="./logs/clover.xml"/>
    </logging>
    <php>
        <env name="DB_CONNECTION" value="sqlite"/>
        <env name="APP_ENV" value="testing"/>
        <env name="BCRYPT_ROUNDS" value="4"/>
        <env name="CACHE_DRIVER" value="array"/>
        <env name="MAIL_DRIVER" value="array"/>
        <env name="QUEUE_CONNECTION" value="sync"/>
        <env name="SESSION_DRIVER" value="array"/>
    </php>
</phpunit>

我在问:是否有可能在 linux shell 命令上启动类似的命令(当然是伪代码):

./vendor/bin/phpunit --db_connection=mysql

【问题讨论】:

    标签: laravel phpunit


    【解决方案1】:

    默认情况下无法从命令行动态编辑phpunit.xml文件,但您可以像这样设置DB_CONNECTION环境变量(和其他变量):

    DB_CONNECTION=mysql ./vendor/bin/phpunit

    您可以在this答案中查看更多设置环境变量的选项。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-12-12
      • 2012-07-29
      • 2012-01-08
      • 1970-01-01
      • 2017-11-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多