Skip to content

Instantly share code, notes, and snippets.

@mjordan
Created January 25, 2019 15:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mjordan/cd73d31bebb2d3db9271c4e5a5e63abc to your computer and use it in GitHub Desktop.
Save mjordan/cd73d31bebb2d3db9271c4e5a5e63abc to your computer and use it in GitHub Desktop.
Symfony 4 fixtures generator for Riprap
<?php
// src/DataFixtures/AppFixtures.php
namespace App\DataFixtures;
use App\Entity\FixityCheckEvent;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\Persistence\ObjectManager;
use Ramsey\Uuid\Uuid;
class AppFixtures extends Fixture
{
public function load(ObjectManager $manager)
{
$ids = range(0, 1000);
$data = array();
foreach ($ids as $id) {
$uuid4 = Uuid::uuid4();
$uuid = $uuid4->toString();
$data[$id] = array('uuid' => $uuid, 'SHA-1' => sha1($id));
$event = new FixityCheckEvent();
$event->setEventUuid($data[$id]['uuid']);
$event->setEventType('fix');
$event->setResourceId('http://localhost:8000/mockrepository/rest/' . $id);
// Only the days and months are "random", within specificed ranges of values.
$month = str_pad(rand(7, 12), 2, '0', STR_PAD_LEFT);
$day = str_pad(rand(1,28), 2, '0', STR_PAD_LEFT);
$rand_date = '2018-' . $month . '-' . $day . 'T19:04:20-0800';
$event->setTimestamp($rand_date);
$event->setDigestAlgorithm('SHA-1');
$event->setDigestValue($data[$id]['SHA-1']);
$event->setEventOutcome('success');
$event->setEventDetail('');
$event->setEventOutcomeDetailNote('');
$manager->persist($event);
}
$manager->flush();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment