Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3316322
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:27:21+00:00 2026-05-17T22:27:21+00:00

Situation We’re using PHPUnit in our project and are using a phpunit.xml to ensure

  • 0

Situation

We’re using PHPUnit in our project and are using a phpunit.xml to ensure things like backupGlobals is turned off.

To further ensure the include path is set and autoloading is active, we also cascade our test bootstraps. That is to say, every test and alltests-suite has a require_once(__DIR__ . '/../bootstrap.php'); at the top, all the way up to the base folder level, where it obviously reads require_once(__DIR__ . '/bootstrap.php');, and the actual bootstrap file resides.

Essentially, our tests are autonomous. You can call any AllTests.php in any folder and any *Test.php by itself and they’ll run with the right configuration.

Except no. ‘Wait a moment.‘

That’s only true if we either force our developers to use phpunit --configuration=path/to/phpunit.xml or they’re in the folder with the phpunit.xml (so that PHPUnit pulls it out of the current working directory when it is executed).

Occasionally, this makes it incredibly hard to determine why tests on one developer’s machine are breaking and why they’re running on another. It just takes forgetting that the bootstrap is not the only thing we need to have the same test environment. Keep in mind that since you couldn’t forget the bootstrap if you tried, because it’s in the tests themselves, forgetting other settings, especially usually-optional ones like that (if you’re in the folder with the phpunit.xml, it’s automatically pulled), is easy.

In fact – it’s happened a few times.

Question

Is there a way I can supply which phpunit.xml to use in the test file being run, such as in our conveniently ubiquitous bootstrap file, rather than supplying it to PHPUnit beforehand, be that by command-line switch or by being in its directory ?

A cursory glance at the code suggests the answer is no – configuration well and truly seems to be loaded before test files are even pulled:

[PHPUnit/TextUI/Command.php]
...
if (isset($this->arguments['configuration'])) {
    $configuration = PHPUnit_Util_Configuration::getInstance(
        $this->arguments['configuration']
    );
    $phpunit = $configuration->getPHPUnitConfiguration();
    ...

That does make some sense, given that the configuration can contain test white- or blacklists.

Really, it wouldn’t make sense to load test filters in the test bootstrap itself, so that’s half the potential configuration out the window with, but the actual behavioural flags of PHPUnit…

[sample of part of our phpunit.xml]
<phpunit
    backupGlobals="false" 
    backupStaticAttributes="false" 
    convertErrorsToExceptions="true"  
    convertNoticesToExceptions="true"
    convertWarningsToExceptions="true"
    syntaxCheck="false"
    processIsolation="false"
    colors="true">

…perhaps with the exception of ‘colors’ strikes me as something that the test itself should be able to decide on some level.

Consolation prize for…

Admittedly, right now I’d be happy just knowing if I can teach PHPUnit backupGlobals="false" from the bootstrap file, if someone knows of a way.

(If fruitless, the practical answer I’ll pursue will probably be to copy the phpunit.xml into all subfolders. I’d like to avoid that solution since it creates redundant copies, and if we ever choose to change a setting… yeah, ouch!)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T22:27:22+00:00Added an answer on May 17, 2026 at 10:27 pm

    Direct answer: No, you can’t do that.

    Longer story – this kind of problem is better solved by changing the habits of developers.

    Here is we do it:

    • All developers always run the tests from the tests root directory, which has the sole phpunit.xml with all the necessary configuration – including bootstrap, which sets up an class autoloader.
    • We don’t have testsuites as such, tests are grouped using directories, no AllTests.php anywhere, because its not necessary. PHPUnit can take a name of directory and run all tests inside it.
    • Its still possible to run any single test by giving a path to it or whole testsuite (by giving path to the directory). It just has to be done from the tests root directory all the time or it won’t work.

    Doing it like this means giving up the freedom of starting PHPUnit from any directory, but to be honest – I don’t feel like that’s a loss at all.

    The gains are much bigger: the amount of housekeeping code is reduced, developers cannot forget anything and results are therefore consistent.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The situation is like this : Main project A. and a class library B.
Situation: I have a simple XML document that contains image information. I need to
The situation: I have a pieceofcrapuous laptop. One of the things that make it
Situation: Classic ASP application, using a custom Application Pool. Default settings. On some IIS7
Situation I'm using matchbox keyboard which is X11 based application. When any application is
Situation is a string that results in something like this: <p>This is some text
Situation I'm creating a C#/WPF 4 application using a SQL Compact Edition database as
Simple situation. I have a list of lists, almost table like, and I am
Situation: Got 160 ids in array, need to build xml requests, in sets of
Situation: A PHP application with multiple installable modules creates a new table in database

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.