Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

chris-lw's avatar

Parallel Testing with Bitbucket Pipelines

I'm interested to know if anyone has managed to get parallel testing working with bitbucket pipelines at all.

I have added the following line to bitbucket-pipelines.yml script instead of the usual vendor/bin/phpunit -

- php artisan test --parallel --coverage-clover coverage.xml

The multiple databases are built as excepted but i'm getting access denied errors on all tests when the tests start to run. Errors such as -

SQLSTATE[42000]: Syntax error or access violation: 1044 Access denied for user 'pipelines'@'%' to database 'test_db_test_4'

My MySQL service is configured like as below. This works perfectly fine without --parallel

environment:
     MYSQL_DATABASE: test_db
     MYSQL_RANDOM_ROOT_PASSWORD: 'yes'
     MYSQL_USER: pipelines
     MYSQL_PASSWORD: secret

Any ideas how to ensure my pipelines user can access the parallel generated databases?

0 likes
2 replies
thery's avatar
thery
Best Answer
Level 2

Yeah I have just done it actually. You can run the mysql service of pipelines as root.

In bitbucket-pipelines.yml you can define your mysql service like:

      environment:
        MYSQL_DATABASE: 'pipelines'
        MYSQL_ROOT_PASSWORD: 'let_me_in'

For the Laravel side, update your .env.build to use root: e,g .env.build

DB_USERNAME=root
DB_PASSWORD=let_me_in

And/Or update your database config for use different credentials for tests or dedicated db connection:

config/database file:

'connections' => [
	'testing_db' => [
		    'username' => env('DB_TESTS_USERNAME', 'root'),
            'password' => env('DB_TESTS_PASSWORD', 'let_me_in'),
			// ... plus any other setting that may be different like db names, etc..
	]
]
chris-lw's avatar

Thanks this worked a treat. I didn't think to run the tests as root. That makes way more sense. Cheers.

Please or to participate in this conversation.