A year of CodeClubbing at Malin Bridge Primary School

CodeClub logoI have just recently realised that I have been leading my CodeClub at Malin Bridge Primary School for a year now! How the time flies! I have seen kids coming and going, some of them returning back and a few of them keep attending our sessions week by week, hardly missing any of it! Right now I have a real mixture of kids with different experience, abilities and age. And all of them have a real passion when it comes to do codeclub projects – some of them continue to work and experiment with what they have done during our sessions afterwards at home!

I am gonna use this opportunity to show some of the brilliant piece of work they have created. I have spent quite a lot of time playing and trying to figure out what they have done and enjoyed it thoroughly. While some of them might seem to be not complicated at all, please remember they were created by kids 8-11 year old!

The best of Malin Bridge CodeClub 2013-2014

Dom Gun Game

A shooter game. Use your mouse to shoot. You have got 50 seconds to score as many points as possible.


Back To The Future style

This is an animation of a scene from Back To The Future Movie. Only mentioning it, because I am a huge fan of Back to The Future Trilogy and it made me laugh so much!

Hover Robot

These 2 games were created by Jack. A brilliant usage of a fluent hovering of a sprite. I was astonished with the end result!

Use the arrow keys on your keyboard to try and keep the robot flying on the screen.

Donut Game

Use the arrow keys on your keyboard to place the small donut inside the big one. What I love about this game is the fact that Jack have tried to add some instructions at the start to hint how you are supposed to play the game.

Fish Chomp

Use your mouse to control the big fish and eat as many prey as possible within 30 seconds. Score as many points as possible! This is one of the games we have in CodeClub curriculum. What is special about it is the fact that Jacob went an extra mile and added so many more prey and made all of them look differently.

jBounce

This game is brilliant. I actually had to ask the author how am I suppose to play it, cause it wasn’t that obvious at first. There are 3 objects hidden behind the balls: a laptop, a bowl of chips and a monster. Click on them to score the points. The bouncing balls will not make it easy though and you only have 30 seconds to do that. A hint… the laptop is a decoy and there are actually 2 bowls of chips. Chips are worth 1 point, monster – 5 points.

Whack a Witch

Another game from CodeClub curriculum. Featured here because of the fact that Oliver have put so many witches in the game and customised them. Use your mouse to click on the witches and score points.You have 30 seconds to do that. Faster and smaller witches score more points so look out for them!

Cheesy Paint Brush

Yet another project from CodeClub curriculum. This time an application. Be afraid Microsoft Paint, the Cheesy Paint Brush is coming! Use your mouse to select options in the toolbar below the board. You have a choice of a pencil, stamp and a rubber. You can draw in 13 different colours, including a rainbow pencil. How cool is that! You can also use a rubber to clean a part of your picture and control the thickness of your pencil.

Cheese Monster

Meet the Cheese Monster. But do not be afraid. You can control him using the left and right arrow keys on your keyboard. Press space to make the monster talk… or click the ‘press to talk’ button in the top right corner to say something to the monster. If you say something nice to him, he will be nice to you – try “Are you my friend?”. But if you are nasty and tell him “You smell!” – well you do that at your own risk. He is watching you… watch his eyes as you move you mouse around him…

Angry Birds

This was a big surprise to me. Apparently the kids use Scratch now in the IT curriculum. And they have created this game. Click the green flag to start the game. Specify the angle you want the red bird to fly and hit the green pig.

What the future holds

After Easter, we are gonna start the Web and CSS curriculum with the most experienced kids. And to make it even more fun we are gonna do that using the Raspberry Pis we have received. So watch this space!!! I am sure the kids are gonna get even more creative!

Malin Bridge Primary School CodeClub dancing robots

Let’s Robo-Boogie!

Last week at Malin Bridge Primary School we took part in Robo-Boogie CodeClub competition. Robo-Boogie competition is organised by CodeClub - a nationwide network of volunteer led after-school coding clubs for children aged 9-11. The web application they have released allows kids to create dancing robots and share they work with the others. I think we must have created about 50 different dancing robots, out of which 20 got submitted for voting. There are some examples of brilliant code engineering. Please have a look at some of the robots we have created and vote for the ones you like the most and help the kids win some awesome prizes!

The voting is open until midnight of 26th November 2013.

 

 

CodeClub a sprawa polska

CodeClub logoThis will be a post mainly targeted at polish community, to explain more about CodeClub, CodeClub World and what we could do to promote the idea in Poland. Therefor it’ll be easier for me to do it in polish. So apologies to all non-polish speaking readers.

Co to jest CodeClub?

Zacznijmy więc może od początku. Cóż to jest ten CodeClub? Idea powstała jakieś 2 lata temu w Wielkiej Brytanii, a za tym wszystkim stoją 2 panie - Clare Sutcliffe i Linda Sandvik. W tym wszystkim chodzi o to, żeby zachęcić dzieciaki do programowania i dać im okazję spojrzeć na komputer z troszkę innej strony. Przeważająca większość dzieci (i nie tylko dzieci) traktuje komputer jako narzędzie do nauki lub/i zabawy, i nie zdają sobie sprawy z tego, że naprawdę niewiele trzeba, aby samemu móc przejąć kontrolę nad komputerem i napisać swój własny program. Program skierowany jest do dzieci w wieku 9 – 11 lat, które w trakcie zajęć tworzą gry i aplikacje interaktywne.

Jak to działa?

Jak już wspomniałem wcześniej, wszystko zaczęło się w Wielkiej Brytanii i skierowane było do dzieci mieszkających na Wyspach Brytyjskich, ale okazało się na tyle popularne, że parę miesięcy temu ideę zaczęto promować na całym świecie, i tak właśnie powstał CodeClub World. Ale wróćmy na moment do tego jak to funkcjonuje w Wielkiej Brytanii. Pierwszy raz usłyszałem o CodeClub na konferencji PHP w Londynie, w lutym zeszłego roku. I w ciągu niecałych 2 miesięcy udało mi się założyć taki klub w szkole do której chodzą moje dzieci.

Kluby prowadzone są przez ochotników, którzy poświęcają na to 1 godzinę tygodniowo na prowadzenie samych zajęć, plus około 1 godziny dodatkowo na przygotowanie się do tych zajęć. Zajęcia są całkowicie bezpłatne, prowadzone na terenie szkoły, po głównych zajęciach. W Wielkiej Brytanii, w szkole podstawowej zajęcia odbywają się od godziny 9 rano do 15:30 popołudniu, ale w wielu szkołach są organizowane zajęcia dodatkowe, po szkole. I w tym właśnie czasie odbywają się również zajęcia CodeClub. W UK jest około 21 tyś szkół podstawowych, i CodeClub robi wszystko co może, żeby dostać się do każdej z tych szkół. Na dzień dzisiejszy, zarejestrowało się 1375 klubów, więc jest jeszcze dużo do zrobienia, ale CodeClub staje się coraz bardziej popularny, i z dnia na dzień przybywa coraz więcej klubów. Idea jest wspierana przez takie firmy jak: Google, Mozilla czy ARM, a patronat honorowy objął nad nim nawet Jego Królewska Wysokość Książę Yorku. W promocję CodeClub zaangażowały się nawet takie osoby jak Niklas Zennström (założyciel Skype’a), Chad Hurley (założyciel YouTube) czy Tim Berners-Lee (twórca WWW!) . Film poniżej wspaniale to obrazuje.

Po zarejestrowaniu klubu, otrzymujesz dostęp do wszystkich materiałów potrzebnych do prowadzenia klubu. Przykłady takich materiałów, możecie znaleźć tutaj:

Szkoła udostępnia salę z komputerami oraz wsparcie pedagogiczne oraz pomaga w przygotowaniu do zajęć – drukowaniu materiałów, rozpromowaniu klubu, itd. Materiał zawiera wszystkie rzeczy potrzebne do przeprowadzenia zajęć – skrypt, który dzieci używają do napisania gry/programu krok po kroku, informacje dla prowadzącego jak przeprowadzić zajęcia oraz dodatkowe materiały (jeżeli są potrzebne) – pliki graficzne, dźwiękowe, cokolwiek, co się przyda w trakcie zajęć.

Prowadzący musi się jedynie zgłosić na czas w szkole, pomagać dzieciom w trakcie zajęć i generalnie dobrze się bawić. Bo w tych zajęciach, głównie chodzi o naukę poprzez zabawę.

Używane oprogramowanie

Dzieciaki zaczynają pierwszy semestr tworząc gry przy pomocy programu Scratch. Jest to darmowy program który można pobrać ze strony projektu i zainstalować na komputerach w szkole.

 

Programowanie polega na układaniu klocków, symbolizujących różne struktury kodu. Działa to podobnie jak puzzle – nie wszystkie klocki pasują do siebie, wszystkie klocki są podzielone ze względu na funkcjonalność i wyróżnione odpowiednim kolorem.

