Today I set off to start writing some API documentation, but ended up reworking some of the pain points in creating a custom metric or variant type. In ShrimpTest I’m requiring that custom metrics and variants be written as PHP classes so as not to polute the global namespace unnecessarily. Here were some previous restrictions which have now all been lifted:

  1. Custom metric and variant files had to specify the class that they were exporting by setting an $export_class variable. This meant, for example, you couldn’t write multiple metric types in one file. Boo!
  2. Their class name had to specify whether it was a metric or variant. I’d also required (redundantly!) that their files be prefixed by metric- and variant-.

The solution has instead been to require that these classes extend the ShrimpTest_Variant or ShrimpTest_Metric class, respectively. I now simply load all the files in the plugins subdirectory, look at all defined classes, and initialize and register the variants, then initialize and register the metrics. It results in some cleaner custom metric and variant code. I then did write up a little bit of initial API documentation.

I also tried to track down this bug (see thread below) but was still unable to reproduce this issue. :/