<commit_before><?php
/*
 * This file is part of the Dive ORM framework.
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Dive\Test\Connection;

use Dive\Connection\Connection;

/**
 * @author <NAME> <<EMAIL>>
 * Date: 31.10.12
 */
class ConnectionTest extends \Dive\TestSuite\TestCase
{

    /**
     * @dataProvider provideGetScheme
     *
     * @param string $dsn
     * @param string $expected
     */
    public function testGetScheme($dsn, $expected)
    {
        /** @var \Dive\Connection\Driver\DriverInterface $driver */
        $driver = $this->getMockForAbstractClass('\Dive\Connection\Driver\DriverInterface');
        $conn = new \Dive\Connection\Connection($driver, $dsn);
        $this->assertEquals($expected, $conn->getScheme());
    }


    public function provideGetScheme()
    {
        return array(
            array('mysql:', 'mysql'),
            array('sqlite:', 'sqlite'),
            array('mssql::', 'mssql'),
        );
    }


    /**
     * @dataProvider provideTestConnectDisconnect
     */
    public function testConnect(array $database)
    {
        $events = array(Connection::EVENT_PRE_CONNECT, Connection::EVENT_POST_CONNECT);

        $conn = $this->createDatabaseConnection($database);

        // expected events will be gathered through closure calls
        $expectedEventsCalled = array();
        $eventDispatcher = $conn->getEventDispatcher();
        $this->addMockListenerToEventDispatcher($eventDispatcher, $events, $expectedEventsCalled);

        // connect database (events will be fired)
        $conn->connect();

        $this->assertTrue($conn->isConnected());
        $this->assertEquals($events, $expectedEventsCalled);
    }


    public function provideTestConnectDisconnect()
    {
        return $this->getDatabaseAwareTestCases();
    }


    /**
     * @dataProvider provideTestConnectDisconnect
     */
    public function testDisconnect(array $database)
    {
        $events = array(Connection::EVENT_PRE_DISCONNECT, Connection::EVENT_POST_DISCONNECT);

        $conn = $this->createDatabaseConnection($database);

        // expected events will be gathered through closure calls
        $expectedEventsCalled = array();
        $eventDispatcher = $conn->getEventDispatcher();
        $this->addMockListenerToEventDispatcher($eventDispatcher, $events, $expectedEventsCalled);

        // disconnect will be only processed, if connection has been established before
        $conn->connect();
        // disconnect database (events will be fired)
        $conn->disconnect();

        $this->assertFalse($conn->isConnected());
        $this->assertEquals($events, $expectedEventsCalled);
    }


    /**
     * @dataProvider provideGetDatabaseName
     */
    public function testGetDatabaseName($database)
    {
        $dsn = $database['dsn'];
        $search = 'dbname=';
        if (false === ($pos = strpos($dsn, $search))) {
            $this->markTestSkipped("No database name found in data source: $dsn!");
        }

        $pos += strlen($search);
        $posEnd = strpos($dsn, ';', $pos);
        $expectedDatabaseName = $posEnd !== false
            ? substr($dsn, $pos, $posEnd - $pos)
            : substr($dsn, $pos);

        $conn = $this->createDatabaseConnection($database);
        $this->assertEquals($expectedDatabaseName, $conn->getDatabaseName());
    }


    public function provideGetDatabaseName()
    {
        return $this->getDatabaseAwareTestCases();
    }

}<commit_msg>added some empty testcases for connection unit tests<commit_after><?php
/*
 * This file is part of the Dive ORM framework.
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Dive\Test\Connection;

use Dive\Connection\Connection;
use Dive\TestSuite\TestCase;

/**
 * @author <NAME> <<EMAIL>>
 * Date: 31.10.12
 */
class ConnectionTest extends TestCase
{

    /**
     * @dataProvider provideGetScheme
     *
     * @param string $dsn
     * @param string $expected
     */
    public function testGetScheme($dsn, $expected)
    {
        /** @var \Dive\Connection\Driver\DriverInterface $driver */
        $driver = $this->getMockForAbstractClass('\Dive\Connection\Driver\DriverInterface');
        $conn = new Connection($driver, $dsn);
        $this->assertEquals($expected, $conn->getScheme());
    }


