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 6892201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:30:18+00:00 2026-05-27T06:30:18+00:00

I am currently going to start from scratch with the phpunit tests for a

  • 0

I am currently going to start from scratch with the phpunit tests for a project. So I was looking into some projects (like Zend) to see how they are doing things and how they organizing their tests.

Most things are pretty clear, only thing I have some problems with is how to organize the test suites properly.
Zend has an AllTests.php from which loads others test suites.
Tough looking at the class it is useing PHPUnit_Framework_TestSuite to create a suite object and then add the other suites to it, but if I look in the PHPUnit docs for organizing tests in PHPUnit versions after 3.4 there is only a description for XML or FileHierarchy. The one using classes to organize the tests was removed.
I haven’t found anything that this method is deprecated and projects like Zend are still using it.

But if it is deprecated, how would I be able to organize tests in the same structure with the xml configuration? Executing all tests is no problem, but how would I organize the tests (in the xml) if I only wanted to execute a few tests. Maybe creating several xmls where I only specify a few tests/test suites to be run?

So if I would want to only test module1 and module2 of the application, would I have an extra xml for each and defining test suites only for those modules (classes used by the module) in it. And also one that defines a test suite for all tests?

Or would it be better to use the @group annotation on the specific tests to mark them to be for module1 or module2?

Thanks in advance for pointing me to some best practices.

  • 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-27T06:30:19+00:00Added an answer on May 27, 2026 at 6:30 am

    I’ll start of by linking to the manual and then going into what I’ve seen and heard in the field.

    Organizing phpunit test suites

    Module / Test folder organization in the file system

    My recommended approach is combining the file system with an xml config.

    tests/
     \ unit/
     | - module1
     | - module2
     - integration/
     - functional/
    

    with a phpunit.xml with a simple:

    <testsuites>
      <testsuite name="My whole project">
        <directory>tests</directory>
      </testsuite>
    </testsuites>
    

    you can split the testsuites if you want to but thats a project to project choice.

    Running phpunit will then execute ALL tests and running phpunit tests/unit/module1 will run all tests of module1.

    Organization of the "unit" folder

    The most common approach here is to mirror your source/ directory structure in your tests/unit/ folder structure.

    You have one TestClass per ProductionClass anyways so it’s a good approach in my book.

    In file organization

    • One class per file.

    It’s not going to work anyways if you have more than one test class in one file so avoid that pitfall.

    • Don’t have a test namespace

    It just makes writing the test more verbose as you need an additional use statement so I’d say the testClass should go in the same namespace as the production class but that is nothing PHPUnit forces you to do. I’ve just found it to be easier with no drawbacks.

    Executing only a few tests

    For example phpunit --filter Factory executes all FactoryTests while phpunit tests/unit/logger/ executes everything logging related.

    You can use @group tags for something like issue numbers, stories or something but for "modules" I’d use the folder layout.

    Multiple xml files

    It can be useful to create multiple xml files if you want to have:

    • one without code coverage
    • one just for the unit tests (but not for the functional or integration or long running tests)
    • other common "filter" cases
    • PHPBB3 for example does that for their phpunit.xmls

    Code coverage for your tests

    As it is related to starting a new project with tests:

    • My suggestion is to use @covers tags like described in my blog (Only for unit tests, always cover all non public functions, always use covers tags.
    • Don’t generate coverage for your integration tests. It gives you a false sense of security.
    • Always use whitelisting to include all of your production code so the numbers don’t lie to you!

    Autoloading and bootstrapping your tests

    You don’t need any sort of auto loading for your tests. PHPUnit will take care of that.

    Use the <phpunit bootstrap="file"> attribute to specify your test bootstrap. tests/bootstrap.php is a nice place to put it. There you can set up your applications autoloader and so on (or call your applications bootstrap for that matter).

    Summary

    • Use the xml configuration for pretty much everything
    • Seperate unit and integration tests
    • Your unit test folders should mirror your applications folder structure
    • To only execute specif tests use phpunit --filter or phpunit tests/unit/module1
    • Use the strict mode from the get go and never turn it off.

    Sample projects to look at

    • Sebastian Bergmanns "Bank Account" example project
    • phpBB3 Even so they have to fight some with their legacy 😉
    • Symfony
    • Doctrine2
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are currently going through the long process of writing some coding standards for
I'm currently planning a new web project. Clients are going to connect using a
I am thinking about going into .net framework client profile, but currently I am
I'm going to start a new project - rewriting an existing system (PHP +
So I inherited this Android project from someone else. The code currently seems to
I have currently created a facebook like page that pulls notifications from different tables,
[Question moved in from askubuntu.com] I'd like to get into Ubuntu systems programming; to
have been going through here and google looking for a spellcheck solution. I see
I'm going to start maintaining an Eclipse RCP application for my current employer soon.
i'm trying to make the following routes .. and currently i'm going about this

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.