<commit_before><?php namespace CodeIgniter\Database\Live;

use CodeIgniter\Database\Exceptions\DatabaseException;
use CodeIgniter\Database\Forge;
use CodeIgniter\Test\CIDatabaseTestCase;

/**
 * @group DatabaseLive
 */
class ForgeTest extends CIDatabaseTestCase
{
	protected $refresh = true;

	protected $seed = 'Tests\Support\Database\Seeds\CITestSeeder';
	/**
	 * @var \CodeIgniter\Database\Forge
	 */
	protected $forge;

	protected function setUp()
	{
		parent::setUp();
		$this->forge = \Config\Database::forge($this->DBGroup);
	}

	public function testCreateDatabase()
	{
		$database_created = $this->forge->createDatabase('test_forge_database');

		$this->assertTrue($database_created);
	}

	public function testDropDatabase()
	{
		if ($this->db->DBDriver === 'SQLite3')
		{
			$this->markTestSkipped('SQLite3 requires file path to drop database');
		}

		$database_dropped = $this->forge->dropDatabase('test_forge_database');

		$this->assertTrue($database_dropped);
	}

	public function testCreateDatabaseExceptionNoCreateStatement()
	{
		$this->setPrivateProperty($this->forge, 'createDatabaseStr', false);

		if ($this->db->DBDriver === 'SQLite3')
		{
			$database_created = $this->forge->createDatabase('test_forge_database');
			$this->assertTrue($database_created);
		}
		else
		{
			$this->expectException(DatabaseException::class);
			$this->expectExceptionMessage('This feature is not available for the database you are using.');

			$this->forge->createDatabase('test_forge_database');
		}
	}

	public function testDropDatabaseExceptionNoDropStatement()
	{
		$this->setPrivateProperty($this->forge, 'dropDatabaseStr', false);

		if ($this->db->DBDriver === 'SQLite3')
		{
			$this->markTestSkipped('SQLite3 requires file path to drop database');
		}
		else
		{
			$this->expectException(DatabaseException::class);
			$this->expectExceptionMessage('This feature is not available for the database you are using.');

			$this->forge->dropDatabase('test_forge_database');
		}
	}

	public function testCreateTable()
	{
		$this->forge->dropTable('forge_test_table', true);

		$this->forge->addField([
			'id'     => [
				'type'           => 'INTEGER',
				'constraint'     => 11,
				'unsigned'       => true,
				'auto_increment' => true,
			],
			'mobile' => [
				'type'       => 'INTEGER',
				'constraint' => 10,
				'unsigned'   => true,
			],
		]);

		$unsignedAttributes = [
			'INTEGER',
		];

		$this->setPrivateProperty($this->forge, 'unsigned', $unsignedAttributes);

		$this->forge->addKey('id', true);
		$this->forge->createTable('forge_test_table');

		$exist = $this->db->tableExists('forge_test_table');
		$this->forge->dropTable('forge_test_table', true);

		$this->assertTrue($exist);
	}

	public function testCreateTableWithAttributes()
	{
		if ($this->db->DBDriver === 'SQLite3')
		{
			$this->markTestSkipped('SQLite3 does not support comments on tables or columns.');
		}

		$this->forge->dropTable('forge_test_attributes', true);

		$this->forge->addField('id');

		$attributes = [
			'comment' => "Forge's Test",
		];

		$this->forge->createTable('forge_test_attributes', false, $attributes);

		$exist = $this->db->tableExists('forge_test_attributes');
		$this->forge->dropTable('forge_test_attributes', true, true);

		$this->assertTrue($exist);
	}

