CakePHP 项目 travis MySQL 5.7

CakePHP project travis MySQL 5.7

我正在尝试使用 travis 设置我的项目以检查 MySQL 5.7

我的.travis.yml如下

language: php

dist: trusty

sudo: false

php:
  - 5.6
  - 7.0
  - 7.1

env:
  - DB=mysql db_dsn='mysql://root@127.0.0.1/cakephp_test'

services:
  - mysql
  - docker

matrix:
  fast_finish: true


before_install:
  - sudo service mysql stop || sudo service mysql-5.6 stop || sudo stop mysql-5.6 || sudo stop mysql || echo "failed to stop mysql"
  - sudo docker run -d -p 3306:3306 mysql:5.7
  - mysql -u root -e "CREATE DATABASE cakephp_test;"

before_script:
  - composer install;
  - composer require phpunit/phpunit:"^5.7|^6.0";
  - composer run-script post-install-cmd --no-interaction;

script:
  - vendor/bin/phpunit;

notifications:
  email: false

似乎没有 docker 我无法使用 MySQL 5.7,但使用此设置我无法连接到 MySQL 服务器。

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

我错过了什么?

经过一些研究和尝试,我找到了问题的答案。

这里是要点:https://gist.github.com/rrd108/d366cca7feb33825e6989ba3fad049de

.travis.yml 中,我不得不更改一些内容。

language: php

dist: trusty

sudo: true

php:
  - 5.6
  - 7.0
  - 7.1

env:
  - DB=mysql db_dsn='mysql://root@127.0.0.1/cakephp_test'

services:
  - mysql

matrix:
  fast_finish: true

before_script:
  - bash .travis.install-mysql-5.7.sh
  - mysql -u root -e "CREATE DATABASE cakephp_test;"
  - composer update;
  - composer run-script post-install-cmd --no-interaction;

script:
  - vendor/bin/phpunit;

notifications:
  email: false

我需要一个 .travis.install-mysql-5.7.sh 文件

echo mysql-apt-config mysql-apt-config/select-server select mysql-5.7 | sudo debconf-set-selections
wget https://dev.mysql.com/get/mysql-apt-config_0.7.3-1_all.deb
sudo dpkg --install mysql-apt-config_0.7.3-1_all.deb
sudo apt-get update -q
sudo apt-get install -q -y --allow-unauthenticated -o Dpkg::Options::=--force-confnew mysql-server
sudo mysql_upgrade

而且我不得不在 Datasources

更改我的 config/app.default.php
'test' => [
            'className' => 'Cake\Database\Connection',
            'driver' => 'Cake\Database\Driver\Mysql',
            'persistent' => false,
            'host' => 'localhost',
            //'port' => 'non_standard_port_number',
            'username' => 'root',
            'password' => '',
            'database' => 'cakephp_test',
            'encoding' => 'utf8',
            'timezone' => 'UTC',
            'cacheMetadata' => true,
            'quoteIdentifiers' => false,
            'log' => false,
            //'init' => ['SET GLOBAL innodb_stats_on_metadata = 0'],
            'url' => env('DATABASE_TEST_URL', null),
        ],

因为我想针对 php 5.6 进行测试,所以我应该在我的 composer.json 中使用 php 单元,像这样

 "phpunit/phpunit": "^5.7|^6.0"