Trac

Howto run and create unit tests (NEW)(DRAFT)

Doctrine is testing using UnitTests.

Requirements

In order to create and run the tests for Doctrine you need to check out the entire project, not just the lib folder.
In addition, you need a recent version of PHPUnit3 that is available from the include_path. If you installed PHPUnit through pear this is already the case.

Terminology

Doctrine's test suite has a terminology you need to be familar with:

Test Model Package
Doctrine's test suite contains a few sets of models, each modeling a part of an imaginary software system (actually, they're taken from real-world applications, but they evolve independantly). Such a model set is called a test model package. Currently the three test model packages are forum, cms and ecommerce. The test model packages are located in the following directories:
tests/models/forum/
tests/models/cms/
tests/models/ecommerce/

Fixtures and Fixture Scenarios
Fixtures are datasets that can be loaded into the database to set up some state for a testcase. A Fixture Scenario is a set of fixtures for a particular model package that are logically consistent. That means if a complete scenario would be loaded into the database it would reflect the state of the application at a particular point in time. When writing fixtures, you need to take care of the uniqueness of primary keys and the consistency of foreign keys within the scope of the scenario, not further. One default scenario that the 3 provided model packages have is the "common" scenario. The fixtures are structure like this:
tests/fixtures/forum/common/users.php (users.php fixture of the common scenario of the forum model package)

In a testcase you can load just a few fixtures of a particular scenario or even a complete scenario. But you should always only load as many fixtures as you need to successfully write a good testcase. Never load fixtures of different scenarios in one and the same testcase.

If the scenarios that already exist are not sufficient (they dont contain fixtures you can use to show your problem), you may create a custom scenario, i.e. named after a ticket number, that reflects the database state that triggers your issue.

Structure

[Explain test structure]

CLI

You can run the tests on the command line. In order to run the tests on the CLI you need to have php-cli installed in your environment.
Navigate to the [DOCTRINE_PATH]/tests folder and run the following command:

phpunit AllTests