<commit_before><?php
namespace Asgard\Migration\Tests;

class BrowserTest extends \PHPUnit_Framework_TestCase {
	public function testAddMigration() {
		\Asgard\File\FileSystem::delete(__DIR__.'/migrations');
		\Asgard\File\FileSystem::copy(__DIR__.'/fixtures/migrations', __DIR__.'/migrations');
		$mm = new \Asgard\Migration\MigrationsManager(__DIR__.'/migrations/');
		$mm->add(__DIR__.'/fixtures/Migration.php');
		$this->assertTrue(file_exists(__DIR__.'/migrations/Migration.php'));
		$this->assertRegExp('/\{'."\n".
'    "Migration": \{'."\n".
'        "added": [0-9.]+'."\n".
'    \}'."\n".
'\}/', file_get_contents(__DIR__.'/migrations/migrations.json'));
	}

	public function testCreateAndRemoveMigration() {
		\Asgard\File\FileSystem::delete(__DIR__.'/migrations');
		\Asgard\File\FileSystem::copy(__DIR__.'/fixtures/migrations', __DIR__.'/migrations');
		$mm = new \Asgard\Migration\MigrationsManager(__DIR__.'/migrations/');
		$mm->create('up();', 'down();', 'Amigration');
		$this->assertTrue(file_exists(__DIR__.'/migrations/Amigration.php'));
		$this->assertEquals('<?php'."\n".
'class Amigration extends \Asgard\Migration\Migration {'."\n".
'	public function up() {'."\n".
'		up();'."\n".
'	}'."\n".
'	'."\n".
'	public function down() {'."\n".
'		down();'."\n".
'	}'."\n".
'}', $this->normalize(file_get_contents(__DIR__.'/migrations/Amigration.php')));
		$this->assertRegExp('/\{'."\n".
'    "Amigration": \{'."\n".
'        "added": [0-9.]+'."\n".
'    \}'."\n".
'\}/', file_get_contents(__DIR__.'/migrations/migrations.json'));

		$mm->remove('Amigration');
		$this->assertRegExp('/\['."\n".
"\n".
'\]/', file_get_contents(__DIR__.'/migrations/migrations.json'));
	}

	public function testMigrate() {
		\Asgard\File\FileSystem::delete(__DIR__.'/migrations');
		\Asgard\File\FileSystem::copy(__DIR__.'/fixtures/migrations_migrate', __DIR__.'/migrations');
		$mm = new \Asgard\Migration\MigrationsManager(__DIR__.'/migrations/');
		$mm->migrate('Migration', true);
		$this->assertTrue(\Migration::$migrated);

		$this->assertRegExp('/\{'."\n".
'    "Migration": \{'."\n".
'        "migrated": [0-9.]+'."\n".
'    \}'."\n".
'\}/', file_get_contents(__DIR__.'/migrations/tracking.json'));
	}

	public function testMigrateAll() {
		\Asgard\File\FileSystem::delete(__DIR__.'/migrations');
		\Asgard\File\FileSystem::copy(__DIR__.'/fixtures/migrations_all', __DIR__.'/migrations');<commit_msg>fixing test<commit_after><?php
namespace Asgard\Migration\Tests;

class BrowserTest extends \PHPUnit_Framework_TestCase {
	public function testAddMigration() {
		\Asgard\File\FileSystem::delete(__DIR__.'/migrations');
		\Asgard\File\FileSystem::copy(__DIR__.'/fixtures/migrations', __DIR__.'/migrations');
		$mm = new \Asgard\Migration\MigrationsManager(__DIR__.'/migrations/');
		$mm->add(__DIR__.'/fixtures/Migration.php');
		$this->assertTrue(file_exists(__DIR__.'/migrations/Migration.php'));
		$this->assertRegExp('/\{'."\n".
'    "Migration": \{'."\n".
'        "added": [0-9.]+'."\n".
'    \}'."\n".
'\}/', file_get_contents(__DIR__.'/migrations/migrations.json'));
	}

	public function testCreateAndRemoveMigration() {
		\Asgard\File\FileSystem::delete(__DIR__.'/migrations');
		\Asgard\File\FileSystem::copy(__DIR__.'/fixtures/migrations', __DIR__.'/migrations');
		$mm = new \Asgard\Migration\MigrationsManager(__DIR__.'/migrations/');
		$mm->create('up();', 'down();', 'Amigration');
		$this->assertTrue(file_exists(__DIR__.'/migrations/Amigration.php'));
		$this->assertEquals('<?php'."\n".
'class Amigration extends \Asgard\Migration\Migration {'."\n".
'	public function up() {'."\n".
'		up();'."\n".
'	}'."\n".
'	'."\n".
'	public function down() {'."\n".
'		down();'."\n".
'	}'."\n".
'}', $this->normalize(file_get_contents(__DIR__.'/migrations/Amigration.php')));
		$this->assertRegExp('/\{'."\n".
'    "Amigration": \{'."\n".
'        "added": [0-9.]+'."\n".
'    \}'."\n".
'\}/', file_get_contents(__DIR__.'/migrations/migrations.json'));

		$mm->remove('Amigration');
		$this->assertRegExp('/\[\s*\]/', file_get_contents(__DIR__.'/migrations/migrations.json'));
	}

	public function testMigrate() {
		\Asgard\File\FileSystem::delete(__DIR__.'/migrations');
		\Asgard\File\FileSystem::copy(__DIR__.'/fixtures/migrations_migrate', __DIR__.'/migrations');
		$mm = new \Asgard\Migration\MigrationsManager(__DIR__.'/migrations/');
		$mm->migrate('Migration', true);
		$this->assertTrue(\Migration::$migrated);

		$this->assertRegExp('/\{'."\n".
'    "Migration": \{'."\n".
'        "migrated": [0-9.]+'."\n".
'    \}'."\n".
'\}/', file_get_contents(__DIR__.'/migrations/tracking.json'));
	}

	public function testMigrateAll() {
		\Asgard\File\FileSystem::delete(__DIR__.'/migrations');
		\Asgard\File\FileSystem::copy(__DIR__.'/fixtures/migrations_all', __DIR__.'/migrations');
{'fraction_non_alphanumeric': 0.2521902377972466, 'fraction_numerical': 0.0025031289111389237, 'mean_word_length': 4.436507936507937, 'pattern_counts': {'":': 12, '<': 7, '<?xml version=': 0, '>': 29, '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': '7197035', 'n_tokens_mistral': 1837, 'n_tokens_neox': 1821, 'n_words': 187}