News Feed
Sections




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

Jeremy Cook's Blog:
Making PHPUnit, Doctrine & MySQL Play Nicely
March 02, 2012 @ 12:05:48

Jeremy Cook has put together a new post showing how he got PUPUnit, Doctrine and MySQL to "play nicely" together when he was writing up some of his tests in a current application.

One of the pain points for me though has been in getting Doctrine setup with PHPUnit for testing. One of the main Doctrine contributors, Benjamin Beberlei, has written a package called DoctrineExtensions which amongst other things adds a class called DoctrineExtensionsPHPUnitOrmTestCase which extends PHPUnit's DbUnit database test case class. This all works well in principle but hits a major snag in reality: MySQL doesn't allow InnoDb tables with foreign keys to be truncated. PHUnit's database extension truncates the database tables before each test run and inserts a fresh set of data to work with.

To work around this issue Jeremy by porting over a method posted by Mike Lively over to Doctrine as a custom "MySQLTruncate" class (code included in the post). He also includes some sample code showing it in use - a basic ORM test case that calls the truncate method when its set up.

0 comments voice your opinion now!
phpunit doctrine orm unittest mysql truncate


blog comments powered by Disqus

Similar Posts

Michael Kimsal's Blog: Zend Framework and Doctrine integration autoloading of doctrine models

SitePoint PHP Blog: pTest: PHP Unit Tester in 9 Lines Of Code

MySQL Performance Blog: SSL Performance Overhead in MySQL

Matthias Noback: Test Symfony2 commands using the Process component and asynchronous assertions

Mike Kornienko's Blog: Integration of Spry and PHP/MySQL


Community Events

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


conference introduction development community library podcast series video opinion interview extension laravel release framework language unittest voicesoftheelephpant psr7 api laravel5

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