PDOStatementTest.php 1.48 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
<?php

namespace Doctrine\Tests\DBAL\Functional;

use Doctrine\DBAL\Driver\PDOConnection;
use Doctrine\DBAL\Schema\Table;
use Doctrine\Tests\DbalFunctionalTestCase;
use PDO;
use function extension_loaded;

class PDOStatementTest extends DbalFunctionalTestCase
{
13
    protected function setUp() : void
14 15 16 17 18 19 20
    {
        if (! extension_loaded('pdo')) {
            $this->markTestSkipped('PDO is not installed');
        }

        parent::setUp();

Sergei Morozov's avatar
Sergei Morozov committed
21
        if (! $this->connection->getWrappedConnection() instanceof PDOConnection) {
22 23 24 25 26
            $this->markTestSkipped('PDO-only test');
        }

        $table = new Table('stmt_test');
        $table->addColumn('id', 'integer');
27
        $table->addColumn('name', 'string');
Sergei Morozov's avatar
Sergei Morozov committed
28
        $this->connection->getSchemaManager()->dropAndCreateTable($table);
29 30 31 32
    }

    /**
     * @group legacy
33
     * @expectedDeprecation Using a PDO fetch mode or their combination (%d given) is deprecated and will cause an error in Doctrine DBAL 3.0
34
     */
35
    public function testPDOSpecificModeIsAccepted() : void
36
    {
Sergei Morozov's avatar
Sergei Morozov committed
37
        $this->connection->insert('stmt_test', [
38 39 40
            'id' => 1,
            'name' => 'Alice',
        ]);
Sergei Morozov's avatar
Sergei Morozov committed
41
        $this->connection->insert('stmt_test', [
42 43 44 45
            'id' => 2,
            'name' => 'Bob',
        ]);

Sergei Morozov's avatar
Sergei Morozov committed
46
        $data = $this->connection->query('SELECT id, name FROM stmt_test ORDER BY id')
47 48 49 50 51 52 53 54
            ->fetchAll(PDO::FETCH_KEY_PAIR);

        self::assertSame([
            1 => 'Alice',
            2 => 'Bob',
        ], $data);
    }
}