Skip to content

Collect query templates 2 #146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions src/Utils/FakeDriver/FakeConnection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php

declare(strict_types=1);

namespace Keboola\Db\ImportExport\Utils\FakeDriver;

use Doctrine\DBAL\Cache\ArrayResult;
use Doctrine\DBAL\Driver\Connection;
use Doctrine\DBAL\ParameterType;
use Exception;

class FakeConnection implements Connection
{
/** @var resource */
private $conn;

private array $queries = [];

/**
* @param mixed[]|null $options
*/
public function __construct()
{
// do nothing
}

public function getPreparedQueries(): array
{
return $this->queries;
}

public function query(string $sql): ArrayResult
{
$stmt = $this->prepare($sql);
return $stmt->execute();
}

public function prepare(string $sql): FakeStatement
{
$this->queries[] = $sql;

return new FakeStatement($this->conn, $sql);
}

/**
* @inheritDoc
*/
public function quote($value, $type = ParameterType::STRING): string
{
return $value;
}

public function exec(string $sql): int
{
$stmt = $this->prepare($sql);
$result = $stmt->execute();

return $result->rowCount();
}

/**
* @inheritDoc
*/
public function lastInsertId($name = null)
{
throw new Exception('method is not implemented yet');
}

public function beginTransaction(): bool
{
throw new Exception('method is not implemented yet');
}

private function inTransaction(): bool
{
throw new Exception('method is not implemented yet');
}

public function commit(): bool
{
throw new Exception('method is not implemented yet');
}

public function rollBack(): bool
{
throw new Exception('method is not implemented yet');
}
}
64 changes: 64 additions & 0 deletions src/Utils/FakeDriver/FakeConnectionFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

declare(strict_types=1);

namespace Keboola\Db\ImportExport\Utils\FakeDriver;

use Doctrine\DBAL\Configuration;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DriverManager;

class FakeConnectionFactory
{
/**
* @param array{
* 'port'?:string,
* 'warehouse'?:string,
* 'database'?:string,
* 'schema'?:string,
* 'tracing'?:int,
* 'loginTimeout'?:int,
* 'networkTimeout'?:int,
* 'queryTimeout'?: int,
* 'clientSessionKeepAlive'?: bool,
* 'maxBackoffAttempts'?:int
* } $params
*/
public static function getConnection(
string $host = 'fakehost',
string $user = 'fakeuser',
string $password = 'fakepassword',
array $params = [],
?Configuration $config = null
): Connection {
/** @var array{
* 'port'?:string,
* 'warehouse'?:string,
* 'database'?:string,
* 'schema'?:string,
* 'tracing'?:int,
* 'loginTimeout'?:int,
* 'networkTimeout'?:int,
* 'queryTimeout'?: int,
* 'clientSessionKeepAlive'?: bool,
* 'maxBackoffAttempts'?:int,
* 'driverClass': class-string<Doctrine\DBAL\Driver>,
* 'host': string,
* 'user': string,
* 'password': string,
* } $params */
$params = array_merge(
$params,
[
'driverClass' => FakeDriver::class,
'host' => $host,
'user' => $user,
'password' => $password,
]
);
return DriverManager::getConnection(
$params,
$config
);
}
}
51 changes: 51 additions & 0 deletions src/Utils/FakeDriver/FakeDriver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

declare(strict_types=1);

namespace Keboola\Db\ImportExport\Utils\FakeDriver;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Platforms\AbstractPlatform;

class FakeDriver implements Driver
{
/**
* @param array{
* 'host':string,
* 'user':string,
* 'password':string,
* 'port'?:string,
* 'warehouse'?:string,
* 'database'?:string,
* 'schema'?:string,
* 'tracing'?:int,
* 'loginTimeout'?:int,
* 'networkTimeout'?:int,
* 'queryTimeout'?: int,
* 'clientSessionKeepAlive'?: bool,
* 'maxBackoffAttempts'?:int
* } $params
*/
public function connect(
array $params
): FakeConnection {
return new FakeConnection();
}

public function getDatabasePlatform(): FakePlatform
{
return new FakePlatform();
}

public function getSchemaManager(Connection $conn, AbstractPlatform $platform): FakeSchemaManager
{
assert($platform instanceof FakePlatform);
return new FakeSchemaManager($conn, $platform);
}

public function getExceptionConverter(): FakeExceptionConverter
{
return new FakeExceptionConverter();
}
}
18 changes: 18 additions & 0 deletions src/Utils/FakeDriver/FakeExceptionConverter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace Keboola\Db\ImportExport\Utils\FakeDriver;

