This is a short tutorial to show how to use fixtures for database related unit tests. The inspiration for this post came from a conversation I had at the recent PHP Unconference in Hamburg, Germany. From my experience, the usual way to test database related classes is to use a special test database, that needs a reset before each run (drop the existing tables and import the test dump). That approach has several severe drawbacks, all observed in real life projects many, many times:
There is a subtle difference between what Robert C. Martin recommends in Clean Code and what Andrew Hunt / David Thomas recommend in The Pragmatic Programmer. Martin encourages you to always use exceptions if the normal program flow is interrupted to avoid if statements (or even worse: forgotten if statements and mixed result types) while Hunt/Thomas say this can cause harm (“it’s a kind of cascading goto”) and should only be used if something truly unexpected happens (tip 34).
What does passion mean for a Software Engineer? Depends on the context. First, and that’s what start-up companies usually expect from their employes, it means you love the company, the business idea and the team you work with. Some people are also passionate about their Apple computer/phone/tablet in a similar way (the term “Fanboy” is frequently used in Web forums to describe this behavior). * Second, it can mean that you stay ahead of the curve and have strong opinions about how to do your job (independent from the company you’re currently working for): For example, I’m obsessed with clean code and unit tests.
As you can see on my Linkedin profile, I used to work as consultant for 6Wunderkinder, a Berlin based start-up company, last year. My job was to provide training for the developers and help building the initial Web frontend for Wunderkit, their next product after the popular Wunderlist app. Even though I could say a lot about what I liked and didn’t like about any company I worked with, I’m never disclosing internal details.
I’m currently reading The Clean Coder by Robert C. Martin. Here are some of my favorite quotes: Caffeine “There is no doubt that some of us can make more efficient use of our focus-manna by consuming moderate amounts of caffeine. But take care. Caffeine also puts a strange jitter on our focus.” Arrogance “Programmers tend to be arrogant, self-absorbed introverts.We didn’t go into this business because we like people. Most of us got into programming because we prefer to deeply focus on sterile minutia, juggle lots of concepts simultaneously, and in general prove to ourselves that we have brains the size of a planet, all while not having to interact with the messy complexities of other people.
During the last couple of days, I’ve been updating my posting about cargo cult coding standards for PHP. There are some examples now. Thanks to Arturas Smorgun for retweeting it. I’m sure my post doesn’t have a huge impact on the community, but for me it’s still worth talking about my experiences. Guess what’s bothering me the most is that the popular PEAR/Zend Framework coding standard actually forces you to lose the context of your currently edited code.
Cargo cult means that you copy some (previously) successful behavior from others and expect something good to happen to you (or your project) as well. For coding standards, that’s a very good starting point. Especially since formatting standards are often not based on any science – life is just easier, if everyone is using the same formatting for source code and we all hate the discussions at the start of projects, when some junior developer tries to promote it’s own fancy ideas.
Since I can’t use OpenJDK for most applications (see last post), I was looking for a way to easily replace it with the original JDK. Thankfully I found a good howto. The short version: # Download Java from Oracle * and extract the contents of the tar.gz archive to "java-7-oracle" sudo mv java-7-oracle/ /usr/lib/jvm/ sudo add-apt-repository ppa:nilarimogard/webupd8 sudo apt-get update sudo apt-get install update-java sudo update-java http://www.oracle.com/technetwork/java/javase/downloads/java-se-jdk-7-download-432154.html This should work for Ubuntu 11.