StockBreak
StockBreak

Reputation: 2885

Symfony and PHPUnit with Bitbucket pipelines

I am trying to set up a pipeline to automatically execute my test suite using Bitbucket.

Unfortunately I am completely new to Docker and pipelines. I read this article and after a lot of trial and errors I came up with this bitbucket-pipelines.yml configuration:

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

The problem is that this configuration still displays an error:

  [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 

Why is it trying to connect using MySQL? Shouldn't it be executing tests only? I don't need the project running or a deployable version, I just need the test suite executed using SQLite and unit tests.

Upvotes: 2

Views: 3282

Answers (2)

Ricardo Jesus Ruiz
Ricardo Jesus Ruiz

Reputation: 135

See this example please:

# 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'

in this configuration i use my own image to uses in bitbucket pipeline

Upvotes: 0

Nicolai Fröhlich
Nicolai Fröhlich

Reputation: 52513

Doctrine tries to guess your MySQL/PostgreSQL version. It therefore tries to establish a connection to the database when creating the adapter.

This behavior can be circumvented by configuring a concrete version in your configuration.

# config.yaml

doctrine:
  dbal:
    # [..]
    server_version: '5.7' # or mariadb-<version> for MariaDB

You can find more information about this "issue" in the notice below the configuration overview in the documentation chapter Doctrine DBAL Configuration.

Just add server_version to config_test.yaml to resolve your issue.

Upvotes: 1

Related Questions