Contact Us

Agile web development (with CakePHP)

Posted on 14/8/06 by Felix Geisendörfer

For everybody who has read my previous post on automatisation, there are good news:

After having finished the "Pragmatic Programmer", I'm reading "Practices of an Agile Developer" and I enjoy it a lot. So I've decided that, over the course of the next couple days (or weeks), I'll dedicate quite a bit of my time to explore ways to improve the way I write web applications. This includes getting into unit/integration testing, automating workflows, and also adopting better coding techniques. A lot of it will eventually speed up processes here and there, but most of it will be directed torwards higher quality (which will hopefully lead to less bugs and reduce work on "finished" projects). A lot of times I'll try to translate some of the tips out of the books I mentioned above into the world of web development, on other times you'll just see my regular php related code postings ; ).

Right now, I'm trying to get a list of good technologies to help me on my way to agility. So far I've come across a couple very nice ones for some of the things I plan to do:

Automatisation: Apache Ant

In my last post I wrote about using bash scripts to automate some of my common tasks. Daniel Hofstetter pointed out that he is using Ant for his projects, and since I respect his opinnion a lot, I went ahead and checked it out:

The official website states that "Apache Ant is a Java-based build tool. In theory, it is kind of like Make, but without Make's wrinkles.". Usally tools like make (or Ant) are being used for java/c/c++ or other compiled languages to help with the process of creating the binary files by providing ways to define a toolchain. In the (Cake)PHP world, we don't "compile" things, so I wasn't quite sure if it would be useful. But as it turns out those folks working on ant are going way beyond that. Ant ships (or can be extended) with tools to complete tasks like: Zipping, Mailing, FTP, SVN/CVS, Image editing, Unit testing, MySql, and many more. Lots of them very useful when working on web projects. I already used it to automate the deployment (strip .svn files, upload to ftp, update sql) of my latest project and I'm in the process of refactoring it to be useful for any CakePHP app. I'll write more about it when I feel like I gained enough familarity with it.

In case you are interested in it already and want to check it out by yourself:

Testing: Simple Test for PHP

For unit testing I am probably going to use the popular Simple Test testing framework. I've looked at some other ones but I've heard a lot of good things about this one so I'll give it a try. However, I am probably not going to use CakePHP's TestSuite for it. That's mostly because it has no official documentation / support and it also seems to have some problems when running from within a sub folder. I want my unit (and integrational) testing to work from the command line, so I can include it into ant's deployment task (nothing ships unless it passes the test).

If anybody has other suggestions of which testing framework to use, i'd be glad to hear them ; ).

Testing: Selenium Remote Control

In terms of Integration/Acceptance testing, it seems like the Selenium framework is the only thing around that allows you to run your tests directly inside some of the major browsers (ie, firefox, opera, safari (?)). This allows for not only testing the normal html output, but also most of the fancy ajax features one might uses in his application. Selenium itself uses javascript to perform a good form of cross site scripting (xss) that allows you to simulate the behavior of a user. You can make it click links, submit forms, validate texts etc.. Selenium Remote Control is an addition to Selenium Core that allows you to use a programming language to write your integrational tests, rather then Selenium Core's default Selenese markup (which basically is made up by a bunch of html tables). That way you can output the results to just about anything, like a command line for my needs ; ).

Since php is not on the list of supported languages I'll not waste my time to write a hack for it, but rather learn one of the other languages it supports. Most likely that'll be ruby (but don't you worry, I'm not going to join the rails crowd at any point soon).

Testing: Selenium IDE

Selenium IDE is an extension for Mozilla Firefox that'll allow you to manually record things you do in your browser and play them back. Yes, you've heard right! It's the exact kind of neat little tool that you wanted to have years ago when you tried to get this form to work and typed in sample data by hand over and over again! Well it's 2006 and you really shouldn't be doing this any more ; ). One or two times are ok, but if you find yourself running the same kind of test for more then 3 times in a row, you might want to use this little tool instead. But anyway, that's just it's basic funcionality. What it will do as well, is to generate Selenese, Java, Ruby, Python, C# or Perl scripts for you, that you can use for Selenium Remote Control. Neat, uhm?!

Finally ...

... I ran out of tools to point out and have come to the end of this posting. One of the things I want to say before I quit firefox in order to bring out the trash, is that I don't know if all the tools I mentioned here, will really be the ones I end up using. I've played around with ant for the last couple of days, and I used to work with Selenium core, but other then that I might change my mind again. In case you have other programs you like for agile web development, or things one of the ones I mentioned isn't any good, just drop me a comment and I'll check it out.

Anyway, thanks for reading, I hope I have some more "productive" stuff to write about next time ; ).

--Felix Geisendörfer aka the_undefined


You can skip to the end and add a comment.

Daniel Hofstetter said on Aug 14, 2006:

Well, I am going to work on the test suite soon. At the moment I am gathering ideas on how to improve it. But command line support is definitely one of the goals ;-)

If there are other features you think could be useful, please let me know.

Felix Geisendörfer said on Aug 14, 2006:

Alright, is there are formal place for it? Or should I send you an e-mail / put it in the comments here?

Daniel Hofstetter said on Aug 14, 2006:

There is no formal place for that. Just send me an email or put it in the comments, whatever you prefer. said on Aug 14, 2006:

Felix Geisendörfer's Blog: Agile Web development (with CakePHP)...


Walker Hamilton said on Aug 14, 2006:

