ZF, Doctrine and Unit Tests

Recently there are a lot of very interesting blog posts about using Zend Framework with the Doctrine ORM. I am really glad to see more and more people start talking about application design patterns, test driven development, etc. This trend means the PHP community is preparing to take PHP into the next level (enterprise? no?) . As a PHP developer, I see a lot of things to learn.

Back to the topic. I’ve been testing to use both Zend Framework and Doctrine for a while now. As a matter of fact, I never really have them hook up perfectly. The issue I faced was about the Doctrine command line tool. I just cannot manage to bootstrap the Doctrine command line script correctly. I can get Doctrine command line script to drop database, create database, generate models in PEAR style (which is used by the Zend Framework) from the yaml schema file. But I cannot get it to create tables, generate SQL, etc.

This did not seem to be a real issue until I started wondering about unit test my Doctrine model classes. Ideally, when I do my unit tests, I can re-create my testing database, reload my data fixture file. So … I started digging.

Eric Leclerc made a really helpful blog post recently about setting up Zend Framework and Doctrine. Even better, Eric kindly created a sample application on github. I downloaded it, had a play, worked really well!

Next is unit testing. Lucky we still have Jon Lebensold, the creator of ZendCasts. Jon just made another great podcast on “Writing Doctrine Unit Tests with Zend_Test” yesterday. I downloaded the source code from Jon’s episode. I started merging it with Eric’s sample application.

After some tweaks and changes. I believe I finally have a working copy. That is Zend Framework + Doctrine + ZFDebug + Zend_Test. All in one project (no need to create models in a model generator project with Doctrine, copy them across to my ZF application).

I have pushed my sample application to github to share with others who are interested in using Doctrine with Zend Framework. You can find the application at http://github.com/marsbomber/zf-with-doctrine.

Hope it helps. And also, my sincere thanks to Eric Leclerc and Jon Lebensold.

Reference

Share this article on:
  • Facebook
  • Twitter
  • Google Bookmarks
  • Digg
  • del.icio.us
  • LinkedIn
  • MySpace
  • email
  • Live
  • Reddit
  • RSS
  • StumbleUpon

Related posts:

  1. Zend Framework 1 and Doctrine 2 integration
  2. Zend Framework 1 and Doctrine 2 integration – modular setup
  3. ZF authentication using Doctrine
  4. My Zend Framework project setup
  5. Doctrine tricks
Categories: Doctrine - PHP - Zend Framework
yicjiang
thanks for sharing this..
11 January 10 at 14:36
lexterv
hello, tested your example and when it comes to generating model, the CLI is not able to find the yaml class and when this problem is fixed it is not able to find the base class
1 February 10 at 09:27
@lexterv can you be a bit more specific? what was the cmd you run, when you got your yaml cannot be found error? are you on windows, linux or osx?

I tested the setup on both osx and windows 7, both using the xampp stack. it seems to be working fine.
1 February 10 at 10:00
Genial dispatch and this post helped me alot in my college assignement. Say thank you you seeking your information.
2 February 10 at 12:13
Hey, I read a lot of blogs on a daily basis and for the most part, people lack substance but, I just wanted to make a quick comment to say GREAT blog!…..I”ll be checking in on a regularly now….Keep up the good work! :)
2 February 10 at 19:45