Pregunta

My unit test is very simple. My question isn't so much as 'whats wrong with the test/query' as it is how to trouble shoot these issues in APP/test.php by getting a generated SQL Query.

The following is my Unit Test:

public function testMatchingPasswords() {
    debug($this->User->save($this->genericSaveData));
}

And I get the following error:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'User.username' in 'where clause'

I understand the problem, and if I could see the generated SQL Query, I should be able to troubleshoot the issue further and resolve it. But on test.php it doesn't display the generated SQL Query. How can I make the test.php more verbose so that I can see what query is being generated?

¿Fue útil?

Solución

It looks as though the best bet is to catch the PDOException and inspect the stack trace, as that includes the prepared query.

So say you are having trouble with $this->User->save($data) you could do this:

try {
    $this->User->save($data);
} catch (PDOException $e) {
    var_dump(array_slice($e->getTrace(), 0, 3));
}

The _execute call should be fairly near the top, with the generated query included in args.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top