Symfony和PHPUnit与Bitbucket管道
我正在尝试设置一个管道,以便使用Bitbucket自动执行我的测试套件 不幸的是,我对Docker和pipelines完全陌生。我阅读了大量的尝试和错误之后我想出了这个Symfony和PHPUnit与Bitbucket管道,php,symfony,phpunit,bitbucket,bitbucket-pipelines,Php,Symfony,Phpunit,Bitbucket,Bitbucket Pipelines,我正在尝试设置一个管道,以便使用Bitbucket自动执行我的测试套件 不幸的是,我对Docker和pipelines完全陌生。我阅读了大量的尝试和错误之后我想出了这个比特桶管道。yml配置: image: php:7.2.17 pipelines: default: - step: caches: - composer script: - apt-get update && apt-get i
比特桶管道。yml
配置:
image: php:7.2.17
pipelines:
default:
- step:
caches:
- composer
script:
- apt-get update && apt-get install -y unzip zlib1g-dev sqlite3 libsqlite3-dev
- docker-php-ext-install zip && docker-php-ext-install pdo_sqlite && docker-php-ext-install pdo_mysql
- curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
- composer install
- vendor/bin/simple-phpunit
问题是此配置仍显示错误:
[RuntimeException]
An error occurred when executing the "'cache:clear --no-warmup'" command:
In ConnectionFactory.php line 79:
An exception occured while establishing a connection to figure out your pla
tform version.
You can circumvent this by setting a 'server_version' configuration value
For further information have a look at:
https://github.com/doctrine/DoctrineBundle/issues/673
In AbstractMySQLDriver.php line 93:
An exception occurred in driver: SQLSTATE[HY000] [2002] Connection refused
In PDOConnection.php line 31:
SQLSTATE[HY000] [2002] Connection refused
In PDOConnection.php line 27:
SQLSTATE[HY000] [2002] Connection refused
为什么它试图使用MySQL进行连接?它不应该只执行测试吗?我不需要运行项目或部署版本,我只需要使用SQLite和单元测试执行测试套件。条令试图猜测您的MySQL/PostgreSQL版本。因此,在创建适配器时,它会尝试建立到数据库的连接 可以通过在配置中配置具体版本来避免这种行为
# config.yaml
doctrine:
dbal:
# [..]
server_version: '5.7' # or mariadb-<version> for MariaDB
#config.yaml
教条:
dbal:
# [..]
服务器版本:“5.7”或mariadb-用于mariadb
有关此“问题”的更多信息,请参见文档一章中配置概述下方的通知
只需将
server\u version
添加到config\u test.yaml
即可解决您的问题。请参见此示例:
# This is a sample build configuration for PHP.
# Check our guides at https://confluence.atlassian.com/x/e8YWN for more examples.
# Only use spaces to indent your .yml configuration.
# -----
# You can specify a custom docker image from Docker Hub as your build environment.
image: medtrainermx/php:5.6
pipelines:
branches:
'**':
- step:
name: "Build"
caches:
- composer
script:
- cp symfony/app/config/local.yml.dist symfony/app/config/local.yml
- cp symfony/tests/config.local.php.dist symfony/tests/config.local.php
- cd symfony/tests
- composer install
artifacts:
- build/**
- symfony/vendor/**
- symfony/app/config/local.yml
- symfony/app/cache/**
- symfony/tests/vendor/**
- symfony/tests/config.local.php
- step:
name: "Coding Standards"
caches:
- composer
script:
- cd symfony
- mkdir app/cache
- ./bin/phpcs --cache=app/cache/.phpcs-cache
- step:
name: "Unit Tests"
services:
- mysql
caches:
- composer
script:
- cd symfony
- ./bin/phpunit --testsuite=unit --debug
definitions:
services:
mysql:
image: mysql:5.7
environment:
MYSQL_DATABASE: 'test'
MYSQL_ROOT_PASSWORD: 'password'
在此配置中,我使用自己的映像在bitbucket管道中使用