我有一个泊坞测试数据库,该数据库已启动并正在运行,“已准备好进行连接”:
testdb:
image: mysql:5.7
restart: always
container_name: ufr-mysql-test
environment:
MYSQL_DATABASE: workit_test
MYSQL_USER: local
MYSQL_PASSWORD: local
MYSQL_ROOT_PASSWORD: admin
ports:
- "3307:3306"
tmpfs: /var/lib/mysql
我可以很好地连接到Sequel Pro。我的.env.testing文件:
DB_CONNECTION=mysql
DB_DATABASE=workit_test
DB_HOST=ufr-mysql-test
DB_PORT=3307
DB_USERNAME=local
DB_PASSWORD=local
我知道我在测试文件中正确运行了phpunit,因为我刚刚克服了另一个问题,可以config('app.env');
在测试中转储“测试”,但是当我击中Doctrine\DBAL\Driver\PDOException: SQLSTATE[HY000] [2002] Connection refused
时在我的应用容器中运行vendor/bin/phpunit
。我在这里想念什么吗?如果我在应用容器中运行php artisan migrate --env=testing
,则会得到SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = workit_test and table_name = migrations and table_type = 'BASE TABLE').
。我正在手动清除bootstrap/cache/
中的缓存文件(这解决了phpunit在本地环境中运行而不是在测试中运行的问题)并且已经运行source .env.testing
。