<commit_before><?php declare(strict_types=1);

namespace EdmondsCommerce\DoctrineStaticMeta\Tests\Large\Entity\Savers;

use EdmondsCommerce\DoctrineStaticMeta\Entity\Interfaces\EntityInterface;
use EdmondsCommerce\DoctrineStaticMeta\Entity\Savers\BulkEntitySaver;
use EdmondsCommerce\DoctrineStaticMeta\Tests\Assets\AbstractLargeTest;
use EdmondsCommerce\DoctrineStaticMeta\Tests\Assets\AbstractTest;
use EdmondsCommerce\DoctrineStaticMeta\Tests\Assets\TestCodeGenerator;

class BulkEntitySaverTest extends AbstractLargeTest
{
    public const WORK_DIR = AbstractTest::VAR_PATH . '/' . self::TEST_TYPE_LARGE . '/BulkEntitySaverTest';

    /**
     * @var BulkEntitySaver
     */
    private $saver;

    public function setup(): void
    {
        parent::setUp();
        if (false === self::$built) {
            $this->getTestCodeGenerator()
                 ->copyTo(self::WORK_DIR, self::TEST_PROJECT_ROOT_NAMESPACE);
        }
        $this->setupCopiedWorkDirAndCreateDatabase();
        $this->saver = new BulkEntitySaver($this->getEntityManager());
    }

    /**
     * @test
     * @large
     */
    public function itCanBulkSaveLargeDataEntities()
    {
        $this->saver->setChunkSize(100);
        $entityFqn = $this->getCopiedFqn(TestCodeGenerator::TEST_ENTITY_LARGE_DATA);
        $generator = $this->getTestEntityGeneratorFactory()
                          ->createForEntityFqn($entityFqn)
                          ->getGenerator($this->getEntityManager(), $entityFqn);
        foreach (range(0, $this->getDataSize()) as $offset) {
            $this->saver->addEntityToSave($this->getNextEntity($generator));
        }
        $this->saver->endBulkProcess();
        $numEntities = $this->getRepositoryFactory()->getRepository($entityFqn)->count();
        self::assertSame($this->getDataSize(), $numEntities);
    }

    private function getDataSize()
    {
        if ($this->isQuickTests()) {
            return 200;
        }
        if (isset($_SERVER['BulkEntitySaverTest_DataSize'])) {
            return (int)$_SERVER['BulkEntitySaverTest_DataSize'];
        }

        return 1000;
    }

    private function getNextEntity(\Generator $generator): EntityInterface
    {
        $generator->next();

        return $generator->current();
    }
}
<commit_msg>cs fixes<commit_after><?php declare(strict_types=1);

namespace EdmondsCommerce\DoctrineStaticMeta\Tests\Large\Entity\Savers;

use EdmondsCommerce\DoctrineStaticMeta\Entity\Interfaces\EntityInterface;
use EdmondsCommerce\DoctrineStaticMeta\Entity\Savers\BulkEntitySaver;
use EdmondsCommerce\DoctrineStaticMeta\Tests\Assets\AbstractLargeTest;
use EdmondsCommerce\DoctrineStaticMeta\Tests\Assets\AbstractTest;
use EdmondsCommerce\DoctrineStaticMeta\Tests\Assets\TestCodeGenerator;

class BulkEntitySaverTest extends AbstractLargeTest
{
    public const WORK_DIR = AbstractTest::VAR_PATH . '/' . self::TEST_TYPE_LARGE . '/BulkEntitySaverTest';

    /**
     * @var BulkEntitySaver
     */
    private $saver;

    public function setup(): void
    {
        parent::setUp();
        if (false === self::$built) {
            $this->getTestCodeGenerator()
                 ->copyTo(self::WORK_DIR, self::TEST_PROJECT_ROOT_NAMESPACE);
        }
        $this->setupCopiedWorkDirAndCreateDatabase();
        $this->saver = new BulkEntitySaver($this->getEntityManager());
    }

    /**
     * @test
     * @large
     */
    public function itCanBulkSaveLargeDataEntities()
    {
        $this->saver->setChunkSize(100);
        $entityFqn = $this->getCopiedFqn(TestCodeGenerator::TEST_ENTITY_LARGE_DATA);
        $generator = $this->getTestEntityGeneratorFactory()
                          ->createForEntityFqn($entityFqn)
                          ->getGenerator($this->getEntityManager(), $entityFqn);
        for ($i = 0, $iMax = $this->getDataSize(); $i < $iMax; $i++) {
            $this->saver->addEntityToSave($this->getNextEntity($generator));
        }
        $this->saver->endBulkProcess();
        $numEntities = $this->getRepositoryFactory()->getRepository($entityFqn)->count();
        self::assertSame($this->getDataSize(), $numEntities);
    }

    private function getDataSize()
    {
        if ($this->isQuickTests()) {
            return 200;
        }
        if (isset($_SERVER['BulkEntitySaverTest_DataSize'])) {
            return (int)$_SERVER['BulkEntitySaverTest_DataSize'];
        }

        return 1000;
    }

    private function getNextEntity(\Generator $generator): EntityInterface
    {
        $generator->next();

        return $generator->current();
    }
}

{'fraction_non_alphanumeric': 0.12898297686599738, 'fraction_numerical': 0.005237887385421213, 'mean_word_length': 3.0701598579040854, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 53, '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': '3307838', 'n_tokens_mistral': 1390, 'n_tokens_neox': 1357, 'n_words': 180}