N98\Util\Console\Helper\DatabaseHelperTest::getMysqlVariable PHP Method

getMysqlVariable() public method

public getMysqlVariable ( )
    public function getMysqlVariable()
    {
        $helper = $this->getHelper();
        // behaviour with existing global variable
        $actual = $helper->getMysqlVariable('version');
        $this->assertInternalType('string', $actual);
        // behavior with existent session variable (INTEGER)
        $helper->getConnection()->query('SET @existent = 14;');
        $actual = $helper->getMysqlVariable('existent', '@');
        $this->assertSame("14", $actual);
        // behavior with non-existent session variable
        $actual = $helper->getMysqlVariable('nonexistent', '@');
        $this->assertNull($actual);
        // behavior with non-existent global variable
        try {
            $helper->getMysqlVariable('nonexistent');
            $this->fail('An expected Exception has not been thrown');
        } catch (RuntimeException $e) {
            // test against the mysql error message
            $this->assertStringEndsWith("SQLSTATE[HY000]: 1193: Unknown system variable 'nonexistent'", $e->getMessage());
        }
        // invalid variable type
        try {
            $helper->getMysqlVariable('nonexistent', '@@@');
            $this->fail('An expected Exception has not been thrown');
        } catch (InvalidArgumentException $e) {
            // test against the mysql error message
            $this->assertEquals('Invalid mysql variable type "@@@", must be "@@" (system) or "@" (session)', $e->getMessage());
        }
    }