[5.0] Use PHPUnit's assertCount

This #5976 targeted at 5.0, and with an extra test added in too.