Adding GitLab CI to one of my contrib modules

I had a few hours free at the end of January to get GitLab CI enabled for the daterange_compact module.

When I first wrote this module, Drupal projects could opt-in to automated PHPUnit testing. This module has always had plenty of test coverage, so having tests run for every patch was so useful. Somewhere along the line something changed and the automated tests stopped running (though the tests themselves still were still fine). Nowadays, projects can have their own GitLab CI pipeline, but I’d never got around to setting that up.

The first task to fail was cspell, a spell checker for comments. I had no idea such a thing existed, but I soon found out.

Drupal Core uses US English spelling for all source code, including comments and names.

🤷 Whatever:

- * behaviour of that field formatter, and the default configuration.
+ * behavior of that field formatter, and the default configuration.

Pick your battles.

Next was the PHP code sniffer. It checks coding standards, comments, whitespace etc. I tidied up a few things here, adding some missing functions comments and fixing whitespace issues.

Sometimes, it’s ok to be a bit lazypragmatic:

// phpcs:ignore
private static function isSameDay($start_timestamp, $end_timestamp, $timezone): bool

The last error was more interesting. An actual test failure!

What?! These tests have been working for years, and I’ve always been dilligent to run them locally whenever I work on this project. Moreover, they still passed locally. But one of them failed on GitLab CI.

The offender was a test that makes sure we revert to a fallback date format when something isn’t available. And that fallback date format has changed in Drupal 11.1. I was still running 11.0.

So the test needed updating to match. It now expects different results depending on what version of Drupal is in use.

$expected = \Drupal::VERSION >= '11.1'
  ? 'Thu, 1 Jan 1970 - 10:00 - Thu, 1 Jan 1970 - 11:00'
  : 'Thu, 01/01/1970 - 10:00 - Thu, 01/01/1970 - 11:00';

It was good to get the CI pipeline working. As a bonus, I got to write a line of code too!