PHP code example of mgdsoft / fixtures-generator-bundle
1. Go to this page and download the library: Download mgdsoft/fixtures-generator-bundle library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
mgdsoft / fixtures-generator-bundle example snippets
MGDSoft\FixturesGeneratorBundle\MgdsoftFixturesGeneratorBundle::class => ['dev' => true],
if (in_array($this->getEnvironment(), ['dev', 'test'], true)) {
$bundles[] = new MGDSoft\FixturesGeneratorBundle\MgdsoftFixturesGeneratorBundle()
}
namespace App\DataFixtures\ORM\LibsAuto;
use App\Entity\User;
use MGDSoft\FixturesGeneratorBundle\LoaderFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
abstract class AbstractLoadUserFixture extends AbstractFixture implements DependentFixtureInterface
{
/**
* (Skipped) all parameters to auto complete IDE
*/
protected function loadRow($key, array $overrideDefaultValues = [])
{
$obj = new User();
$defaultValues = $this->getDefaultValues();
$properties = array_merge($defaultValues, $overrideDefaultValues);
foreach ($properties as $property => $value) {
$this->propertyAccessor->setValue($obj, $property, $value);
}
$this->om->persist($obj);
$this->addReference("user-".$key, $obj);
}
protected function getDefaultValues()
{
return [
// ---[ // 'avatar' => 'avatar',
// 'initials' => 'initials',
// 'lang' => 'en',
// 'planDateEnd' => new \DateTime(),
// 'stripeSubscriptionId' => 'stripeSubscriptionId',
// 'userHasEmails' => $this->getReference("user_has_email-1"),
// 'webPushes' => $this->getReference("user_web_push-1"),
// 'user_resources' => $this->getReference("user_resources-1"),
// 'tags' => $this->getReference("tag-1"),
// 'guest' => $this->getReference("guest-1")
];
}
public function getDependencies()
{
return [
'App\DataFixtures\ORM\LoadPlanFixture',
// ---[ non-mandatory fields ]---,
// 'App\DataFixtures\ORM\LoadUserHasEmailFixture',
// 'App\DataFixtures\ORM\LoadUserWebPushFixture',
// 'App\DataFixtures\ORM\LoadUserResourcesFixture',
// 'App\DataFixtures\ORM\LoadTagFixture',
// 'App\DataFixtures\ORM\LoadGuestFixture'
];
}
}
namespace App\DataFixtures\ORM;
use App\DataFixtures\ORM\LibsAuto\AbstractLoadUserFixture;
class LoadUserFixture extends AbstractLoadUserFixture
{
protected function loadRows()
{
$this->loadRow('1', []);
}
}
namespace Tests\Fixtures\General;
use App\DataFixtures\ORM\LibsAuto\AbstractLoadUserFixture;
class LoadTestUserFixture extends AbstractLoadUserFixture
{
protected function loadRows()
{
$this->loadRow('1', []);
}
}
namespace App\DataFixtures\ORM;
use App\DataFixtures\ORM\LibsAuto\AbstractLoadUserFixture;
class LoadUserFixture extends AbstractLoadUserFixture
{
protected function loadRows()
{
$this->loadRow('1', ['username' => 'Miguel1', 'email' => '[email protected] ']);
$this->loadRow('2', ['username' => 'Miguel2', 'email' => '[email protected] ']);
$this->loadRow('3', ['username' => 'Miguel3', 'email' => '[email protected] ']);
}
}
namespace App\DataFixtures\ORM;
use App\DataFixtures\ORM\LibsAuto\AbstractLoadUserFixture;
class LoadUserFixture extends AbstractLoadUserFixture
{
protected function loadRows()
{
$this->loadRow('1', ['comments|1' => $this->getReference('comment-2'), 'comments|2' => $this->getReference('comment-1') ]);
}
}