Events: PHPUnit Code Sprint

Last week Friday/Saturday I had the privilege to join PHPUnit Code Sprint. It was a rather small event with only six people, but the competence was huge.

I expected something like our FireGento hackathons, but due to the small group, we started with an introduction how PHPUnit was the last years and then Sebastian Bergmann started to introduce us to a couple of problems he brought with him. But as expected he didn’t make it to the second, because everyone was already thinking about how to solve the first and we started a lovely mob programming session.

Filter --list-tests and --list-tests-xml

The first task was to add filtering by test names an groups to --list-tests and --list-tests-xml. And it was a deep dive into PHPUnits inner workings. Did you know, that before today PHPUnit did filter during test running, which means there was no way to easily use it for --list-tests? But we split it up and because the filtering was already implement, it worked with --group as well 🎉

We had a short lunch break – thanks to celebrate for the food and the location! And hopped right back into the code after the break by implementing more tests and hardening the setup, especially regarding PHPT tests. You don’t know what PHPT tests are? It is the format PHP uses to test it’s core system and PHPUnit is using to test it’s inner workings. It is an implementation detail and I didn’t know there is a PhptTestcase, but we learn something new every day.

Rabbithole: hrtime()

And then we fell into a deep rabbit hole. I never heard of hrtime() but it is a method in PHP to get a time from the operating system. The assumption is, that the return value is monotonic, but for some reason there are people who somehow make the duration based on hrtime to take negative time 🤔 As you might expect: This shouldn’t be the case, no one implemented a time machine – yet. We read the code. Again and again, thought about it but couldn’t explain why this happens – under the assumption that every hrtime() call returns at least the same (not unix) timestamp. As you can see on the ticket, even the reporters have a rough time to reproduce it, so we decided that obviously a negative duration doesn’t make sense and throwing an unreliable exception for whatever reason is not helpful as well, so we ignore negative durations and just return a duration of 0. That doesn’t make the nerd in all of us happy, but it makes the code work – and make it work is the most important thing.

Board games

In case you don’t know: Sebastian Bergmann is totally into boardgames, but today another brought a boardgame: Among cultists. It took a while to prepare and to explain, but then it is a nice, quick game. I really enojoyed it <3 The mechanics are easy (at least if you play it with 5 people, there is a lot more with more people!). The basic idea is Werewolf, but with a couple of added workings. It was fun!

I’m looking forward to tomorrow, because I’m writing this on Friday evening.

One thought on “Events: PHPUnit Code Sprint

Leave a Reply

Discover more from Winkelwagen

Subscribe now to keep reading and get access to the full archive.

Continue reading