<commit_before><?php

declare(strict_types=1);

namespace Doctrine\Migrations\Tests\Tools\Console\Command;

use Doctrine\Migrations\Configuration\Configuration;
use Doctrine\Migrations\Tests\MigrationTestCase;
use Doctrine\Migrations\Tests\Stub\Version1Test;
use Doctrine\Migrations\Tools\Console\Command\VersionCommand;
use InvalidArgumentException;
use PHPUnit\Framework\MockObject\MockObject;
use Symfony\Component\Console\Helper\HelperSet;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Tester\CommandTester;
use function sys_get_temp_dir;

class MigrationVersionTest extends MigrationTestCase
{
    /** @var VersionCommand|MockObject */
    private $command;

    /** @var Configuration */
    private $configuration;

    protected function setUp() : void
    {
        $this->command = $this
            ->getMockBuilder(VersionCommand::class)
            ->setConstructorArgs(['migrations:version'])
            ->setMethods(['getMigrationConfiguration'])
            ->getMock();

        $this->configuration = new Configuration($this->getSqliteConnection());
        $this->configuration->setMigrationsNamespace('DoctrineMigrations');
        $this->configuration->setMigrationsDirectory(sys_get_temp_dir());

        $this->command
            ->expects(self::once())
            ->method('getMigrationConfiguration')
            ->will(self::returnValue($this->configuration));
    }

    /**
     * Test "--add --range-to --range-from" options on migrate only versions in interval.
     */
    public function testAddRangeOption() : void
    {
        $this->configuration->registerMigration('1233', Version1Test::class);
        $this->configuration->registerMigration('1234', Version1Test::class);
        $this->configuration->registerMigration('1235', Version1Test::class);
        $this->configuration->registerMigration('1239', Version1Test::class);
        $this->configuration->registerMigration('1240', Version1Test::class);

        $commandTester = new CommandTester($this->command);
        $commandTester->execute(
            [
                '--add'        => true,
                '--range-from' => '1234',<commit_msg>Do not use /tmp as a migration directory<commit_after><?php

declare(strict_types=1);

namespace Doctrine\Migrations\Tests\Tools\Console\Command;

use Doctrine\Migrations\Configuration\Configuration;
use Doctrine\Migrations\Tests\MigrationTestCase;
use Doctrine\Migrations\Tests\Stub\Version1Test;
use Doctrine\Migrations\Tools\Console\Command\VersionCommand;
use InvalidArgumentException;
use PHPUnit\Framework\MockObject\MockObject;
use Symfony\Component\Console\Helper\HelperSet;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Tester\CommandTester;
use const DIRECTORY_SEPARATOR;
use function file_exists;
use function mkdir;
use function sys_get_temp_dir;

class MigrationVersionTest extends MigrationTestCase
{
    /** @var VersionCommand|MockObject */
    private $command;

    /** @var Configuration */
    private $configuration;

    protected function setUp() : void
    {
        $this->command = $this
            ->getMockBuilder(VersionCommand::class)
            ->setConstructorArgs(['migrations:version'])
            ->setMethods(['getMigrationConfiguration'])
            ->getMock();

        $this->configuration = new Configuration($this->getSqliteConnection());
        $this->configuration->setMigrationsNamespace('DoctrineMigrations');
        $migrationsDirectory = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'doctrine-migrations';
        if (! file_exists($migrationsDirectory)) {
            mkdir($migrationsDirectory);
        }
        $this->configuration->setMigrationsDirectory($migrationsDirectory);

        $this->command
            ->expects(self::once())
            ->method('getMigrationConfiguration')
            ->will(self::returnValue($this->configuration));
    }

    /**
     * Test "--add --range-to --range-from" options on migrate only versions in interval.
     */
    public function testAddRangeOption() : void
    {
        $this->configuration->registerMigration('1233', Version1Test::class);
        $this->configuration->registerMigration('1234', Version1Test::class);
        $this->configuration->registerMigration('1235', Version1Test::class);
        $this->configuration->registerMigration('1239', Version1Test::class);
        $this->configuration->registerMigration('1240', Version1Test::class);

        $commandTester = new CommandTester($this->command);
        $commandTester->execute(
            [
                '--add'        => true,
                '--range-from' => '1234',
{'fraction_non_alphanumeric': 0.12855614973262033, 'fraction_numerical': 0.013262032085561497, 'mean_word_length': 3.5310077519379846, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 63, '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': '1466964', 'n_tokens_mistral': 1261, 'n_tokens_neox': 1230, 'n_words': 200}