PHP code example of ergebnis / factory-girl-definition

1. Go to this page and download the library: Download ergebnis/factory-girl-definition 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/ */

    

ergebnis / factory-girl-definition example snippets




namespace Foo\Bar\Test\Fixture\Entity;

use Ergebnis\FactoryGirl\Definition\Definition;
use FactoryGirl\Provider\Doctrine\FixtureFactory;
use Foo\Bar\Entity;

final class UserDefinition implements Definition
{
    public function accept(FixtureFactory $fixtureFactory): void
    {
        $fixtureFactory->defineEntity(Entity\User::class, [
            // ...
        ]);
    }
}



namespace Foo\Bar\Test\Integration;

use Doctrine\ORM;
use Ergebnis\FactoryGirl\Definition\Definitions;
use FactoryGirl\Provider\Doctrine\FixtureFactory;
use Faker\Generator;
use PHPUnit\Framework;

abstract class AbstractIntegrationTestCase extends Framework\TestCase
{
    /**
     * @var FixtureFactory
     */
    private $fixtureFactory;

    final protected function entityManager(): ORM\EntityManager
    {
        // ...
    }

    final protected function faker(): Generator
    {
        // ...
    }

    final protected function fixtureFactory(): FixtureFactory
    {
        if (null === $this->fixtureFactory) {
            $fixtureFactory = new FixtureFactory($this->entityManager());
            $fixtureFactory->persistOnGet(true);

            Definitions::in(__DIR__ . '/../Fixture')
                ->registerWith($fixtureFactory)
                ->provideWith($this->faker());

            $this->fixtureFactory = $fixtureFactory;
        }

        return $this->fixtureFactory;
    }
}