You’ve written a PHP based web app, and you’ve made sure it doesn’t cause errors if the user submits unexpected values via any URLs or forms. But there’s something you quite likely forgot to test: What if the data that’s expected to be a singular value happens to be an array? If you assumed a GET or POST parameter will …
What is a null object, and when are they useful?
If you’ve written code, you’ve probably used the value null to indicate some variable is not set. This is perfectly good, but did you know there’s more to nulls than just the value null? There is also a null object, which doesn’t really have anything to do with the value null, but its purprose is similar. How many times have …
Unit testing 4: Mock objects and testing code which uses the database
After learning to write tests and some good testing practices, it’s now time to look at mock objects. When testing a class which needs an instance of another class to work, you do not want to depend on the other class too much. This is where mock objects come in – a mock object is a “clone” of an object, …
Unit testing 3: Writing tests for existing code
Now that you know what unit testing is and how to write and run tests, it’s time to look at writing tests in more depth. Today we’ll take an example class and write tests for it. We’ll also introduce some common testing methodologies.
Unit testing part 2: Writing and running tests
Continuing from the unit test introduction, we will now continue and take a look at how to write tests and ways to run the tests.
Refactoring
Today I’d like to point out a bunch of good articles about refactoring – the process of improving code without changing the functionality. Sameer Borate has written four posts about the topic in his blog, and I encourage you to check them out: Refactoring: An introduction to PHP programmers Refactoring 1: Conslidate conditional expressions Refactoring 2: Extract method Refactoring 3: …
Dealing with different password validation schemes in a single app
If your application is well thought out, you would not want to save any data that isn’t valid. So what do you do, when you need different validation schemes, say for passwords, depending on some special case? For example: Your user passwords need to be at least 8 characters long and contain upper and lower case letters, a number and …
Doctrine vs. Propel: 2009 update
The best PHP ORM libraries, Doctrine and Propel. Last year I compared them to each other, and now it’s time to get a fresh look at how they have advanced in about a year – Is Doctrine still the better of the two? This time, I’ll also look at the features of each in more depth.
Validating Zend_Forms using model objects
Zend_Forms, models, validation and how they all work together is a tricky topic. There are many opinions and many ways to do it. This time I’ll show you what I think could be the answer to validating forms without having to duplicate validation code both in a model class and in your form.
PHP Magic Features
I wrote an article for Packt Publishing about PHP’s magic features: Magic functions, methods and constants. The article has now been published on Packt’s website, and you can read it here!