Tak więc, mamy do dyspozycji pętle, zmienne, warunki, możemy kontrolować klawiaturę i mysz oraz interakcje między obiektami na ekranie. Niektóre skrypty mogą być naprawdę skomplikowane, ale wcale nie takie trudne do stworzenia.

W drugim semestrze, projekty Scratch stają się bardziej złożone, ale równocześnie dzieci mają większą swobodę działania, co zachęca ich do eksperymentowania. W trzecim semestrze przechodzi się do tworzenia stron WWW – używając HTML-a i CSS, a w czwartym zaczyna się już prawdziwe programowanie w Pythonie. To wszystko jest jeszcze przede mną, ale jasno widać jak wszystko jest zaplanowane do przodu.

Semestr jest jedynie logicznym podziałem i wcale nie musi odnosić się do semestru szkolnego. Wszystko zależy jak dzieci sobie radzą – są tacy którzy “łapią” wszystko bardzo szybko, a są takie dzieci które potrzebują więcej czasu aby zrozumieć pewne rzeczy. Także, w pewnym momencie może się zdarzyć, że dzieci będą pracować nad różnymi projektami w trakcie tych samych zajęć. Poszczególne semestry podzielone są na poziomy – po skończeniu każdego poziomu dzieci nagradzane są certyfikatami.

Rejestracja klubu

Rejestracja klubu jest banalna. Najpierw trzeba znaleźć szkołę w której chcecie rozpocząć prowadzić zajęcia. Jeżeli nie wiecie w jakiej szkole możecie zacząć prowadzić zajęcia, skorzystajcie z wyszukiwarki na głównej stronie CodeClub. Wpisujecie tylko kod pocztowy i w jakim okręgu chcecie znaleźć szkołę.

Następnie skontaktujcie się ze szkołą – najlepiej umówić się na spotkanie z dyrektorem i omówić szczegóły. Zanim rozpoczniecie zajęcia, musicie pozytywnie przejść sprawdzenie CRB (Criminal Records Bureau). Generalnie szkoła musi się upewnić, że nie macie żadnej przeszłości kryminalnej, szczególnie jeżeli chodzi o kontakty z dziećmi. Większość szkół bez problemu zrobi wam to na miejscu. Alternatywnie można przystąpić do programu STEM Ambassadors, która też wam w tym wszystkim pomoże.

Następnie, trzeba zarejestrować swój klub na stronie CodeClub – https://www.codeclub.org.uk/quick-registrations/new.  Pamiętajcie, że tak to wygląda w przypadku rejestracji klubu w Wielkiej Brytanii. Jak zarejestrować klub w Polsce powiem wam poniżej.

Po zarejestrowaniu klubu, uzyskacie dostęp do materiałów i… możecie zaczynać. Trzeba tylko wydrukować materiały i przyjść na zajęcia. Przed każdymi zajęciami polecam przeczytać wszystkie dokumenty. Bardzo one pomogą w zrozumieniu jak zacząć klub, jak podchodzić do dzieci, itd. Warto również samemu ukończyć każdy projekt przed zajęciami, żeby zrozumieć na czym on polega i być w stanie odpowiedzieć na pytania dzieci i im pomóc.

CodeClub a sprawa polska

Pozostaje więc pytanie, jak możemy poprowadzić taki klub w Polsce? Po pierwsze podstawowym źródłem informacji będzie strona CodeClubWorld - http://codeclubworld.org/. Jeżeli chodzi o materiały, to zacząłem tłumaczyć je na język polski. Wszystkie materiały są dostepne na koncie GitHub - https://github.com/CodeClub. Polskie tłumaczenie jeszcze tam nie jest dostępne, ciągle nad nim pracuję, ale w ciągu następnych dwóch tygodni spodziewam się, że tłumaczenie już się tam pojawi. Do tego czasu, możecie je sobie pobrać z mojego forka - https://github.com/proofek/scratch-curriculum.

Tutaj mam mały apel o pomoc. Potrzebuję kogoś, kto będzie wstanie przejrzeć przetłumaczone materiały i potwierdzić, że są OK i nadają się do użycia. Jeżeli ktoś jest chętny pomóc to bardzo proszę o kontakt na Twiterze.

