Skip to content

Commit 0d15043

Browse files
committed
Tweaked the generation of data fixtures
1 parent 3cf18af commit 0d15043

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

src/AppBundle/DataFixtures/ORM/PostFixtures.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,7 @@ class PostFixtures extends AbstractFixture implements DependentFixtureInterface,
4141
*/
4242
public function load(ObjectManager $manager)
4343
{
44-
$phrases = $this->getPhrases();
45-
shuffle($phrases);
46-
47-
foreach ($phrases as $i => $title) {
44+
foreach ($this->getRandomPostTiles() as $i => $title) {
4845
$post = new Post();
4946

5047
$post->setTitle($title);
@@ -182,6 +179,18 @@ private function getPhrases()
182179
];
183180
}
184181

182+
private function getRandomPostTiles()
183+
{
184+
$phrases = $this->getPhrases();
185+
186+
// this ensures that the first title is always 'Lorem Ipsum...'
187+
$loremIpsumPhrase = array_shift($phrases);
188+
shuffle($phrases);
189+
array_unshift($phrases, $loremIpsumPhrase);
190+
191+
return $phrases;
192+
}
193+
185194
private function getRandomPostSummary($maxLength = 255)
186195
{
187196
$phrases = $this->getPhrases();

var/data/blog.sqlite

80 KB
Binary file not shown.

var/data/blog_test.sqlite

80 KB
Binary file not shown.

0 commit comments

Comments
 (0)