<commit_before><?php
use iNDIEVOX\MasterSlaveDBAccess\MasterSlaveDBAccess;

class MasterSlaveDBAccessTest extends PHPUnit_Framework_TestCase
{

    protected static $db_config;
    protected static $no_slave_db_config;

    public static function setUpBeforeClass()
    {

        self::$db_config = array(
            "database_server" => array(
                "master"=>array(
                    "db_host"=>'localhost',
                    "db_name"=>'homestead',
                    "db_user"=>'root',
                    "db_password"=>''
                ),
                "slave1"=>array(
                    "db_host"=>'localhost',
                    "db_name"=>'homestead',
                    "db_user"=>'root',
                    "db_password"=>''
                ),
                "slave2"=>array(
                    "db_host"=>'localhost',
                    "db_name"=>'homestead',
                    "db_user"=>'root',
                    "db_password"=>'',
                )
            ),
            "slave_database_name" => array(
                'slave1',
                'slave2'
            )
        );

        self::$no_slave_db_config = array(
            "database_server" => array(
                "master"=>array(
                    "db_host"=>'localhost',
                    "db_name"=>'homestead',
                    "db_user"=>'root',
                    "db_password"=>''
                )
            ),
            "slave_database_name" => array()
        );

    }

    public static function tearDownAfterClass()
    {
        self::$db_config = null;
        self::$no_slave_db_config = null;
    }

    public function testGetInstance()
    {

        $db_obj = MasterSlaveDBAccess::getInstance(self::$no_slave_db_config);
        $db_obj = MasterSlaveDBAccess::getInstance(self::$no_slave_db_config);
        $db_obj = MasterSlaveDBAccess::getInstance(self::$no_slave_db_config);
        $this->assertEquals('master', $db_obj->current_mode);
        $this->assertEquals('one_time', $db_obj->context_status);
        unset($db_obj);
        MasterSlaveDBAccess::destroyInstance();

        $db_obj = MasterSlaveDBAccess::getInstance(self::$db_config);
        $db_obj = MasterSlaveDBAccess::getInstance(self::$db_config);
        $db_obj = MasterSlaveDBAccess::getInstance(self::$db_config);
        $this->assertRegexp('/slave/', $db_obj->current_mode);
        $this->assertEquals('one_time', $db_obj->context_status);
        unset($db_obj);
        MasterSlaveDBAccess::destroyInstance();

    }

    public function testConnectMaster()
    {

        $db_obj = MasterSlaveDBAccess::getInstance(self::$db_config);
        $db_obj->connectMaster();
        $this->assertEquals('master', $db_obj->current_mode);
        unset($db_obj);
        MasterSlaveDBAccess::destroyInstance();

    }

    public function testConnectSlave()
    {

        $db_obj = MasterSlaveDBAccess::getInstance(self::$no_slave_db_config);
        $this->assertEquals('master', $db_obj->current_mode);
        $db_obj->connectSlave();
        $this->assertEquals('master', $db_obj->current_mode);
        unset($db_obj);
        MasterSlaveDBAccess::destroyInstance();

        $db_obj = MasterSlaveDBAccess::getInstance(self::$db_config);
        $db_obj->connectSlave();
        $this->assertRegexp('/slave/', $db_obj->current_mode);
        unset($db_obj);
        MasterSlaveDBAccess::destroyInstance();

    }