Następna sprawa, która boję się że będzie trochę bardziej problematyczna, to jest kwestia znalezienia szkoły, która będzie chętna poprowadzić takie zajęcia. Niestety tutaj mam ograniczone pole działania, bo nie mam żadnych znajomych w polskim systemie edukacji.  Muszę tu troszkę znów liczyć na waszą pomoc. Trzeba by odwiedzić jakieś szkoły, porozmawiać z nauczycielami lub dyrektorem i dowiedzieć się jak to można zorganizować. Nie mówię, że będzie prosto, ale z właściwą determinacją na pewno uda się coś osiągnąć. Takie kluby działają w takich krajach jak: Rosja, Ukraina, Rumunia, Bułgaria, Dania, Turcja, Grecja czy Chorwacja. Coś musi się dać zrobić. Jeżeli uda się wam coś dowiedzieć to bardzo proszę o kontakt. Może jesteś nauczycielem albo pracujesz w kuratorium albo ministerstwie edukacji. Jeżeli nie uda się w szkołach, to może da się to zorganizować w trakcie zajęć na świetlicach, albo może uda się zorganizować jakieś zajęcia przy pomocy urzędu miasta.

Uważam, że naprawdę warto jest rozpromować ideę CodeClub i się w nią zaangażować. Nie dość, że jest to świetna zabawa to na pewno pomoże w edukacji naszych dzieci, a być może w przyszłości niektórzy z nich zostaną programistami. Kto wie!?

Referencje

SugarCRM relate field vs 1-2-many relationship

I have been using studio to add custom relate fields to my modules, but until now I wasn’t really aware of its downsides. It seems that Studio is making really nasty shortcuts when it creates a relate field which impacts the ways you can access related fields from the API for example. And when I say impacts, it means it’s basically impossible. So let’s have a look what Studio does when you add a relate field.

Studio creates 2 fields: one called related_user_c and one called user_id6_c. Here are their definitions:

They are linked together via the id_name element of the related_user_c definition. After ‘Repair and Rebuild’ we gonna end up with an user_id6_c column in the table. It all seems to be working well, until you try to use the SugarCRM API. There is now way to fetch data from the related field in one API call. All you can do is to fetch the id from the user_id6_c column and then knowing that it actually links back to Users module fetch the details. It’s all because Studio did not create a proper relationship with the Users module. So, let’s have a look how we could do it with a 1-2-many relationship built in code. Instead of using the studio, let’s just build the required fields manually in the code. For a brand new module I recommend you do that in the modules directory –  modules/<module_name>/vardefs.php, for an existing one create a file in custom/modules/Accounts/Ext/Vardefs/. I prefer to have every field definition in a separate file. It’s up to you. You will need 3 fields – one storing an id in the database – related_user_id, one is gonna be a relate field used on the forms to present the field – releted_user_name and the final one is gonna be a link, that API can use to fetch related record details - requested_by_link. They will roughly look like this:

Please note the fields are linked to each other - releted_user_name links to the releted_user_id field using id_name element and links to the releted_user_link field using link element. releted_user_link field links to releted_user_id using id_name element and links to a relationship called accounts_related_user using relationship element. This relationship doesn’t exist yet, we still have to create it. It’s gonna roughly look like this:

Again, note that it links to the releted_user_id field via rhs_key element.

 

Now when you repair and rebuild the field will be added to the database and you can add it to your views – edit, details and list views. And most importantly you can access the related field details through the API, by using the link we have created – just pass it through using link_name_to_fields parameter in your request, something like this:

SugarCRM 1-2-many relationship with no middle table

In SugarCRM, when you create a relationship, and it doesn’t matter whether it is a 1-2-many or many-2-many relationship, it always creates you a middle table. Which is kinda annoying, since for 1-2-many relationships you don’t really needed. And when I say middle table, I mean a link table between 2 tables.

It’s the best to describe that in a real life example. Let’s assume, you want to start storing in Sugar your suppliers details and their contact details. What you would normally do, you would create a Suppliers module to store the supplier details – the name, address, contract details, etc and a ContactDetails module to store information about different ways you can contact the supplier – so type of contact details and a value. Then you would create a 1-2-many relationship between them 2:

Now, when you look in the database, Sugar is gonna create for you the 3 “nice” tables:

But, what we really want is 2 tables with a “foreign” key in the contact details table, something like this:

Fortunately, it’s not that difficult. Searching google for a solution brings a few posts. Me personally I have based on 2 posts by John Mertic from SugarCRM:

The problem is, they cover the topic well in terms of concept, but you can’t really follow it step by step, at least not without a good understanding of SugarCRM as a development platform. It took me several hours to match all the dots together, before I made the whole thing work. And that’s because I simply did not understands some of the things John did there (and I am not quite sure whether I understand it now). So here’s the step by step guide, that I follow, and my understanding how it all works. I assume you already have the 2 modules created, and what we will do now, is just create the relationship between them so Sugar modifies db schema for us, add the panel to the parent module so we can see associated records on the Suppliers screen and modify the panel so we can create new records using quick create form.

