<commit_before><commit_msg>[NEW] Start tests on \Change\Db\Mysql\DbProvider<commit_after><?php
namespace ChangeTests\Change\Db\Mysql;

use Change\Db\Mysql\DbProvider;
use Change\Db\ScalarType;

class DbProviderTest extends \PHPUnit_Framework_TestCase
{

	public function testGetInstance()
	{
		$provider = \Change\Application::getInstance()->getApplicationServices()->getDbProvider();
		/* @var $provider \Change\Db\Mysql\DbProvider */
		$this->assertInstanceOf('\Change\Db\Mysql\DbProvider', $provider);
		
		$this->assertEquals('mysql', $provider->getType());
		$this->assertNull($provider->getId());
		
		$pdo = $provider->getDriver();
		try 
		{
			$pdo->exec('INVALID SQL');
			$this->fail('Invalid PDO Exception');
			
		}
		catch (\PDOException $e)
		{
			$this->assertStringStartsWith('SQLSTATE', $e->getMessage());
			$this->assertEquals('42000', $e->getCode());
		}
		
		return $provider;
	}
	
	/**
	 * @depends testGetInstance
	 */
	public function testTransaction(DbProvider $provider)
	{
		$this->assertFalse($provider->inTransaction());
		
		$provider->beginTransaction();
		
		$this->assertTrue($provider->inTransaction());
	
		$provider->commit();
		
		$this->assertFalse($provider->inTransaction());
		
		$provider->beginTransaction();
		
		$this->assertTrue($provider->inTransaction());
		
		$provider->rollBack();
		
		$this->assertFalse($provider->inTransaction());	
		
		return $provider;
	}
	
	/**
	 * @depends testTransaction
	 */
	public function testValues(DbProvider $provider)
	{
		$this->assertSame(1, $provider->phpToDB(true, ScalarType::BOOLEAN));
		$this->assertSame(true, $provider->dbToPhp(1, ScalarType::BOOLEAN));
		$this->assertSame(0, $provider->phpToDB(false, ScalarType::BOOLEAN));
		$this->assertSame(false, $provider->dbToPhp(0, ScalarType::BOOLEAN));
		
		$dt = new \DateTime('now', new \DateTimeZone('UTC'));
		$dbval =  $dt->format('Y-m-d H:i:s');
		
		$this->assertSame($dbval, $provider->phpToDB($dt, ScalarType::DATETIME));
		$this->assertEquals($dt, $provider->dbToPhp($dbval, ScalarType::DATETIME));
	}
	
}
{'fraction_non_alphanumeric': 0.18832116788321168, 'fraction_numerical': 0.004379562043795621, 'mean_word_length': 4.994169096209912, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 44, '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': '925449', 'n_tokens_mistral': 758, 'n_tokens_neox': 671, 'n_words': 94}