Skip to content

Commit e8a803a

Browse files
committed
minor #468 Tweaked the generation of data fixtures (javiereguiluz)
This PR was merged into the master branch. Discussion ---------- Tweaked the generation of data fixtures This change makes sure that "Lorem Ipsum..." is always the title of the first blog post, which is better for aesthetic reasons. Commits ------- 0d15043 Tweaked the generation of data fixtures
2 parents 2da7490 + 0d15043 commit e8a803a

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)