1. Step 1: Create the relate fields

First we will create fields required for the relationship: the id field and relate field. Create a new file called SupplierRelate.php in custom/Extension/modules/Demo_SupplierContactDetails/Ext/Vardefs/ and define the 2 fields in there as below:

There is a few things you have to pay attention to. First of all make sure the module name is correct in the $dictionary array. In my case it is Demo_SupplierContactDetails, following the convention of <PackageName>_<ModuleName> – I named my package Demo and the module SupplierContactDetails. Next the field name is really important and it has to follow the pattern of <ParentBean>_<FieldName>, so in my case it is demo_suppliers_name and demo_suppliers_id (all lowercase). If you don’t do it right, later on the quick create form is not gonna work. If you change the values in the field definitions to match appropriate parent module name, everything should be fine. Take a note of name and id_name in demo_suppliers_name field definition and name in demo_suppliers_id field definition. The relate field (‘name’ one) we will be using to associate SupplierContactDetails data with a parent supplier, while the ‘id’ field will be used to alter the demo_suppliercontactdetails table and add the parent id column in there (which will be called demo_suppliers_id)

2. Step 2: Define the relationship

Next, we will define the relationship. Will do that in the same file, as follows:

First is the link to the relationship – note the relationship element of the first array that is used below for the relationship definition itself and module and bean name of the parent module.  Secondly note the 2 sides of the relationship in the relationship definition – the left hand side (lhs) pointing at Demo_SupplierContactDetails table and demo_suppliers_id key (the same name we have define above in the id field definition) and right hand side (rhs) pointing at Demo_Suppliers table with id key.

To complete the relationship we also have to define the link in the parents module. So let’s create another file called SupplierContactDetailsRelate.php in custom/Extension/modules/Demo_Suppliers/Ext/Vardefs/:

Note the module name in the $dictionary array which point at our parent module Demo_Suppliers, the name of the field that point at the child module (although I am not sure whether it is important, but I guess even for clarity and readability it is worth to stick to it) and finally the relationship name which has to be the same as the one we have used in the definition in the child module above.

3. Step 3: Add missing labels in the language pack

Don’t forget about the label definitions. I only care about en_UK packs so I have added the new label definitions into:

  • modules/Demo_Suppliers/language/en_UK.lang.php
  • modules/Demo_SupplierContactDetails/language/en_UK.lang.php

That includes:

  • ‘LBL_SUPPLIER_NAME’ => ‘Supplier name’,
  • ‘LBL_SUPPLIER_ID’ => ‘Supplier ID’,
  • ‘LBL_SUPPLIERS’ => ‘Suppliers’,
  • ‘LBL_SUPPLIER_CONTACTDETAILS’ => ‘Supplier Contact Details’,

4. Step 4: Repair and rebuild

Now, when you go to the admin panel and run Quick Repair and Rebuild Sugar will generate the SQL query you need to run to alter the child table (instead of creating the middle table):

and achieve what we wanted from the very beginning, no middle table.

5. Step 5: Add relate field to SupplierContactDetails layout

But, that’s not it. While we have created the relationship, we can’t associate the records together yet. First thing we have to do, is to add the newly created relate field (Supplier name) onto detail, edit, quick create and list view of the Demo_SupplierContactDetails module. You can easily do that via Studio:

Now we can easily associate and see the parent record information.

6. Step 6: Create the subpanel for Suppliers module

The final step will be to add subpanel in the Suppliers module, so we can easily see the associated records and create them from within the same module. All we have to do is create a new file called demo_suppliercontactdetails_subpanel.php in custom/Extension/modules/Demo_Suppliers/Ext/Layoutdefs/ with the following contents:

Once again, note the name of the subpanel in $layout_defs array – demo_suppliercontactdetails (although I don’t know whether it has to match the child module – again will definitely make it easier to understand what the panel is for), module and get_subpanel_data need to point at the child module. It’s extremly important that get_subpanel_data points at the child module, otherwise no data will be retrieved. And finally top buttons will allow us to create new contact details record using quick create form. I have also added the label to modules/Demo_Suppliers/language/en_UK.lang.php and run ‘Repair and Rebuild’.

