Are you missing a MYSQL_HOST?
Apr 23, 2021
7
Level 54
Tests fail in pipelines
I've been setting up my current laravel 8 project with a pipeline to run tests on bitbucket before publishing to my live server.
My application is able to migrate and seed data ok but when I run the php artisan test step I get failures for the feature tests.
A typical feature test looks like:
/** @test */
public function gets_list_of_activities(): void
{
$response = $this->get('/api/v1/activities');
$response
->assertSuccessful();
}
and the failure message is
SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known
and full bitbucket pipeline
image: php:7.4-fpm
pipelines:
branches:
'{develop,feature/*}':
- step:
name: Run tests and deploy to dev
deployment: test
caches:
- composer
services:
- mysql
artifacts: # defining the artifacts to be passed to each future step.
- storage/logs/*.log
- reports/*.txt
after-script:
- find /opt/atlassian/pipelines/agent/build/ -name *laravel*.log
script:
- echo "master, dev, or feature/*"
- mkdir /usr/share/man/man1/
- apt-get update && apt-get install -qy git zip curl libmcrypt-dev default-mysql-client libxml2-dev default-jre wget maven
# - yes | pecl install mcrypt-1.0.1
- docker-php-ext-install pdo_mysql bcmath
- curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
- composer install
- ln -f -s .env.pipelines .env
- php artisan optimize:clear
- php artisan migrate:fresh
- php artisan db:seed
- php artisan serve &
- sleep 5
- php artisan test
definitions:
services:
mysql:
image: mysql:5.7
command: --max_allowed_packet=100M
environment:
MYSQL_DATABASE: 'homestead'
MYSQL_RANDOM_ROOT_PASSWORD: 'yes'
MYSQL_USER: 'homestead'
MYSQL_PASSWORD: 'secret'
Does anyone know what I should do with DNS so phpunit can access the application?
Please or to participate in this conversation.