flm
flm

Reputation: 970

How to enable Doctrine query logging in Symfony 1.4 unit tests

I am unit testing a model class and I would like all Doctrine queries to be logged. My settings.yml for the test environment contains

logging_enabled: true

and my script

$configuration = ProjectConfiguration::getApplicationConfiguration( 'frontend', 'test', true);
new sfDatabaseManager( $configuration ) ;

Still, I don't see any log in any log file.

Upvotes: 1

Views: 696

Answers (1)

flm
flm

Reputation: 970

So, I found a workaround by using an event listener on the Doctrine profiler.

$profiler = new Doctrine_Connection_Profiler();
$conn = Doctrine_Manager::connection();
$conn->setListener($profiler);

/* tests go here */

foreach ($profiler as $event) {
    echo $event->getQuery() . "\n";
}

But the same query is printed out several times for some reason (I am sure it is executed only once). Plus it is not so convenient to have the query logs dissociated from the rest of the log messages.

Upvotes: 2

Related Questions