But that’s not it. We now have to define the subpanel itself. Create a brand new file called Demo_Suppliers_subpanel_demo_suppliercontactdetails.php in custom/modules/Demo_SupplierContactDetails/metadata/subpanels/. It’s very important that this filename matches the name of the subpanel defined in the file above – Demo_Suppliers_subpanel_demo_suppliercontactdetails, and follows the pattern I used. If you live that file empty (with only opening php tag at the top) you will be able to go into Studio and drag the columns you want on the subpanel and simply click ‘Save and Deploy’.

 

The file will then look something like this:

Please note the 2 elements of the array at the bottom – edit_button and remove_button. Studio won’t have them on the column list – I have added them manually afterwards. These 2 buttons will allow you to edit and delete a record on the list. And so here it is our completed subpanel:

and the quick create form (I have already tweaked it in Studio to show only relevant fields):

Note: I have noticed, that the remove button actually doesn’t work. Will have to find out why.

The first rule of Code Club is ALWAYS talk about Code Club!

CodeClub

 

So I do! The first time I have heard about Code Club was about 2 months ago at PHP UK Conference in London. Aral Balkan has mentioned it in his talk and immediately got my attention. We’d had a lengthy discussion about it as I thought it’s a brilliant idea, and decided that I want to get involved and support it.

In short, Code Club is a nationwide network of free volunteer-led after-school coding clubs for children aged 9-11. It is an amazing project co-founded by Clare Sutcliffe and Linda Sandvik in April 2012. I believe it is a brilliant idea and a perfect way to promote programming and software engineering amongst young people. Otherwise how are we going to get more people involved into development?! You can read a bit more what the Code Club is all about at their website - http://www.codeclub.org.uk/about. We are using Scratch - a programming language that makes it easy to create interactive stories, animations, games, music, and art.

As I have my 2 kids at a local primary school – Malin Bridge Primary School in Sheffield, what would we be a better place then to start there. So I got in touch with the Head Teacher – Stephen Betts, during a PTA meeting, explained what a Code Club is and that I wanted to start one. He loved the idea and with a lot of help from Steve Green, a school teacher and extended earning coordinator, we have set up the first Code Club session to happen on Wed, 17th April – which is today!

Malin Bridge Primary School

Despite the fact that I already have a bit of experience in public speaking, I was quite nervous and stressed. Wasn’t quite sure how I am gonna handle a group of children in front of computer screens and make them listen to me and follow the instructions. But I got a lovely group of 11 students from year 5 and 6, who I believe have had a lot of fun and were very excited about the prospect of being able to create a computer game. I must admit, this first session, got a little bit out of hand, as everybody was trying to make their work unique and therefor the kids needed a lot of my attention when something was going the wrong way, but the end result is astonishing. You can see what the kids have created so far at the Scratch website – I was amazed with the amount of imagination that went into that work, and to be honest I am really curious how the game is going to look like at the very end.

So, please, if you are a developer, why don’t you start a Code Club at your local school? It’s very easy – all you have to do is:

Code Club provides all the materials that you will need to run the Club – you will get access to them once you register your club. You don’t need a lot of time to do that – a few hours initially to go through the process of setting it up, and after that, an hour a week to lead the club and probably about an hour just to prepare to your next session. Well… there is one thing they don’t tell you. Make sure you have a bottle of water with you. Today, I could hardly speak after the session :D

Finally, I’d like to say a big thank you to my employer – EMIS. I can work in such hours, that I can easily come to school and lead the after school club. I wouldn’t be able to do that without their support.

Test your code like a pro – PHPUnit in practice – preparation guide

As promised, here’s a quick guide that will allow you to prepare for my “Test your code like a pro – PHPUnit in practice” tutorial at PHPNW12 conference in Manchester on 5th October. If you still haven’t decided whether to go or not have a look at the official abstract and my previous blog posts. There is still time to get the tickets!

There are really 2 things that you will need, to get smoothly through the tutorial: git client and working installation of PHPUnit. So please make sure you have installed them and you can use them. Being able to open PDF files is also recommended as I will be giving out a tutorial’s manual/instructions in a PDF format.

Well this above obviously requires a computer. I guess you will decide to bring a laptop with you, although if you prefer to take your desktop computer with you, it will do too. While most of the stuff will be in the PDF file, going through the tutorial without a laptop will be difficult to follow and you will not learn as much. I will not have any spare laptops to borrow, sorry.

I strongly discourage brining in a Windows machine with you, unless you feel comfortable with solving any problems related with php, pear and PHPUnit in a very short period of time or you come really well prepared. We will not have a lot of time to spend configuring each other machines and we also don’t want the others to wait and do nothing while you set everything up. We only have 3 hours, and believe me it will go fast.

Ubuntu/Debian

git

