Take the 2-minute tour ×

I need a way to determine if the person calling the function is Travis-CI or not. If it is Travis-CI, I do not want to start a session here. Right now, I have my tests script create a file called test.txt and then look for it.

protected function __construct() {
    if ( (!session_id()) && (!file_exists('test.txt' ))) session_start();

However, there has to be a better way. It seems, that without the file check, if there is in fact a session made, a new one will not be created. But this is not the case. If this was the case, the before link below should have passed.

Before the addition of the "test.txt" file:

share|improve this question
Systems that explicitly change their behaviour when being tested are not being tested properly. –  paxdiablo Oct 19 '12 at 22:14
@paxdiablo Not really. The issue at hand is that to test my wp plugin, we use a dependency which starts the session. Unfortunately, I can't turn that off. –  chriscct7 Oct 19 '12 at 22:17

2 Answers 2

In general you can detect if you are on Travis-CI by checking the environment variables. You can check either for CI=true or the more specific TRAVIS=true. In PHP you can use the getenv() function to get the value of an environment variable.

See the complete list of the environment. You can set even more env variables in your .travis.yml.

share|improve this answer
up vote -1 down vote accepted

As I should have thought about earlier, Instead of making a file, I now save a session field, and then check for it later.

share|improve this answer

Your Answer


