eddiejaoude / Zend-Framework--Doctrine-ORM--PHPUnit--Ant--Jenkins-CI--TDD-

[DEPRECATED for ZF2 & Composer] Best practice Zend Framework (ZF) skeleton / base with Doctrine2 integration : High code coverage & build scripts using TDD. Issues section ar e used for project planning (features etc)
http://www.jaoudestudios.com
160 stars 40 forks source link

Bootstrapping of unit tests #55

Open papayasoft opened 13 years ago

papayasoft commented 13 years ago

So I see that phpunit.xml points to the bootstrap script tests/bootstrap.php, which contains an inline definition of a BaseTestCase.

Several questions:

  1. In general, shouldn't this BaseTestCase reside in it's own external file, probably somewhere in the tests folder?
  2. BaseTestCase::setUp() performs a complete Doctrine bootstrap by calling $this->doctrine(). Do we need to perform a complete Doctrine bootstrap for each testXXX()? Or is it sufficient to simply bootstrap Doctrine a single time when we start the test run? I gotta figure it would at least speed up the tests.
  3. Along the same lines, can't we point to the common app Bootstrap class and then in bootstrap.php simply call something like:

    $application->bootstrap('autoloader') ->bootstrap('doctrine) // etc.

Even if there are slight differences between the Bootstrap for production and for testing - I seem to see a different argument to $config->newDefaultAnnotationDriver(), couldn't we share code and implement those differences in the config? At worst, we could change the config key bootstrap.path to point to a distinct testing Bootstrap that resides within the tests folder.

Just thinking out loud.

eddiejaoude commented 13 years ago

Some really good ideas there. I like your thinking, with optimisation & separation.

papayasoft commented 13 years ago

Looking at it more closely, I see that the controller based tests - tests that actually dispatch a request - do need to do a full bootstrap on each setUp(). So, those tests should extends this BaseTestCase which contains that required app bootstrapping. Still, tests that don't use a full dispatch cycle - like the config tests and perhaps others - should probably only extend the standard PHPUnit_Framework_TestCase.

But we should still look at the other two aspects:

  1. Have BaseTestCase reside in an external file
  2. Try to refactor the app Bootstrap so that it is configurable for all APPLICATION_ENV's

I'll try to take a look at that.

eddiejaoude commented 13 years ago

Thanks for keeping us posted with your progress & what you find. Afterwards it will be more efficient and have a better code coverage of each mode. :)