To install the plugin into a Symfony project:
-
Install the plugin files into
plugins/
. -
Install PHPUnit 3.6 if necessary. Make sure it is accessible from PHP's
include_path
. -
Add a
test
entry toconfig/databases.yml
or disableuse_database
inapps/*/config/settings.yml
. -
Remove the
error_reporting
andno_script_name
entries for thetest
environment insettings.yml
for each application in your project. -
Add the following code to
ProjectConfiguration::setup()
inconfig/ProjectConfiguration.class.php
:if( PHP_SAPI == 'cli' ) { $this->enablePlugins('sfJwtPhpUnitPlugin'); }
Note: Because this plugin only provides Symfony tasks and should have no effect upon the normal operation of your project, it only needs to be loaded when in CLI mode.
Now you're ready to start writing tests!
For best results, consider adding the following additional configurations.
Note: these changes could affect the execution of your application logic and so are not turned on by default. Use caution!
By default, sfDoctrineDatabase
creates a Doctrine_Profiler
instance
to measure the performance of queries. It is particularly useful in dev mode
so that you can review queries in Symfony's Web Debug Toolbar, but in test
mode, it does little more than take up valuable system resources and memory.
To disable the profiler, add the following to your databases.yml
file:
# sf_config_dir/databases.yml
test:
<connection_name>:
class: sfDoctrineDatabase
param:
...
profiler: false
When you are done with a Doctrine_Query
object, it is a good idea to unset()
it to reclaim system resources.
This is especially critical during unit tests, where unreleased objects can hang around in memory long after the test that created them finishes. This can cause memory leaks that only manifest during testing - very annoying!
Ultimately the solution to this problem is to practice good memory management,
but if you are frequently encountering out-of-memory errors when running
tests, try adding the following code to your ProjectConfiguration
class:
# sf_config_dir/ProjectConfiguration.class.php
public function configureDoctrine( Doctrine_Manager $manager )
{
/* Automatically free() query objects to keep memory usage low. */
$manager->setAttribute(Doctrine_Core::ATTR_AUTO_FREE_QUERY_OBJECTS, true);
}
See Improving Performance from the Doctrine documentation for more information.