	public function testCreateTableWithArrayFieldConstraints()
	{
		if (in_array($this->db->DBDriver, ['MySQLi', 'SQLite3']))
		{
			$this->forge->dropTable('forge_array_constraint', true);
			$this->forge->addField([
				'status' => [
					'type'       => 'ENUM',
					'constraint' => [
						'sad',
						'ok',
						'happy',
					],
				],
			]);
			$this->forge->createTable('forge_array_constraint');

			$fields = $this->db->getFieldData('forge_array_constraint');

			$this->assertEquals('status', $fields[0]->name);

			if ($this->db->DBDriver === 'SQLite3')
			{
				// SQLite3 converts array constraints to TEXT CHECK(...)
				$this->assertEquals('TEXT', $fields[0]->type);
			}
			else
			{
				$this->assertEquals('enum', $fields[0]->type);
			}
		}
		else
		{
			$this->expectNotToPerformAssertions();
		}<commit_msg>[ci skip] Fix leftover test table<commit_after><?php namespace CodeIgniter\Database\Live;

use CodeIgniter\Database\Exceptions\DatabaseException;
use CodeIgniter\Database\Forge;
use CodeIgniter\Test\CIDatabaseTestCase;

/**
 * @group DatabaseLive
 */
class ForgeTest extends CIDatabaseTestCase
{
	protected $refresh = true;

	protected $seed = 'Tests\Support\Database\Seeds\CITestSeeder';
	/**
	 * @var \CodeIgniter\Database\Forge
	 */
	protected $forge;

	protected function setUp()
	{
		parent::setUp();
		$this->forge = \Config\Database::forge($this->DBGroup);
	}

	public function testCreateDatabase()
	{
		$database_created = $this->forge->createDatabase('test_forge_database');

		$this->assertTrue($database_created);
	}

	public function testDropDatabase()
	{
		if ($this->db->DBDriver === 'SQLite3')
		{
			$this->markTestSkipped('SQLite3 requires file path to drop database');
		}

		$database_dropped = $this->forge->dropDatabase('test_forge_database');

		$this->assertTrue($database_dropped);
	}

	public function testCreateDatabaseExceptionNoCreateStatement()
	{
		$this->setPrivateProperty($this->forge, 'createDatabaseStr', false);

		if ($this->db->DBDriver === 'SQLite3')
		{
			$database_created = $this->forge->createDatabase('test_forge_database');
			$this->assertTrue($database_created);
		}
		else
		{
			$this->expectException(DatabaseException::class);
			$this->expectExceptionMessage('This feature is not available for the database you are using.');

			$this->forge->createDatabase('test_forge_database');
		}
	}

	public function testDropDatabaseExceptionNoDropStatement()
	{
		$this->setPrivateProperty($this->forge, 'dropDatabaseStr', false);

		if ($this->db->DBDriver === 'SQLite3')
		{
			$this->markTestSkipped('SQLite3 requires file path to drop database');
		}
		else
		{
			$this->expectException(DatabaseException::class);
			$this->expectExceptionMessage('This feature is not available for the database you are using.');

			$this->forge->dropDatabase('test_forge_database');
		}
	}

	public function testCreateTable()
	{
		$this->forge->dropTable('forge_test_table', true);

		$this->forge->addField([
			'id'     => [
				'type'           => 'INTEGER',
				'constraint'     => 11,
				'unsigned'       => true,
				'auto_increment' => true,
			],
			'mobile' => [
				'type'       => 'INTEGER',
				'constraint' => 10,
				'unsigned'   => true,
			],
		]);

		$unsignedAttributes = [
			'INTEGER',
		];

		$this->setPrivateProperty($this->forge, 'unsigned', $unsignedAttributes);

		$this->forge->addKey('id', true);
		$this->forge->createTable('forge_test_table');

		$exist = $this->db->tableExists('forge_test_table');
		$this->forge->dropTable('forge_test_table', true);

		$this->assertTrue($exist);
	}

	public function testCreateTableWithAttributes()
	{
		if ($this->db->DBDriver === 'SQLite3')
		{
			$this->markTestSkipped('SQLite3 does not support comments on tables or columns.');
		}

		$this->forge->dropTable('forge_test_attributes', true);

		$this->forge->addField('id');

		$attributes = [
			'comment' => "Forge's Test",
		];

		$this->forge->createTable('forge_test_attributes', false, $attributes);

		$exist = $this->db->tableExists('forge_test_attributes');
		$this->forge->dropTable('forge_test_attributes', true, true);

		$this->assertTrue($exist);
	}

	public function testCreateTableWithArrayFieldConstraints()
	{
		if (in_array($this->db->DBDriver, ['MySQLi', 'SQLite3']))
		{
			$this->forge->dropTable('forge_array_constraint', true);
			$this->forge->addField([
				'status' => [
					'type'       => 'ENUM',
					'constraint' => [
						'sad',
						'ok',
						'happy',
					],
				],
			]);
			$this->forge->createTable('forge_array_constraint');

			$fields = $this->db->getFieldData('forge_array_constraint');

			$this->assertEquals('status', $fields[0]->name);

			if ($this->db->DBDriver === 'SQLite3')
			{
				// SQLite3 converts array constraints to TEXT CHECK(...)
				$this->assertEquals('TEXT', $fields[0]->type);
			}
			else
			{
				$this->assertEquals('enum', $fields[0]->type);
			}

			$this->forge->dropTable('forge_array_constraint', true);
		}
		else
		{
			$this->expectNotToPerformAssertions();
		}
{'fraction_non_alphanumeric': 0.1728617827499098, 'fraction_numerical': 0.00408997955010225, 'mean_word_length': 4.248737373737374, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 189, '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': '6258509', 'n_tokens_mistral': 3142, 'n_tokens_neox': 2662, 'n_words': 435}