Try using "Capistrano": rather than Ant. The guy who built the first version of Ant professes that it's really crap, and he "kinda wishes" he hadn't released it. He said it was good for what he was doing at the time.

Capistrano is a ruby based script but it can be used to deploy any web application written in any language.

Evan Wired  said on Aug 14, 2006:

Have you considered using Phing, which is a PHP5 port of Ant?

I use Phing for all of my build automation.

Capistrano is also quite good, if you can put up with Ruby.

Felix Geisendörfer said on Aug 14, 2006:

Walker Hamilton: Thanks for pointing Capistrano out. Unfortunatly I don't think I am not going to be able to use it. Many (if not all) of the servers I deploy my web app's on are cheap shared host ones that don't give me SSH acess (which Capistrano demands). The other thing is, that it's more aimed at the Rails croud than anybody else. Now I can see how one may configure that, but running against the conventions is usally a little tricky.

Another thing: I can not see how the Ant guy says he wishes he would never have published it. Ant is great, and has been very helpful to many developers out there (as far as I can tell), and maybe there are things that could be done (a lot?) better, but if the tool did the job it was supposed to do at the time of release, it's still a good tool. I hate it when people complain about their old projects to be of low quality (including me ^^). Because what it shows is that those projects have made you a better developer, and you should worry a little bit if you feel like the projects you did 2-3 years ago are just as good as the ones you do now, because that means you haven't improved much since then. Anyway, enough ranting on that ; ).

Evan Wired: I looked at phing, and I don't get why it exists. I could not find any amazing advantages over ant nor does it even seem to have the same functionality. It seems to lack an ftp task which is very important to me, and it's also php5 (I'm still using php4).

Anyway, thanks for the comments and I'll keep looking out for other tools to play around with ; ).

teemow said on Aug 16, 2006:

I've added javascript unit tests to cake's test suite. It's just a hack and so is the whole test suite. Assuming it would be better to start from scratch.

@Daniel: I would like to work on it too as it's really important to get more people into testing cake apps.

Felix Geisendörfer said on Aug 16, 2006:

teemow : How does your javascript unit testing work? I'm interested in playing around with that as wel, even so Unit/Integrational testing has kept me quite busy so far : P.

Evan Wired  said on Aug 18, 2006:

The reason Phing exists is because some of us don't have any need for Java in our PHP toolchain.

We wrote our own (S)FTP task for Phing.

Felix Geisendörfer said on Aug 18, 2006:

Hi Even: Don't get me wrong. I was not exactly exited about installing all this java stuff required for it either, but now that I did I'm fairly happy with it. If Phing wasn't php5 only I might give it a try, but right now I still am mainly doing php4.

teemow said on Aug 20, 2006:

I simply took the jsunit testing application and integrated it with cake's test suite. Just added a js folder besides app and core and handing over those files to the jsunit app.

There is a german post about my javascript MVC concept with jquery.

Markus Bertheau said on Sep 15, 2006:

I’ve written a tutorial on how to use Selenium Remote Control: Functional unit testing for web applications. I'm using the Python client driver still; if I find time to write the PHP client driver, I'll blog about how to integrate it with the testing framework from cakeforge which uses SimpleTest.

Felix Geisendörfer said on Sep 15, 2006:

Hey Markus: I've looked at your post and I think it's pretty nice read. I was more in favor of using Ruby for writing my test cases (as an excuse to pick up some Ruby skills) but Python is a cool idea too.

However, having a PHP client driver would definitly be awesome and you'd get a big "hurray for markus" post on here if you would find the time to write one ; ). But thanks for pointing out your article for now.

Ryan Rose  said on Sep 16, 2006:

I am looking to automate the deployment of my current CakePHP project using Ant and Subversion. It looks like you already have experience doing this (strip .svn files, upload to ftp, update sql). Could you please post an example about this?

Felix Geisendörfer said on Sep 16, 2006:

Ryan: Hm, I had one problem that I really couldn't resolve so far: Ant's ftp task isn't able to chmod folders which I would need for the /app/tmp/ folder, so I didn't get a fully automated deployment cycle done so far either. The other problem is that I did all those things on another computer I have no access to any more, so I'll have to setup things on my dev machine here again. Anyway, I will keep working on it and write a post when I've found a complete solution.

Troy Schmidt  said on Sep 21, 2006:


Sounds like we are in the same boat. Desperately trying to find something already written to deploy a single application to multiple client servers, then upload their specific configuration files. I don't need the subversion part of it, but the chmod on the ftp would be nice.

I also sometimes need SQL update as well. I have thought for this a CakePHP app update component or controller would be nice. I could put the zip on a server and then run the app update which would grab the zip, unpack correctly, update chmod as necessary, run necessary SQL.

Although seems like someone would have already done something to accomplish this task.

Felix Geisendörfer said on Sep 21, 2006:

My main problem is that I mostly deploy on shared hosting enviornments and some of the good tools out there are working with SSH access only : /. One thing I'm considering is writing some deployment app for myself in php4. I'll definitly talk about this again soon.

[...] Ok, what are the other alternatives? I know some people like Phing, but it doesn’t come with a FTP task and uses php5 (I’m on php4). Anyway, “Evan Wired” mentioned that he uses (scroll down to the comments) a custom FTP task with phing, so Evan if you are still reading this blog and would like to share your task - I would love to give it a try at this point. [...]

This post is too old. We do not allow comments here anymore in order to fight spam. If you have real feedback or questions for the post, please contact us.