“All code should be tested in my opinion – it helps produce quality code and give you the confidence the code is working in the way you expect”
So writing more javascript has meant I want to test that too I quickly discovered QUnit – a very simple library developed by the creator of jQuery John Resig. Although not the only tool I looked at this seemed to satisfy my requirements at the time. I need to check out Jasmine as I have heard that is good too. But this was simple and quick to adopt and had an easily understood syntax.
So here is a quick code example, taken directly from an application I put together – check to make sure the marker array is emptied of markers when the appropriate function is called.
{code}
test(“remove markers”,function(){
kepn_map.removeMarkers();
ok(kepn_map.markers.length==0); <— assertion
})
{code}
It has some basic yet powerful assertions (OK,equal being the most commonly used), ability to run tests asynchronously and is easy to set up so I thought i would share it. I know I will be using this more often,and looking into other tools for the same.
Don’t upgrade PHPUnit if on Zend 1.11
OK I learnt the hard way – after upgrading my phpunit to 3.6 so I could give a talk at ILinkoln I soon discovered that this made my Zend tests hang – particularly controller tests. Didumms I hear you say just downgrade. But it is not just downgrade so I thought I would write it up here for anyone else needing to downgrade from PHPunit 3.6
You need to determine which aspects you have installed – then Unistall them
sudo pear uninstall phpunit/PHPUnit
sudo pear uninstall phpunit/DbUnit
sudo pear uninstall phpunit/PHP_CodeCoverage
sudo pear uninstall phpunit/File_Iterator
sudo pear uninstall phpunit/Text_Template
sudo pear uninstall phpunit/PHP_Timer
sudo pear uninstall phpunit/PHPUnit_MockObject
sudo pear uninstall phpunit/PHPUnit_Selenium
sudo pear uninstall pear.symfony-project.com/YAML
Then you need to specifically install the versions you require for the phpunti version you are reverting to
I chose 3.5.15 – even through Zend on officailly support 3.4.x I have been happily running with this.
You need to install the specific versions of each dependency, in an exact order depending on what you, then install PHPUnit-3.5.15 last.
But how do you install a previous persion of a dependency and phpunit easy
Next install these specific versions of each dependency, in this order, installing PHPUnit-3.5.15 last.
sudo pear install
e.g
sudo pear install phpunit/PHPUnit-3.5.15
Hope that helps someone else not waste a hour.
PHPNW11 – a review – Day 1
I recently attended PHPNW conference again (I have been to all but one since it started), this has become another one of my annual geek pilgramages and thought I would drop a few notes down, *Disclaimer: I was a volunteer helper, which means I don’t have anything to do with the organisation, but sometimes the session I am in is not one I would have immediately chosen. Also I did not get chance to go to the un-conferance part, shame that. Please note these individual reviews are marked up with hReview and are therefore freely and easily available for you to share if you so wish.
The awesome conference that is PHPNW.
Reviewer: Shaun Hare Oct 9th 2011
OK, the title/summary probably says enough, I thoroughly enjoyed the conference,as I have on previous years.
The change in venue this year to the former Ramada Manchester, was actually beneficial I think, as I managed to secure a room there
having the conference 4 floors down from your own room was extremely useful, I never had to queue for the gents, a big conference problem
as these things are largely full of geeky men. That puts me on a tangent – more women needed, if you are a woman reading this please attend these type of conferences if you can. They are great and you will come away with a great deal of info and I know there are some awesome women developers in our industry. I go to conferences to learn from awesome developers I don’t care what sex you are. There were a few there but really they are underrepresented at every conference I go to. As far as I am aware there was only one woman speaker, see review later. Anyway it’s up to you guys(ladies etc) but all I can say is I would welcome more women over to the geeky white side.
There were a range of exhibitors, and I was impressed by the content, even though a lot of them were recruiting and I wasn’t looking for a job they were still happy to chat. If you were looking for a job in PHP and weren’t there then sorry you missed out, it was definitely the place to get a good PHP job. One thing I like about this a other geek conferences there was a good selection of books for sale, in this case thanks to O’Reilly, at reduced prices. So that was good too.
I came away with a interesting coffeescript book – as that is something I am playing with at the moment.
Registration is often challenging at conferences and as I was helping out I am going to have to say it was good, but I do feel we got a lot of people through with minimal confusion.
So what for next year would I suggest if anything. Maybe the conference organisers Emma ,Ian , Jeremy and his team if they remain at the venue could try and swing some exclusive room rates. And maybe relocate the tea/coffee stations or have more smaller ones, during the breaks as this area often got crowded.
All in all as before I continue to urge people to attend it is well worth it.
Ian Barber’s Keynote speech How to Stand on the shoulders of giants
Ian’s keynote slides
out of 5 stars
Ian surely know’s his stuff, I have seen him speak before and thought that too. He used skate video production to demonstrate how the particular talents involved there improved by inspiring skaters to “land that trick” because others before them had and push things just that one bit further. He inspired with a mix of historical computing references, and obvious knowledge to encouraged people to work with and build on what has gone before. Definitely inspiring stuff and I certainly came away from it eager to do just that.
Rest and HATEOS by Ben Longden
out of 5 stars
Ben gave us a run down on the HTTP protocol and the role that plays in REST, and an example of creating a REST service, using his site (fdrop.it) as a example. It was good, there were a few takeaway messages, I learnt a bit about using media types and the role of hypermedia in a restful service and picked up the use of RestConsole a chrome add-on as a tool. I feel actually it could have been a bit more in depth about differing output formats and problems associated with, the examples of it on his site were good but that appeared to be only outputting one format type (application xml/xhtml), when we are building these services we tended to use multiple formats.
But the concepts were definitely there and presented well. Personally I did not need the lesson on HTTP protocol and hopefully others didn’t too. If people are not aware of the basics then they should be, if they call themselves web developers<rant>.
PHP Testers Toolbox Sebastian Bergman
out of 5 stars
I have used PHPUnit for quite a while and advocate unit testing to anyone so this talk was a must see for me.
Sebastian kicked off by saying he may be bias so set the tone. But overall gave a good roundup of the tools out there. I was introduced to a couple which until that time I had not heard of Atoum and Behat. I am starting to look into Behat as I feel I could use it, as I would like to do some BDD (Behaviour driven development). But ultimately this does not replace just enhances test driven development in my mind.
PHPUnit came out on top, in my opinion, of the others, and that was not because of speaker bias. Whilst the talk gave comprehensive coverage of the tools, I felt the example used to demo some was a bit weak and for others there was no example.
But ultimately introduced me to more things beyond phpunit , job done.
Note see my review on the Behat talk for more info into one of the tools.
Varnish your application Make it Fly by Alistair Stead
Alistair’s slides on Varnish here
out of 5 stars
As I was room manager for this talk I may have not got as much out of it as if I had paid full attention.
A good round up. It included code samples and good solid explanation of when to use varnish, and the types of configuration. I felt we could have had a little more on basic installation and configuration and as I am not familiar with Magento the code samples whilst good I did not quite understand where to implement them or even if they were needed at all.
All round a very good presentation and the slide takeaway is very useful (and hosted on speakerdeck a much nicer service than slideshare IMHO), I will be looking into this further.
Acceptance and Integration testing using Behat -ben Waine
Ben’s slides on Behat and as a bonus Sample code here
out of 5 stars
I thought this talk was very good, Ben presented well and gave a simple thorough understanding of a topic that to me at least is relatively new, and I think in PHP circles I am not alone. His enthusiasm was apparent through the delivery of the topic and the examples were very good and readily understandable.
A few people noted a couple of typo’s in his slides, but the fact they could spot these I think shows how well the speaker explained the facts. The slides were obviously specifically prepared for the conference and
time and effort had gone in to them.
The use of Behat was clearly show and the examples increased with complexity as the talk progressed.
Ben was obviously very knowledgeable on the topic and was also ably assisted by a colleague in the audience on a couple of questions (thankfully not too much as I feel that would have been a distraction). For me the best session of the day.
Are your tests really helping? Laura Beth Denker Etsy
out of 5 stars
I thought this talk was interesting, I have kind of admired what Etsy have done with the whole continuous deployment process. Pushing code every 20mins is certainly admirable.
Laura’s experience showed that she knows her stuff. I am not sure I was a fan of her presentation style though (personal opinion), it was a bit shouty/relaxed and sometimes confrontational. Sadly it appears others agreed with me
It was billed as “we will look at coding and testing patterns inspired by a real PHP project. We will also discuss how to identify patterns and make small adjustments where testing is and is not helping.” I did not find that. She explained she had created a code standard for monitoring testing and had a view of what should be tested which I found refreshing, I imagine seeing more of that would have helped. I was certainly interested in that part. Overall not the best of the talks on testing on the day, and it seems I attended quite a few.
In summary day 1 was excellent and after the free food and beer that followed the talks, spurned many interesting conversations with some talented phpists.
Behat BDD in php
PHP NW conference tickets on sale
This PHP North West Conference is happening again this year on October 7th through 9th in Manchester, UK. I have attended 3 PHPNW conferences and they have all been brilliant in every way. Jeremy Coates ( @phpcodemonkey) certainly has and continues to produce a great event. The conference this year will be split over two days on the 8th and 9th of October with 3 full tracks on the Saturday and 2 tracks on the Sunday. There will also be tutorials this year.
If you are into PHP I urge you to go to this event. So yet again I have purchased the blind bird ticket which went on sale yesterday.
JSP Views not rendering objects – Portlet MVC
It appears there is an extra requirement with Liferay portal at least (probably others) but this has caught me out a couple of times so I thought it was worth jotting down to prompt my greymatter when this happens again.
turns out if you want jsp’s to process expression langauge you need to tell them not to ignore it.
<%@ page isELIgnored ="false" %>
Who would have thought it.
Spring Unit tests – Maven – Application Context not loading
I more than often nowadays split my time between Java and PHP and try to adopt the best practices I know, in both areas.
This typically starts with ensuring I can carry out
- Test Driven Development
- Continuous Integration
I have just started to use a framework in Java and have opted for the Spring Framework.
Recently whilst working on a Spring Framework project – I was happily writing Integration tests and testing within the IDE and being new to the framework feeling very happy with my progress. However when I came to committing the code and running it through our Bamboo CI engine I was getting tests failing. (That didn’t fail in the IDE?)
The report showed
java.lang.IllegalStateException: Failed to load ApplicationContext
Turns out the clean I was performing (as you would ) before tests in Maven was causing an issue. So I did a bit of digging and trying to resolve.
So this is here as a reminder and help for other people with the same issue.
You need to ensure you load your files from the classpath.
My code :
@ContextConfiguration (locations = "classpath:/FormControllerTestCase-context.xml") /* Note that if no file is specified to @ContextConfiguration, it is derived as-context.xml, */ @RunWith(SpringJUnit4ClassRunner.class) public class FormControllerTestCase { private FormController controller; @Before public void setup() { controller = new FormController(); } @Test public void testIndexViewShownOnConstruction() {
And the key to it all was ensuring the context files and any associated property files were stored in /src/test/resources/
This is the default location Maven pulls from apparently.
Web losses
I was saddened when geocities closed and yet again I am saddened by the news of the latest BBC cuts which will remove lots of web real estate.
About half of the 400 stand-alone websites and webpages will close. Among the sites facing the axe are the youth-orientated BBC Switch, Video Nation and a number of forums, blogs and message boards, including the 606 community football site.
And these are digital resources containing our memories , for example literally the BBC asked the public to contribute their memories of World War Two to a website between June 2003 and January 2006…” and five years later someone has decided to bin them. The BBC’s decision to actively delete old content (rather than simply allowing it to take up some space on a server) I think is the wrong decision and it made me think what we should do with web content past it expiration date (if there is such a thing) or more likely no longer commercially / economically viable?
Convention vs Configuration in PHP?
As a programmer I often question the design paradigm “Convention over configuration” many developers I am sure do the same thing.
I really like writing code and the interesting part is solving the problems and acknowledge some of it is not interesting.
More and more I find myself coding by convention as I rely on framework code.
I do this a lot in Java, largely because of the lack of underlying knowledge, I still have to think quite a lot about the basics, but with PHP this is different, so I thought I would write down my thoughts on the whole thing, so next time I question should I do this I might look back and take my own advice.
I have created a lot of stuff and earned my badges creating a lot of the standard design patterns from scratch.
So once you have solved the basic problem should I revert to some ready made solution, that is likely to have done it better than I had anyway.
If I need to build a quite large complex system or even one that I know is going to grow quite significantly. There are a number of advantages to using a framework, for the reason I can use other well tested code to achieve large proportions of the functionality,but largely to me code organisation and separation of concerns are the big pluses.
As I write a lot of stuff for internal use and most of the stuff is going to integrate with other systems I seem to have a knack of finding the quirks that make that hard work using the framework code, on both sides, there is a enough to do anyway.
So if I am writing a system should I use a framework — YES
If I am writing a small script forget it – even though I am tempted.
As to which, well that depends on the current trends and functionality you need.
I was not wrong – WordCamp a round up
Having attended WordCamp last weekend, and tried to embrace it with the attitude I will do as much as I can to listen,learn,help and have a good time. I can confirm it did not disappoint.
Not quite sure what the core organisers prefer to call it but this is a conference in my book, it is billed as a mix between that and an un-conference, and now a must on my conference calendar and should be for anyone interested in WordPress.
It was a good weekend, and I am thoroughly pleased I attended, first the downsides, the un-conference bit did not really work in the venue. A series of lecture theatres do not make a good space for conducting an un-conference, it did not seem to flow and made it difficult I felt to run the sessions I did (WordHack). I also felt the quality of some of the presentations I attended could be improved but personal opinions and all that.
Overall the venue was well organised, credit has to go to Chi-chi Ekweozor for that I think, who was tireless and ensuring people’s needs were met. There were certainly a few highlights for me which could be summarised as
- WordPress in the Enterprise II (David Coveney) from Interconnectit
- Working with some awesome people on WordHack
- Being introduced to Custom Posts
- Some interesting stuff from Peter Westwood – one of the core developers
- being stimulated to think about BuddyPress – even though I did not attend any sessions on it

Oh and of course WordHack was an excellent adventure- that produced a whole self sustaining WordPress based site in a very limited amount of time, more can be learn’t about the process on the wordcamp wiki and the actual site is live at openaid.org.uk
So overall I think it was a good event, made so by the people involved. I will certainly be looking to go again next year.
If any one is thinking of getting involved with Wordcamps I would recommend it. As would I that you look out on wordpress.tv for videos from the weekend.