Database helper for PHPUnit

August 27, 2008 – 1:10 pm Tags: ,

When testing code which uses the database, you would usually want to make sure the database stays pristine for each test - All tables should be empty, as any extra data could interfere with the tests.

You could probably write an extended Testcase class which automatically does this before each test in setUp and afterwards in tearDown, but it may have some issues. For example, Zend Framework’s Zend_Test Testcase class also extends PHPUnit’s one, and you might need to extend the Zend_Test one as well… and so on.

Luckily, PHPUnit has a way to add event listener that react to certain events.

Read the rest of this entry »

Implementing swappable authentication methods

August 21, 2008 – 5:13 pm Tags: ,

I’ve mentioned a CMS I’m working on in a couple of occaions. Lately, I’ve been tinkering with the user authentication part of it, and stumbled upon a small obstacle: How to make it easy to change authentication methods?

Most of the time you probably would like to use a database to store your users, but at work, I had to create a way to authenticate users from Windows Active Directory using LDAP. Another case could be unit testing - you might want to test your authentication code without a database.

Read the rest of this entry »

How I got into programming

August 15, 2008 – 8:50 am Tags:

While browsing around some old files on my computer, I came across some old files from 1998 (I think): An old text-game by some of my elementary school friends.

It reminded me of how I got started in programming. It was probably when I was 11 or 12 years old, when a friend told me about a text adventure game he had made and showed me how it worked…

Read the rest of this entry »

Zend_Form decorator tips

August 7, 2008 – 2:56 pm Tags:

It seems a lot of people are struggling with Zend_Form decorators. They want to know how to modify the markup, but they can’t figure out how to do it with the bundled decorators or how to write their own.

Since I’ve done some decorator-stuff myself, I thought I’d share some tips on making the output a bit nicer. For example, how to make Zend_Form use <ul> and <li> tags instead of <dd>, <dt> and <dl>. I also wanted some inputs appear side by side (date from and date to in my case).

Read the rest of this entry »

PRADO: PHP goes ASP.NET (ish)

August 4, 2008 – 11:53 am Tags:

Lately, I’ve been checking out PRADO, which is “a component-based and event-driven programming framework for developing Web applications in PHP 5″.

What that actually means is that you can use components, such as a data grid or a button, and work with them based on events without having to think about the traditional things associated with such: Parsing out POST or GET variables and handling the application state.

I think it’s a quite refreshing approach compared to what most PHP frameworks do.

Read the rest of this entry »

View inheritance and “blocks” in Zend_View

August 1, 2008 – 8:42 pm Tags: ,

Some frameworks like Django and PRADO have the concept of view inheritance, or a “master page” like in ASP.NET. Essentially it’s a similar idea as Zend_Layout is in Zend Framework, but the difference is that you can define the master/parent view inside the view itself.

For example, in Django {% extends "base.html" %} would make the current template extend “base.html”, and you then you can define blocks that will be placed in placeholder blocks in the parent. In Zend Framework, doing this kind of “blocks” is a bit complicated and it’s a bit difficult to create default content in them as well, which can be optionally replaced with something else.

Since I like the block and inheritance style approach, I decided to see how this can be done in Zend Framework…

Read the rest of this entry »

Setting up command-line PHP on Windows

July 28, 2008 – 9:14 am Tags:

On *nix systems you usually have the php executable available in shell, so you can run command-line scripts like unit tests and such, but on Windows this isn’t usually the case. Let’s fix that!

There’s two ways to do this: Temporary and permanent

Read the rest of this entry »

Opera UserJS competition

July 26, 2008 – 8:41 pm Tags:

Opera recently held a UserJS competition, where I participated with a script that makes Google Spreadsheets work in Opera, a script which improves Apache directory listings and a social bookmarking site toolbar.

Opera chose my Google Spreadsheets script as the winner of Site Fixes category, and I will be receiving a shiny new HTC Touch Diamond phone with Opera 9.5 preinstalled! :D

Head to UserJS contest winners post at myopera to see the other scripts that participated. I think especially History+ is a really cool idea and shows clever thinking and that you can actually do a lot more with UserJS than you might initially think.

On template “tag soup”

July 22, 2008 – 10:25 am Tags:

Jeff Atwood’s latest post (at the time of writing this) talks about mixing HTML markup and server-side code, àla

<table>
 <?php foreach($foo as $bar): ?>
  <tr>
   <td><?php echo $bar; ?></td>
  </tr>
 <?php endforeach; ?>
</table>

He also throws in the question: Is there a better way? - However, it seems there’s at least as many ideas of a better way as there are programmers…

Read the rest of this entry »

Is Smarty really obsolete?

July 19, 2008 – 2:28 pm Tags:

There was a short discussion on Zend Framework general mailing list about Smarty being obsolete. I decided to take my opinion here, since the discussion was getting quite off-topic…

Arguments against Smarty presented were mainly the facts that it is PHP4 and its no longer necessary in “modern” web development.

Read the rest of this entry »