While in an effort to insert a post into a WordPress database using a SQL query (abstracted by Codeception methods but requiring parameters nonetheless) I’ve run into the need to generate random content; random “lorems” specifically. On my way to create an ad-hoc LoremMaker
class it struck me that I might not be the first to have such a need.
Not wanting to resort to hardcoded lines like
$defaults = array(
...
'post_content' => 'Post content here.',
'post_title' => 'Post title',
...
);
which could make some test artificially pass or fail I’ve opted for Samuel Williams Lorem Ipsum Generator to be able to write code like
$loremMaker = new Generator();
// create a default value array
$title = $loremMaker->getSentences(1);
$content = $loremMaker->getParagraphs(3);
$defaults = array(
...
'post_content' => $content,
'post_title' => $title,
...
);
While setting up and maintaining a Composer WordPress plugin, theme or generic PHP component might be a chore it really pays off time after time.