1

I have a series of PHPUnit tests that will need to connect to a database. I would like to avoid hardcoding a specific database/username/password into each unit test. How can they share this information?

Right now I am setting these as key/value pairs in the $GLOBALS array in my PHPUnit bootstrap file. Should they be somewhere else?

2 Answers 2

2

you can put them in the %ENV

export DB_PASS=foo
export DB_HOST=127.0.0.1
export DB_USER=bar

or you can have a config file outside of your repository.

Sign up to request clarification or add additional context in comments.

Comments

2

$GLOBALS is quite dirty. You could use constants or derive the unit tests from a class that has the connection data as properties.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.