CircleCI got same environment which is “default”

circle.yml

#1

I want to use a different environment mainly because of the database connection. So we have got two environments.

First one is “default” and it is used in phpunit tests on my local machine (they don’t currently work) Second one is “test” which when I set it on my local machine, everything works out.

This is what I got inside the code:

    if (Configure::read('environment') != 'live') {
    ConnectionManager::alias(Configure::read('environment'), 'default');
}

This means that since it’s not live, the environment is “default”.
How could I change this from the circle.yml ?

How could I do this ?


#2

Maybe you can share parts of your circle.yml showing how you set your environment variables?

It is just a wild guess of mine, but this might be related to the case. Generally env variables are uppercase, so that you have to specify in circle.yml and (probably) your code something like:

  environment:
    ENVIRONMENT: test

#3

Yeah sure.
Maybe the suggested will work.
In the meantime here is my circle.yml:
machine:
php:
version: 7.0.11

database:
override:
- mysql -u ubuntu circle_test < /home/ubuntu/cemcloud2/config/schema/circle_test.sql

dependencies:
cache_directories:
- vendor

pre:
- sudo apt-get update
- curl -s https://packagecloud.io/install/repositories/circleci/trusty/script.deb.sh | sudo bash
- sudo apt-get install circleci-php-7.0.4=1
- sudo apt-get install nginx
- sed ‘3 a server {\n\tlocation ~ .php$ {\n\t\tfastcgi_param APPLICATION_ENV test;\n\t}\n}’ /etc/nginx/nginx.conf
- sudo apt-get install python-software-properties
- curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
- sudo apt-get install nodejs

# getting selenium
- wget http://selenium-release.storage.googleapis.com/2.47/selenium-server-standalone-2.47.1.jar
- 'java -jar selenium-server-standalone-2.47.1.jar > /dev/null 2>&1':
      background: true

# start the web server
- 'php app/console server:run --env=test -vvv localhost:8080 > server.log 2>&1':
      background: true

test:
pre:
- mkdir behat_screenshots
- chmod 777 behat_screenshots
- export BEHAT_SCREENSHOTS="1"
post:
# add a file so that the directory isn’t empty (else copy will fail)
- touch behat_screenshots/keep
- cp behat_screenshots/* $CIRCLE_ARTIFACTS/
- rm $CIRCLE_ARTIFACTS/keep
override:
- chmod 777 -R /home/ubuntu/cemcloud2
- cd /home/ubuntu/cemcloud2 && bin/behat
- mkdir -p $CIRCLE_TEST_REPORTS/phpunit
- phpunit --coverage-html $CIRCLE_TEST_REPORTS/coverage
- mkdir -p $CIRCLE_TEST_REPORTS/jasmine
- /home/ubuntu/cemclooud2/webroot/assets/jasmine-2.5.2/SpecRunner.html
- $CIRCLE_TEST_REPORTS/home/ubuntu/cemclooud2/webroot/assets/jasmine-2.5.2/SpecRunner.html


#4

Of course, this all is indented correctly.


#5

Try adding

environment:
    ENVIRONMENT: test

in machine block. It is better to move BEHAT_SCREENSHOTS there too.


#6

Hey,
This is what I got in my circle.yml

And still this is what I got from circleCi machine


And this is what I got from my local machine

This means that the solution you proposed doesn’t work in either cases.

Or am I doing something wrong ?


#7