Using apt to install git should set you up pretty quickly. Just type in the below:

$ sudo apt-get install git-core
$ git --version

PHP

You will need at least PHP 5.3.3 installed, but I strongly recommend installing PHP 5.4. Again with apt it should be pretty instant to get you set up:

$ sudo apt-get install php5-cli
$ sudo apt-get install php-pear
$ sudo apt-get install php5-xdebug
$ php -v

PEAR

Before you can install PHPUnit you need to make sure PEAR is at the latest version. So upgrade it first

$ sudo pear upgrade PEAR

PHPUnit

Then finally you will be able to install PHPUnit:

$ sudo pear config-set auto_discover 1
$ sudo pear install pear.phpunit.de/PHPUnit
$ phpunit --version

Windows

git

You can install git client on a Windows machine by using the installer package that you can download from msysgit project downloads page.

Just accept all the default options. All you really need is to be able to clone a repo and change branches.

PHP

  1. First download PHP 5.4 binaries from http://windows.php.net/ and unzip it into c:\php.
  2. Then download xdebug library from xdebug downloads page and copy it over to c:\php\ext directory.
  3. Rename the library to php_xdebug.dll.
  4. Copy c:\php\php.ini-development to c:\php\php.ini
  5. Make sure date.timezone is set to “Europe/London”
  6. Activate xdebug by adding the snippet bellow at the end of c:\php\php.ini
  7. [xdebug]
    zend_extension=ext\php_xdebug.dll
  8. Add c:\php to system path via Computer’s Advanced Properties -> Environment Variables
  9. Restart windows
  10. In the command prompt run:
  11. c:\> php -v
    PHP 5.4.7 (cli) (built: Sep 12 2012 23:48:31)
    Copyright (c) 1997-2012 The PHP Group
    Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies
        with Xdebug v2.2.1, Copyright (c) 2002-2012, by Derick Rethans

PEAR

Next we have to install PEAR.

  1. Download go-pear.phar from http://pear.php.net and copy it over to c:\php\
  2. Run the following command and from the presented options change option 1 - Installation base to c:\php and option 11 - Name of configuration file to c:\php\pear.ini
  3. c:\> php c:\php\go-pear.phar
  4. Then hit enter to finish installation
  5. Let installer change your include path at the end by answering y to the question “Would you like to alter php.ini?”
  6. Double-click the PEAR_ENV.reg file in c:\php
  7. Reboot again to make sure PEAR_ENV registry entries have taken effect

PHPUnit

Finally it’s time to install PHPUnit. At this point just running the below should set you up.

c:\> pear config-set auto_discover 1
c:\> pear install pear.phpunit.de/PHPUnit

c:\> phpunit --version
PHPUnit 3.7.0 by Sebastian Bergmann.

If at any point you have a problem with installing it all on Windows please drop me an email. You can also have a look at Stu Herbert’s blog post about Getting PEAR working on Windows 7

I hope this short guide will let you come to my tutorial well prepared. I will see you in Manchester soon!

The Grumpy Programmer’s Book at PHPNW12

I’ve got some good news for the people that already have decided to attend my tutorial “Test your code like a Pro – PHPUnit in practise” at PHPNW12 conference in ManchesterChris Hartjes has kindly offered to give away 3 digital copies of his famous “Guide To Building Testable Applications in PHP” book to attendees of my tutorial! I strongly believe this will nicely compliment the tutorial itself and give the people such a boost in their further adventures with testing. You can learn more about the book itself at http://www.grumpy-testing.com/.

Your still have a chance to get a ticket to my tutorial on 5th October and only one more reason to buy it! For these who already know PHPUnit and already have started they journey through unit testing PHP code I strongly recommend buying the book and reading it. There is plenty of hints and tips that will help you understand how to write unit testable code and increase its quality!

Big thanks to Chris again and I hope to see you all in Manchester soon!

Test your code like a pro – PHPUnit in practice at PHPNW12

PHP NW12 conference is nearly upon us, so I guess it’s about time to tell you more about the workshop that I will be having there on the 5th October morning. I wanted to do that for a very long time, especially that I am a big fan of quality assurance in software engineering. You can read the official abstract at the conference homepage, but here I am gonna tell you a little bit more about what we gonna do during the 3 hour tutorial.

My main focus will be to teach you and lead you through main concepts of unit testing PHP code. It’s a beginners course, so we will go though all the basics of organising your test suite, understanding the benefits of unit tests and making you feel comfortable and confident with the code you write. We’ll do it all big band TDD style – so we will write the tests first and implement the functionality afterwards. It’s very important to get this right and to set up the mindset from the very beginning.

