Laravel Github 操作 CI/CD 、 SQLSTATE[HY000] [2002] 连接被拒绝(SQL:创建表 `migrations`
我想通过我的 yml 文件运行我的单元测试,但它们失败了,因为它们必须在 Mysql 上运行,
我认为缺少一些东西。
这是 yaml 文件:
steps:
- uses: shivammathur/setup-php@15c43e89cdef867065b0213be354c2841860869e
with:
php-version: '7.4|8.0'
- uses: actions/checkout@v2
- name: Copy .env
run: php -r "file_exists('.env') || copy('.env.example', '.env');"
- name: Install Dependencies
run: composer install --no-progress --prefer-dist --optimize-autoloader
- name: Generate key
run: php artisan key:generate
- name: Directory Permissions
run: chmod -R 777 storage bootstrap/cache
- name: Optimize Project
run: php artisan optimize:clear
- name: Execute tests (Unit and Feature tests) via PHPUnit
env:
DB_CONNECTION: mysql
DB_HOST: 127.0.0.1
DB_PORT: 3306
DB_DATABASE: database_name
DB_USERNAME: root
DB_PASSWORD:
run: |
php artisan migrate
php artisan test
这是 phpunit.xml 文件:
<server name="APP_ENV" value="testing"/>
<server name="BCRYPT_ROUNDS" value="4"/>
<server name="CACHE_DRIVER" value="array"/>
<!-- <server name="DB_CONNECTION" value="sqlite"/> -->
<!-- <server name="DB_DATABASE" value=":memory:"/> -->
<server name="MAIL_MAILER" value="array"/>
<server name="QUEUE_CONNECTION" value="sync"/>
<server name="SESSION_DRIVER" value="array"/>
<server name="TELESCOPE_ENABLED" value="false"/>
I want to run my unit tests through my yml file, but they fail because they must be run on Mysql
I think something is missing.
here is yaml file:
steps:
- uses: shivammathur/setup-php@15c43e89cdef867065b0213be354c2841860869e
with:
php-version: '7.4|8.0'
- uses: actions/checkout@v2
- name: Copy .env
run: php -r "file_exists('.env') || copy('.env.example', '.env');"
- name: Install Dependencies
run: composer install --no-progress --prefer-dist --optimize-autoloader
- name: Generate key
run: php artisan key:generate
- name: Directory Permissions
run: chmod -R 777 storage bootstrap/cache
- name: Optimize Project
run: php artisan optimize:clear
- name: Execute tests (Unit and Feature tests) via PHPUnit
env:
DB_CONNECTION: mysql
DB_HOST: 127.0.0.1
DB_PORT: 3306
DB_DATABASE: database_name
DB_USERNAME: root
DB_PASSWORD:
run: |
php artisan migrate
php artisan test
and here is phpunit.xml file:
<server name="APP_ENV" value="testing"/>
<server name="BCRYPT_ROUNDS" value="4"/>
<server name="CACHE_DRIVER" value="array"/>
<!-- <server name="DB_CONNECTION" value="sqlite"/> -->
<!-- <server name="DB_DATABASE" value=":memory:"/> -->
<server name="MAIL_MAILER" value="array"/>
<server name="QUEUE_CONNECTION" value="sync"/>
<server name="SESSION_DRIVER" value="array"/>
<server name="TELESCOPE_ENABLED" value="false"/>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此示例显示 将 MySQL 添加到 GitHub 操作中的示例,以便数据库可用:
您的 GitHub 操作 yaml 需要
services
部分:您可以使用 GH 操作设置
env
命令那个需要数据库访问权限可以包括:您可能需要查看 Chipper CI,它为您完成了很多测试 Laravel 应用程序的工作!
This example shows an example of adding MySQL into into your GitHub action, so the database is available:
Your GitHub actions yaml needs a
services
section:The
env
you can set with your GH Actions command that needs database access can include:You may want to check out Chipper CI, which does a lot of this work for you for testing Laravel apps!