use Doctrine\DBAL\Driver\API\ExceptionConverter;
use Doctrine\DBAL\Driver\Exception;
use Doctrine\DBAL\Exception\DriverException;
use Doctrine\DBAL\Query;

class FakeExceptionConverter implements ExceptionConverter
{
public function convert(Exception $exception, ?Query $query): DriverException
{
return new DriverException($exception, $query);
}
}
101 changes: 101 additions & 0 deletions src/Utils/FakeDriver/FakePlatform.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?php

declare(strict_types=1);

namespace Keboola\Db\ImportExport\Utils\FakeDriver;

use Doctrine\DBAL\Platforms\AbstractPlatform;
use Exception;

class FakePlatform extends AbstractPlatform
{
/**
* @inheritDoc
*/
public function getBooleanTypeDeclarationSQL(array $column)
{
throw new Exception('method is not implemented yet');
// TODO: Implement getBooleanTypeDeclarationSQL() method.
}

/**
* @inheritDoc
*/
public function getIntegerTypeDeclarationSQL(array $column)
{
throw new Exception('method is not implemented yet');
// TODO: Implement getIntegerTypeDeclarationSQL() method.
}

/**
* @inheritDoc
*/
public function getBigIntTypeDeclarationSQL(array $column)
{
throw new Exception('method is not implemented yet');
// TODO: Implement getBigIntTypeDeclarationSQL() method.
}

/**
* @inheritDoc
*/
public function getSmallIntTypeDeclarationSQL(array $column)
{
throw new Exception('method is not implemented yet');
// TODO: Implement getSmallIntTypeDeclarationSQL() method.
}

/**
* @inheritDoc
*/
protected function _getCommonIntegerTypeDeclarationSQL(array $column)
{
throw new Exception('method is not implemented yet');
// TODO: Implement _getCommonIntegerTypeDeclarationSQL() method.
}

/**
* @inheritDoc
*/
protected function initializeDoctrineTypeMappings()
{
throw new Exception('method is not implemented yet');
// TODO: Implement initializeDoctrineTypeMappings() method.
}

/**
* @inheritDoc
*/
public function getClobTypeDeclarationSQL(array $column)
{
throw new Exception('method is not implemented yet');
// TODO: Implement getClobTypeDeclarationSQL() method.
}

/**
* @inheritDoc
*/
public function getBlobTypeDeclarationSQL(array $column)
{
throw new Exception('method is not implemented yet');
// TODO: Implement getBlobTypeDeclarationSQL() method.
}

/**
* @inheritDoc
*/
public function getName()
{
throw new Exception('method is not implemented yet');
// TODO: Implement getName() method.
}

/**
* @inheritDoc
*/
public function getCurrentDatabaseExpression(): string
{
throw new Exception('method is not implemented yet');
// TODO: Implement getCurrentDatabaseExpression() method.
}
}
26 changes: 26 additions & 0 deletions src/Utils/FakeDriver/FakeSchemaManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace Keboola\Db\ImportExport\Utils\FakeDriver;

use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Exception;

/**
* @extends AbstractSchemaManager<FakePlatform>
*/
class FakeSchemaManager extends AbstractSchemaManager
{
/**
* @param string[] $tableColumn
* @throws Exception
*/
// because of compatibility with interface
// phpcs:ignore SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint, SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingNativeTypeHint
protected function _getPortableTableColumnDefinition($tableColumn)
{
throw new Exception('method is not implemented yet');
// TODO: Implement _getPortableTableColumnDefinition() method.
}
}
Loading