PHPUnit is de-facto a standard in PHP world, so it is also important that you are aware of the main features of the tool. We’ll go through the set up, configuration and options that are the most useful at the beginning – so you can get the most out of the tool. The concepts that I am gonna go through will include:

  • working with typical test suites
  • basic assertions – strings, integers, booleans, object
  • PHPUnit from the command line
  • using phpunit.xml configuration file
  • testing exceptions
  • testing PHP errors, warnings and notices
  • asserting output
  • data driving your tests by using data providers
  • generating code coverage report

If you have never had a chance to unit test your code, but you’d like to try now, it’s the best time to get started. I will do my best to make you feel confident and to help you start your own Journey Towards Continuous Integration, but what you have to do is to go to your boss and convince him to buy you a ticket to my tutorial ( and the conference). There is still plenty of time and there are still some tickets left.

No matter whether you have already bought a ticker or you’re thinking about right now, if there is anything specific you you want me to go through during the tutorial please let me know. I’ll do my best to fit that in. We can also change the course of the tutorial if the group will prefer to touch on some slightly different subjects of unit testing – I am open for suggestions. And I will be accessible after the tutorial too, for any questions, help or even quick hacks. You will even get more chances to speak to me over the next 2 days, during the main conference days – on the 6th and 7th October.

It’s a lot of things to go through so it is very important that you come prepared and focused on the day. We only have 3 hours and I’d like to avoid situation where the hardware/operational issues will stand in our way. While I will try to help everybody out if there are any issues I will encourage you to install PHPUnit on your laptops before, so it is working without a problem. I want to focus on writing the tests and using PHPUnit, not on trying to make PHP itself working on your machines.  I strongly recommend using a non-Windows system. Windows has been proved to be very unreliable if it comes to setting up PHP and PEAR. It does work, but it requires some strong skills and patience. So you’d rather install ubuntu or debian, as this is an environment that everything just works out of the box.

During the course of the next 2 days I will post more detailed instructions about how you can prepare your laptops to make sure you can run PHPUnit on them without any issues, so watch this space closely.

I hope to see you at my tutorial in about 3 weeks!

Symfony2 Live! London – aftermatch

Symfony Live LondonI am sitting on the train back to Sheffield coming back from an awesome Symfony Live London event. It was my first time at Symfony Live conference, and at the same time it was first edition of the conference held in London. Conference was organised perfectly, but was else could you expect from  people like Lorna Jane and Wes Thompson! Great event guys and very well done!

For a person like me, who only started working with Symfony2 a few months ago, it was a mind blowing mine of information about Symfony2, tools that support symfony2 applications like composer and behat and general practises around using the framework itself. I was pretty impressed by the fact how Drupal8 and Symfony2 work together, and get the famous CRM event better. It definitely proves that PHP as the language, environment and surrounding community matures. The talks in fact were only the background of the opportunities that I had today – meeting in person and being able to talk to people like Fabien Potencier (creator of Symfony2), Jordi Boggiano (the man behind composer), Konstantin Kudryashov (the Behat man) and Marcello Duarte (the PHPSpec man). The conference venue was all buzzing – people talking and exchanging experiences.

I have seen 6 talks in total:

Every talk was unique and touched on different subject, but I have to admit Konstantin and Marcello just blown my mind off with they approach to testing with BDD. I still can’t get all the things together and they gave me plenty of things to think about. The next thing I will do will be to replicate what they have done with Behat and PHPSpec2 during their presentation.  I do not agree with what they have said about unit testing, and I still believe that unit testing has it’s own place in the development processes, just needs to be used right and for the right purpose. For me the BBD way they have shown us it’s a different approach to testing only complementing xUnit. Anyway have a look at their slides and at Behat and PHPSpec2 if you haven’t yet. PHPSpec2 is still pre,pre,pre,pre,pre,pre,pre,[pre,] alpha, but looks really promising and I can see myself including it in my toolset.

Finally, I’d like to thank everybody who attended my talk Effective Code Reviews and asked all the questions afterwards. It’s been a pleasure to be able to meet you all and exchange all the experiences around code review process. Thanks to everybody who left the feedback on joind.in, and if you have seen my talk and not yet gave me the feedback please do so. It’s very important for me to know what did you like and what not, so I can improve it in the future.

Enough writing, I am too excited about Behat and PHPSpec2 so I am gonna download it and play with it for another hour, and I hope to meet you all again in a year time at the the next Symfony Live! London Conference!