<commit_before><?php

namespace Edge\Test\Doctrine;

use Doctrine\ORM\Tools\SchemaTool;
use Doctrine\Common\DataFixtures\Executor\ORMExecutor;
use Doctrine\Common\DataFixtures\Purger\ORMPurger;
use Doctrine\Common\DataFixtures\Loader;
use Edge\Test\AbstractTestCase;

abstract class AbstractDoctrineTestCase extends AbstractTestCase
{
    public static $schemaExists = false;

    protected $entityManagerAlias = 'EntityManager';

    protected $platform;

    protected $database;

    protected $provider;

    protected function setUp()
    {
        $this->getEntityManager(); //ensures local override is detected

        if (self::$schemaExists) {
            if (!$this->getProvider()->restoreDatabase($this->getDatabaseName())) {
                $this->loadFixtures(false);
            }
            return;
        }

        $this->createSchema();
    }

    protected function createSchema()
    {
        echo 'CREATE';
        $this->getProvider()->deleteDatabase($this->getDatabaseName());

        $schemaTool = new SchemaTool($this->getEntityManager());
        $schemaTool->createSchema($this->getEntityManager()->getMetadataFactory()->getAllMetadata());

        $this->loadFixtures();

        $this->getProvider()->backupDatabase($this->getDatabaseName());

        self::$schemaExists = true;
    }

    protected function loadFixtures($append = true)
    {
        $fixtureLoader = new Loader();
        $fixtureLoader->loadFromDirectory($this->getFixturePath());

        if ($append) {
            $purger = null;
        } else {
            $purger = new ORMPurger();
        }

        $executor = new ORMExecutor($this->getEntityManager(), $purger);
        $executor->execute($fixtureLoader->getFixtures(), $append);
    }

    protected function getPlatform()<commit_msg>preLoad entitymanager for all doctrine based tests<commit_after><?php

namespace Edge\Test\Doctrine;

use Doctrine\ORM\Tools\SchemaTool;
use Doctrine\Common\DataFixtures\Executor\ORMExecutor;
use Doctrine\Common\DataFixtures\Purger\ORMPurger;
use Doctrine\Common\DataFixtures\Loader;
use Edge\Test\AbstractTestCase;

abstract class AbstractDoctrineTestCase extends AbstractTestCase
{
    public static $schemaExists = false;

    protected $entityManagerAlias = 'EntityManager';

    protected $platform;

    protected $database;

    protected $provider;

    protected function setUp()
    {
        $this->getEntityManager(); //ensures local override is detected

        if (self::$schemaExists) {
            if (!$this->getProvider()->restoreDatabase($this->getDatabaseName())) {
                $this->loadFixtures(false);
            }
            return;
        }

        $this->createSchema();
    }

    protected function createSchema()
    {
        $this->getProvider()->deleteDatabase($this->getDatabaseName());

        $schemaTool = new SchemaTool($this->getEntityManager());
        $schemaTool->createSchema($this->getEntityManager()->getMetadataFactory()->getAllMetadata());

        $this->loadFixtures();

        $this->getProvider()->backupDatabase($this->getDatabaseName());

        self::$schemaExists = true;
    }

    protected function loadFixtures($append = true)
    {
        $fixtureLoader = new Loader();
        $fixtureLoader->loadFromDirectory($this->getFixturePath());

        if ($append) {
            $purger = null;
        } else {
            $purger = new ORMPurger();
        }

        $executor = new ORMExecutor($this->getEntityManager(), $purger);
        $executor->execute($fixtureLoader->getFixtures(), $append);
    }

    protected function getPlatform()
{'fraction_non_alphanumeric': 0.1297013274336283, 'fraction_numerical': 0.0, 'mean_word_length': 3.0233592880978866, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3395975', 'n_tokens_mistral': 975, 'n_tokens_neox': 942, 'n_words': 175}