Archive for the ‘PHP Programming’ category

Analysis Paralysis: In a quest for perfection, I manage to achieve nothing

December 4th, 2010

This was supposed to be a live coding note, but it just turned into something else. No ground breaking news, no new concept which will make you go “hmmm”, just a guy kicking himself – you can safely ignore this frustrated post if you aren’t in the mood to read about how much an idiot I think I am :P

It’s been a mixture of Tunnel Vision, NIH Syndrom and Analysis paralysis that had me living in a haze of trying to implement DataMappers ala Zend Quickstart Guide on and off, for the past 4 weeks.

I even wrote the Unit Tests and everything for this project I’ve taken part in called “customember”: a sample project to help a few newbies I know (and to a certain extent myself) skill up through practical experience rather than going into a real world project and doing the floundering around when the gun is really loaded.

» Read more: Analysis Paralysis: In a quest for perfection, I manage to achieve nothing

Unit testing with Live Databases and/or How do I use Mock Objects?

November 30th, 2010

This is another live coding note. I’ve found my rhythm with TDD and currently bashing away at some unit tests for the Models and Service layers for a project I’m working on.

In tonights post, I’m going to write about how I get around with Unit Testing live databases.

Unit Testing with Live Databases

For my unit tests, I’m currently working with a live test database since I don’t fully understand the “power” of mock objects. If you have any links out there that’s worth noting, please be a friend and “link me”. I’m not going to pretend that I know everything and anything about Web Development. I know a lot, but the one thing that I do know is that I don’t know everything.

Mock Objects. WTF are you?

One thing which is mostly a mystery to me is the concept and practical application of Mock Objects in Unit testing. I’ve read several articles on Mock objects, but some of them delve into how to create Mock Objects rather than practical usage for mock objects in a live development setting. What problem exactly are mock objects trying to solve?

I get that it replaces other objects that the current class your testing will collaborate with, but I’m guessing that this is due to not having a setup like I currently have where I have the extra application code which easily gives me access to the db resource so that I can just as easily do this within my unit test as it would with mock objects… maybe? I’m confused.

» Read more: Unit testing with Live Databases and/or How do I use Mock Objects?

How I refactored my Service Class to be “Separation of Concerns” Compliant.

November 23rd, 2010

I’m developing this web application where a users actions is logged at certain places. I initially wrote the logging features into the Main Users Service. I’m currently looking at it now and will be refactoring out the functionality to separate concerns. While to me, at the time, logging a Users action is from a natural standpoint looked like it belonged to the Users service, a more thorough look at it made it clear that the Logging functionality should be it’s own Service.

Don’t see where the mix up of concerns is?

Here’s a list of functionality my Users Service class provided.

  • Creating Users.
  • Reading Users.
  • Updating Users.
  • Deleting Users.
  • Fetching a User by Id.
  • Searching through Users.
  • Counting total search results (I utilise scroll pagination for my record list and dojo datagrid needs to know the total number of records it needs to scroll up to).

Think that the Log functionality is tied in directly with Users since you can’t have one without the other? Well, I did! To the point where the Model automagically handled logging by using the DbTable for the log. At that time, I accepted in my head that Users Log was part of Users and besides, it’s logging; my focus wasn’t on that particular “minor” detail.

» Read more: How I refactored my Service Class to be “Separation of Concerns” Compliant.

Dojo’s IndirectSelection plugin for the Enhanced Datagrid is deceptively unuseful.

November 23rd, 2010

One of the requirements for a project I’m working on is the ability to send emails to selected rows in the datagid. I thought no problem, the IndirectSelection plugin of the EnhancedGrid should be able to handle that semantically! Reading the API and when I initially tried it out I saw the neat little checkboxes as the first column. “Phoar! Checkboxes!” I swear those CBs had a glow around it and I could hear a choir singing in the background (“haaaaaaaaaaaaaa, easy fix for a requiremeeeeeeeeeeennnnnnnnnnnnnnt”).

Then I tried submitting with a bunch of rows selected. It was then clear to me that IndirectSelection is just that. It gives you checkboxes or radiobuttons to tell you that it’s selected, but aside from notification, it has no other use. The value in it is not configurable and neither is the name… Sad. Guess I’ll just have to insert a field for a checkbox. I’ll leave this till later. This functionality is a “nice to have” rather than critical functionality anyway.

» Read more: Dojo’s IndirectSelection plugin for the Enhanced Datagrid is deceptively unuseful.

To copy and paste or not to copy and paste; adventures in unit testing

November 20th, 2010

Yesterday evening. I started my next coding session. I contemplated the validity of copying and pasting unit tests that have similar functionality, but for totally different domains.

I have developed Service classes for a certain module and I can see this functionality the application of this functionality being similar accross the board. Functionality such as CRUD, Search and Search Result Count etc.

The only things that will be different would be the models it uses which will subsequently be using different DB Tables, but yeah… practically the same methods.

I’ll sit on this for a while, tie up some loose ends and will come back with what I’ve decided….

» Read more: To copy and paste or not to copy and paste; adventures in unit testing