如何在Vagrant上使用数据库进行Codeception测试 [英] How to use database on Vagrant for testing with Codeception

查看:84
本文介绍了如何在Vagrant上使用数据库进行Codeception测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Vagrant和Codception,但是当我想测试本地应用程序时,必须在LAMP(或类似的服务器)服务器上进行测试。如何在Vagrant上使用数据库?

I use Vagrant and Codception, but when i want to test application localy, I must do it on LAMP (or something like that) server. How can I use database on Vagrant?

推荐答案

您所需要做的只是设置对主机上来宾计算机(无用盒)上运行的mysql服务器的访问权限然后在您的codeception.yml配置中设置适当的数据库DNS。

All you need is just to setup access to your mysql server that runs on the guest machine (vagrant box) from the host and then to set appropriate database DNS in your codeception.yml config.

以下是一些常规说明:

1)允许您的无业游民的mysql服务器通过在mysql的my.cnf配置中设置'bind-address'选项并将其值更改为0.0.0.0来将所有ssh监听到您的盒子

1) Allow your vagrant's mysql server listen all interfaces ssh to your box by setting 'bind-address' option in mysql's my.cnf config and change it's value to 0.0.0.0

2)向mysql用户授予适当的特权,该特权将用于从主机连接到数据库。
您可以使用mysql客户端按照以下SQL命令运行此操作

2) Grant appropriate privileges to mysql user that will be used to connect to database from the host. You can do this running following SQL commands using mysql client

USE mysql;  
GRANT ALL ON *.* to root@'192.168.0.1' IDENTIFIED BY 'mypass';  
FLUSH PRIVILEGES;

其中 root mypass -您的数据库从代码接收开始将用于连接数据库及其密码和 192.168.0.1 的用户-主机的ip(了解如何为您的gest 此处

where root and mypass - your database user which will be used from codeception to connect to database and its password and 192.168.0.1 - the ip of the host (read how get host's ip for your gest here)

3 )重新启动vagrant的mysql服务器

3) Restart vagrant's mysql server

4)要测试从主机运行到vagrant的mysql的连接

4) To test connection to vagrant's mysql from the host run

mysql -h 192.168.33.10 -P 3306  -u root -p

(这里 192.168.33.10 -我正在运行的无聊的盒子的IP)

(Here 192.168.33.10 - ip of my running vagrant box)

5)在codeception.yml中设置DNS文件,例如

5) Set up DNS in codeception.yml file, e.g.

modules:
    config:
        Db:
            dsn: 'mysql:host=192.168.33.10;dbname=MyDB'
            user: 'root'
            password: 'mypass'

这篇关于如何在Vagrant上使用数据库进行Codeception测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