    public function provideGetScheme()
    {
        return array(
            array('mysql:', 'mysql'),
            array('sqlite:', 'sqlite'),
            array('mssql::', 'mssql'),
        );
    }


    /**
     * @dataProvider provideTestConnectDisconnect
     */
    public function testConnect(array $database)
    {
        $events = array(Connection::EVENT_PRE_CONNECT, Connection::EVENT_POST_CONNECT);

        $conn = $this->createDatabaseConnection($database);

        // expected events will be gathered through closure calls
        $expectedEventsCalled = array();
        $eventDispatcher = $conn->getEventDispatcher();
        $this->addMockListenerToEventDispatcher($eventDispatcher, $events, $expectedEventsCalled);

        // connect database (events will be fired)
        $conn->connect();

        $this->assertTrue($conn->isConnected());
        $this->assertEquals($events, $expectedEventsCalled);
    }


    public function provideTestConnectDisconnect()
    {
        return $this->getDatabaseAwareTestCases();
    }


    /**
     * @dataProvider provideTestConnectDisconnect
     */
    public function testDisconnect(array $database)
    {
        $events = array(Connection::EVENT_PRE_DISCONNECT, Connection::EVENT_POST_DISCONNECT);

        $conn = $this->createDatabaseConnection($database);

        // expected events will be gathered through closure calls
        $expectedEventsCalled = array();
        $eventDispatcher = $conn->getEventDispatcher();
        $this->addMockListenerToEventDispatcher($eventDispatcher, $events, $expectedEventsCalled);

        // disconnect will be only processed, if connection has been established before
        $conn->connect();
        // disconnect database (events will be fired)
        $conn->disconnect();

        $this->assertFalse($conn->isConnected());
        $this->assertEquals($events, $expectedEventsCalled);
    }


    /**
     * @dataProvider provideGetDatabaseName
     */
    public function testGetDatabaseName($database)
    {
        $dsn = $database['dsn'];
        $search = 'dbname=';
        if (false === ($pos = strpos($dsn, $search))) {
            $this->markTestSkipped("No database name found in data source: $dsn!");
        }

        $pos += strlen($search);
        $posEnd = strpos($dsn, ';', $pos);
        $expectedDatabaseName = $posEnd !== false
            ? substr($dsn, $pos, $posEnd - $pos)
            : substr($dsn, $pos);

        $conn = $this->createDatabaseConnection($database);
        $this->assertEquals($expectedDatabaseName, $conn->getDatabaseName());
    }


    public function provideGetDatabaseName()
    {
        return $this->getDatabaseAwareTestCases();
    }


    // TODO!
    /**
     * @dataProvider provideGetStatement
     * @param $database
     * @param $sql
     * @param $params
     */
    public function testGetStatement($database, $sql, $params)
    {
        $conn = $this->createDatabaseConnection($database);

        $stmt = $conn->getStatement($sql, $params);
        $this->assertInstanceOf('\PDOStatement', $stmt);
    }


    public function provideGetStatement()
    {
        $testCases = array();

        $databases = $this->getDatabaseAwareTestCases();
        foreach ($databases as $database) {
            $sql = 'SELECT ?;';
            $params = array(1);
            $testCases[] = array($database, $sql, $params);
        }

        return $testCases;
    }


    // TODO!
    public function testQuery()
    {
        $this->markTestIncomplete();
    }


    // TODO!
    public function testExec()
    {
        $this->markTestIncomplete();
    }


    // TODO!
    public function testInsert()
    {
        $this->markTestIncomplete();
    }


    // TODO!
    public function testDelete()
    {
        $this->markTestIncomplete();
    }
}
{'fraction_non_alphanumeric': 0.13350125944584382, 'fraction_numerical': 0.0015593139018831713, 'mean_word_length': 2.6975609756097563, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 71, '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': '1444904', 'n_tokens_mistral': 2311, 'n_tokens_neox': 2249, 'n_words': 497}