I found the solution. For most of the examples I tried, the required transformation was exclusive canonicalization with comments: http://www.w3.org/TR/2002/REC-xml-exc-c14n-20020718/#WithComments
So my problem was that I was doing the transformation wrong. The first parameter in PHP's C14N function defines whether to use exclusive transformation or not. This is what the code should have been (note that I removed the unnecessary traversal to the first element):
public function testCreateDigest(DOMDocument $request, $expectedDigest) {
$ns = $request->documentElement->namespaceURI;
$body = $request
->getElementsByTagNameNS($ns, 'Body')
->item(0);
$content = $body->C14N(true, true); // <-- exclusive, with comments
$actualDigest = base64_encode(hash('SHA1', $content, true));
$this->assertEquals($expectedDigest, $actualDigest);
}
So there you have it. This served as a reminder for me to double check my XML and understand the standards before I go coding aimlessly.