dongqi8863 2017-10-07 20:28
浏览 81

Laravel测试 - 迁移/刷新错误的环境

Laravel v5.5.14
PHPUnit v6.4.1

I have a Laravel application with a number of feature tests. My base TestCase uses the RefreshDatabase trait for triggering a DB refresh before each test, and the env variables in my phpunit.xml looks like so;

<php>
    <env name="APP_ENV" value="testing"/>
    <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"/>
</php>

The intention being to leave the development mysql DB connection alone and run the tests using sqlite in memory. Despite these settings (and clearing cached config etc) the DB refresh always refreshes the mysql connection DB.

I've looked into the functionality within RefreshDatabase and debugged the refreshDatabase method, which contians;

$this->usingInMemoryDatabase()
                        ? $this->refreshInMemoryDatabase()
                        : $this->refreshTestDatabase();

And usingInMemoryDatabase always returns false. Looking at the content of that method, when retrieving the DB_CONNECTION from config it always returns mysql, even though it should be being overridden by the env variable above.

What is going on here?

  • 写回答

1条回答 默认 最新

  • dongseshu0698 2018-02-07 02:59
    关注

    Run php artisan config:clear before running the tests to clear the cache to make sure the config variables are not cached from a wrong environment. If this doesn't help run PHPUnit using your IDE (e.g PHPStorm) and specifically select your project phpunit.xml

    enter image description here

    评论

报告相同问题?

悬赏问题

  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图2.0 版本点聚合中Marker的位置无法实时更新,如何解决呢?
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题