<commit_before><?php
use Maghead\Migration\MigrationGenerator;
use Maghead\Migration\MigrationLoader;
use Maghead\Console;
use Maghead\Migration\MigrationRunner;
use Maghead\Schema\SchemaFinder;
use Maghead\Testing\ModelTestCase;

/**
 * @group migration
 */
class MigrationGeneratorTest extends ModelTestCase
{
    protected $onlyDriver = 'mysql';

    const MIGRATION_SCRIPT_DIR = 'tests/migrations';

    public function models()
    {
        return [];
    }

    public function setUp()
    {
        parent::setUp();

        if (! file_exists(self::MIGRATION_SCRIPT_DIR)) {
            mkdir(self::MIGRATION_SCRIPT_DIR);
        }
    }

    public function testGenerator()
    {
        $this->conn->query('DROP TABLE IF EXISTS users;');
        $this->conn->query('CREATE TABLE users (id integer NOT NULL PRIMARY KEY);');

        $generator = new MigrationGenerator($this->logger, self::MIGRATION_SCRIPT_DIR);
        $this->assertEquals('20120901_CreateUser.php', $generator->generateFilename('CreateUser', '20120901'));

        list($scriptClass, $path) = $generator->generate('UpdateUser', '20120902');
        // this requires timezone = Asia/Taipei

        $this->assertEquals('UpdateUser_1346515200', $scriptClass);
        $this->assertFileExists($path);
        $this->assertEquals('tests/migrations/20120902_UpdateUser.php', $path);
        $this->assertFileEquals('tests/migrations/20120902_UpdateUser.php.expected', $path);
        unlink($path);
    }

    public function testMigrationByDiff()
    {
        $this->conn->query('DROP TABLE IF EXISTS users');
        $this->conn->query('DROP TABLE IF EXISTS test');
        $this->conn->query('CREATE TABLE users (account VARCHAR(128) UNIQUE)');

        $generator = new MigrationGenerator($this->logger, self::MIGRATION_SCRIPT_DIR);

        $this->assertTrue(class_exists('TestApp\Model\UserSchema', true));

        $finder = new SchemaFinder;
        $finder->find();

        list($scriptClass, $path) = $generator->generateWithDiff('DiffMigration',
            'master',
            [ "users" => new TestApp\Model\UserSchema ],
            '20120101');

        $this->assertFileExists('tests/migrations/20120101_DiffMigration.php.expected', $path);

        require_once $path;

        // Convert date string into timestamp
        $this->assertEquals('1325347200', $scriptClass::getId());
<commit_msg>Fix assertion<commit_after><?php
use Maghead\Migration\MigrationGenerator;
use Maghead\Migration\MigrationLoader;
use Maghead\Console;
use Maghead\Migration\MigrationRunner;
use Maghead\Schema\SchemaFinder;
use Maghead\Testing\ModelTestCase;

/**
 * @group migration
 */
class MigrationGeneratorTest extends ModelTestCase
{
    protected $onlyDriver = 'mysql';

    const MIGRATION_SCRIPT_DIR = 'tests/migrations';

    public function models()
    {
        return [];
    }

    public function setUp()
    {
        parent::setUp();

        if (! file_exists(self::MIGRATION_SCRIPT_DIR)) {
            mkdir(self::MIGRATION_SCRIPT_DIR);
        }
    }

    public function testGenerator()
    {
        $this->conn->query('DROP TABLE IF EXISTS users;');
        $this->conn->query('CREATE TABLE users (id integer NOT NULL PRIMARY KEY);');

        $generator = new MigrationGenerator($this->logger, self::MIGRATION_SCRIPT_DIR);
        $this->assertEquals('20120901_CreateUser.php', $generator->generateFilename('CreateUser', '20120901'));

        list($scriptClass, $path) = $generator->generate('UpdateUser', '20120902');
        // this requires timezone = Asia/Taipei

        $this->assertStringMatchesFormat('UpdateUser_%i', $scriptClass);
        $this->assertFileExists($path);
        $this->assertEquals('tests/migrations/20120902_UpdateUser.php', $path);
        $this->assertFileEquals('tests/migrations/20120902_UpdateUser.php.expected', $path);
        unlink($path);
    }

    public function testMigrationByDiff()
    {
        $this->conn->query('DROP TABLE IF EXISTS users');
        $this->conn->query('DROP TABLE IF EXISTS test');
        $this->conn->query('CREATE TABLE users (account VARCHAR(128) UNIQUE)');

        $generator = new MigrationGenerator($this->logger, self::MIGRATION_SCRIPT_DIR);

        $this->assertTrue(class_exists('TestApp\Model\UserSchema', true));

        $finder = new SchemaFinder;
        $finder->find();

        list($scriptClass, $path) = $generator->generateWithDiff('DiffMigration',
            'master',
            [ "users" => new TestApp\Model\UserSchema ],
            '20120101');

        $this->assertFileExists('tests/migrations/20120101_DiffMigration.php.expected', $path);

        require_once $path;

        // Convert date string into timestamp
        $this->assertEquals('1325347200', $scriptClass::getId());

{'fraction_non_alphanumeric': 0.13795268997278626, 'fraction_numerical': 0.030981787732886748, 'mean_word_length': 3.3674588665447898, 'pattern_counts': {'":': 0, '<': 5, '<?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': '6708741', 'n_tokens_mistral': 1495, 'n_tokens_neox': 1375, 'n_words': 249}