var_dump in Codeception
July 11, 2014
I've learnt making my test failures as ablative as possible trying to stick to the philosophy of "writing a test any time I'm tempted to var_dump".
Sometimes, in a "who watches the watchers" way, what't under test is the testing component itself.
I was trying to iterate over my WPDb module to suit my latest needs and found myself unable to dump some values to the console for light debugging.
While unit-testing running the test case with PHPUnit will allow me to commit any kind of coding crime and see the results in the terminal but Codeception is way more educated and will hide all that mess for the sake of manners.
Make Codeception talk
To make Codeception modules "talk" and make debug possible Codeception can be run in debug
mode like
codeception run --debug
and anywhere in a module the debug
or debugSection
methods can be used like
public function haveOrUpdateInDatabase($table, array $data)
{
$query = $this->driver->insertOrUpdate($table, $data);
$this->debugSection('Query', $query);
...
to have clean and proper output on the terminal [](http://theaveragedev.local/wordpress/wp-content/uploads/2014/07/2014-07-11-at-18.45.png)