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

IBM developerWorks: What's new in PHP V5.2, Part 4: Using the new ZIP extension

Symfony Blog: YAML in symfony 1.1

Community News: PHPUnit 3.2 Released

Sebastian Bergmann's Blog: Isolated (and Parallel) Test Execution

BillS' IIS Blog: How to install FastCGI and PHP on IIS7 Beta 3 (Video)


Community Events





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


update laravel symfony interview tips zendserver language framework series install opinion package deployment list library api community release introduction podcast

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