Perhaps such examples are best written in actual PHP files, put in SemanticMediaWiki/docs/technical/examples/. Then they could have simple tests executed by the CI, ensuring they stay up to date with the SMW version they are bundled with.
Jeroen De Dauw (talk)
https://github.com/SemanticMediaWiki/SemanticMediaWiki/issues/445