1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
<?php
namespace Doctrine\DBAL\Tests\Functional\Driver\PDO\SQLite;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver as DriverInterface;
use Doctrine\DBAL\Driver\PDO\SQLite\Driver;
use Doctrine\DBAL\Tests\Functional\Driver\AbstractDriverTest;
use Doctrine\DBAL\Tests\TestUtil;
use Doctrine\Deprecations\PHPUnit\VerifyDeprecations;
/** @requires extension pdo_sqlite */
class DriverTest extends AbstractDriverTest
{
use VerifyDeprecations;
protected function setUp(): void
{
parent::setUp();
if (TestUtil::isDriverOneOf('pdo_sqlite')) {
return;
}
self::markTestSkipped('This test requires the pdo_sqlite driver.');
}
protected static function getDatabaseNameForConnectionWithoutDatabaseNameParameter(): ?string
{
return 'main';
}
protected function createDriver(): DriverInterface
{
return new Driver();
}
public function testRegisterCustomFunction(): void
{
$params = $this->connection->getParams();
$params['driverOptions']['userDefinedFunctions'] = [
'my_add' => ['callback' => static fn (int $a, int $b): int => $a + $b, 'numArgs' => 2],
];
$connection = new Connection(
$params,
$this->connection->getDriver(),
$this->connection->getConfiguration(),
$this->connection->getEventManager(),
);
$this->expectDeprecationWithIdentifier('https://github.com/doctrine/dbal/pull/5742');
self::assertSame(42, (int) $connection->fetchOne('SELECT my_add(20, 22)'));
}
}
|