News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Matthew Turland:
Customizing Codeception Database Cleanup
May 12, 2014 @ 11:15:24

If you're a Codeception user, you'll find Matthew Turland's latest post interesting. In it he shares a way to customize database cleanup between the tests. Codeception handles it a bit differently that how PHPUnit's Db module does.

Recently, I was looking into ways to speed up the runtime of the test suite at Blopboard. We use the Codeception framework to write functional tests for our REST API, part of which entails putting the database into a known state using Codeception's Db module. The behavior of this module is similar to that of the PHPUnit Database extension with one exception: where PHPUnit only truncates tables and leaves their schemas intact, Codeception removes the database structure and expects the SQL dump it uses to recreate it between tests. I must admit to not understanding this design decision of Codeception, nor attempts to clarify it.

He admits that his solution is "a bit hacky" but it does work to truncate the table rather than drop the entire schema and wait for a rebuild. His "DbHelper" class is used in place of the Db module. He traced through the execution path of the Db module and found a "hook" where he could override the "cleanup" method to prevent the schema drop and replace it with a truncate. He also includes code for a suggested addition to Codception that would handle the same thing in a more integrated way.

0 comments voice your opinion now!
customize database cleanup codeception tutorial schema truncate phpunit

Link: http://matthewturland.com/2014/05/09/customizing-codeception-database-cleanup

blog comments powered by Disqus

Similar Posts

Brandon Savage's Blog: Installing PHP 5.3 On Ubuntu

PHPMaster.com: Using WampServer for Local Development

Avnet Labs Blog: TDD with Zend Framework

NETTUTS.com: Online File Storage with PHP

Code2Learn.com: Using HighCharts with php , MySQL and CodeIgniter


Community Events

Don't see your event here?
Let us know!


api application opinion example composer series symfony language podcast configure list introduction interview framework laravel community part2 php7 yii2 project

All content copyright, 2015 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework