Helper function to create a random comment.
array $settings: (optional) An associative array of settings for the comment, as used in entity_create().
\Drupal\comment\Plugin\Core\Entity\Comment Returns the created and saved comment.
public function drupalCreateComment(array $settings = array()) {
$node = node_load($settings['nid']);
$settings += array(
'subject' => $this
->randomName(),
'node_type' => "comment_node_{$node->bundle()}",
'comment_body' => $this
->randomName(40),
);
$comment = entity_create('comment', $settings);
$comment
->save();
return $comment;
}