    public function testChangeMode()
    {

        $db_obj = MasterSlaveDBAccess::getInstance(self::$db_config);
        $this->assertRegexp('/slave/', $db_obj->current_mode);
        $db_obj->changeMode(array('mode'=>'master'));
        $this->assertEquals('master', $db_obj->current_mode);
        $db_obj->changeMode(array('mode'=>'slave'));
        $this->assertRegexp('/slave/', $db_obj->current_mode);
        unset($db_obj);
        MasterSlaveDBAccess::destroyInstance();
<commit_msg>add test case testChangeMode<commit_after><?php
use iNDIEVOX\MasterSlaveDBAccess\MasterSlaveDBAccess;

class MasterSlaveDBAccessTest extends PHPUnit_Framework_TestCase
{

    protected static $db_config;
    protected static $no_slave_db_config;

    public static function setUpBeforeClass()
    {

        self::$db_config = array(
            "database_server" => array(
                "master"=>array(
                    "db_host"=>'localhost',
                    "db_name"=>'homestead',
                    "db_user"=>'root',
                    "db_password"=>''
                ),
                "slave1"=>array(
                    "db_host"=>'localhost',
                    "db_name"=>'homestead',
                    "db_user"=>'root',
                    "db_password"=>''
                ),
                "slave2"=>array(
                    "db_host"=>'localhost',
                    "db_name"=>'homestead',
                    "db_user"=>'root',
                    "db_password"=>'',
                )
            ),
            "slave_database_name" => array(
                'slave1',
                'slave2'
            )
        );

        self::$no_slave_db_config = array(
            "database_server" => array(
                "master"=>array(
                    "db_host"=>'localhost',
                    "db_name"=>'homestead',
                    "db_user"=>'root',
                    "db_password"=>''
                )
            ),
            "slave_database_name" => array()
        );

    }

    public static function tearDownAfterClass()
    {
        self::$db_config = null;
        self::$no_slave_db_config = null;
    }

    public function testGetInstance()
    {

        $db_obj = MasterSlaveDBAccess::getInstance(self::$no_slave_db_config);
        $db_obj = MasterSlaveDBAccess::getInstance(self::$no_slave_db_config);
        $db_obj = MasterSlaveDBAccess::getInstance(self::$no_slave_db_config);
        $this->assertEquals('master', $db_obj->current_mode);
        $this->assertEquals('one_time', $db_obj->context_status);
        unset($db_obj);
        MasterSlaveDBAccess::destroyInstance();

        $db_obj = MasterSlaveDBAccess::getInstance(self::$db_config);
        $db_obj = MasterSlaveDBAccess::getInstance(self::$db_config);
        $db_obj = MasterSlaveDBAccess::getInstance(self::$db_config);
        $this->assertRegexp('/slave/', $db_obj->current_mode);
        $this->assertEquals('one_time', $db_obj->context_status);
        unset($db_obj);
        MasterSlaveDBAccess::destroyInstance();

    }

    public function testConnectMaster()
    {

        $db_obj = MasterSlaveDBAccess::getInstance(self::$db_config);
        $db_obj->connectMaster();
        $this->assertEquals('master', $db_obj->current_mode);
        unset($db_obj);
        MasterSlaveDBAccess::destroyInstance();

    }

    public function testConnectSlave()
    {

        $db_obj = MasterSlaveDBAccess::getInstance(self::$no_slave_db_config);
        $this->assertEquals('master', $db_obj->current_mode);
        $db_obj->connectSlave();
        $this->assertEquals('master', $db_obj->current_mode);
        unset($db_obj);
        MasterSlaveDBAccess::destroyInstance();

        $db_obj = MasterSlaveDBAccess::getInstance(self::$db_config);
        $db_obj->connectSlave();
        $this->assertRegexp('/slave/', $db_obj->current_mode);
        unset($db_obj);
        MasterSlaveDBAccess::destroyInstance();

    }

    public function testChangeMode()
    {

        $db_obj = MasterSlaveDBAccess::getInstance(self::$db_config);
        $this->assertRegexp('/slave/', $db_obj->current_mode);
        $db_obj->changeMode(array('mode'=>'master'));
        $this->assertEquals('master', $db_obj->current_mode);
        $db_obj->changeMode(array('mode'=>'slave'));
        $this->assertRegexp('/slave/', $db_obj->current_mode);
        $db_obj->changeMode(array('mode'=>'master'));
        $db_obj->changeMode(array('mode'=>'slave'));
        $db_obj->changeMode(array('mode'=>'master'));
        $db_obj->changeMode(array('mode'=>'slave'));
        $db_obj->changeMode(array('mode'=>'master'));
        $db_obj->changeMode(array('mode'=>'slave'));
        $db_obj->changeMode(array('mode'=>'master'));
        $db_obj->changeMode(array('mode'=>'slave'));
        $this->assertRegexp('/slave/', $db_obj->current_mode);
        unset($db_obj);
        MasterSlaveDBAccess::destroyInstance();

{'fraction_non_alphanumeric': 0.15011933174224343, 'fraction_numerical': 0.0009546539379474941, 'mean_word_length': 2.3074191002367797, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 127, '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': '3809204', 'n_tokens_mistral': 2479, 'n_tokens_neox': 2474, 'n_words': 273}