Skip to content
Merged
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
10 changes: 8 additions & 2 deletions src/Driver/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,16 @@ public function withoutCache(): static

$driver = clone $this;
$driver->useCache = false;
$driver->queryCache = [];

return $driver;
}

public function clearCache(): void
{
$this->queryCache = [];
}

/**
* Get driver source database or file name.
*
Expand All @@ -132,7 +138,7 @@ public function getTimezone(): \DateTimeZone
public function getSchemaHandler(): HandlerInterface
{
// do not allow to carry prepared statements between schema changes
$this->queryCache = [];
$this->clearCache();

return $this->schemaHandler;
}
Expand Down Expand Up @@ -171,7 +177,7 @@ public function isConnected(): bool
public function disconnect(): void
{
try {
$this->queryCache = [];
$this->clearCache();
$this->pdo = null;
} catch (\Throwable $e) {
// disconnect error
Expand Down
2 changes: 1 addition & 1 deletion src/Driver/Jsoner.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static function toJson(mixed $value, bool $encode = true, bool $validate

$result = (string) $value;

if ($validate && !json_validate($result)) {
if ($validate && !\json_validate($result)) {
throw new BuilderException('Invalid JSON value.');
}

Expand Down
18 changes: 9 additions & 9 deletions src/Schema/AbstractColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,15 @@ public function isReadonlySchema(): bool
return $this->getAttributes()['readonlySchema'] ?? false;
}

/**
* Get column comment.
* An empty string will be returned if the feature is not supported by the driver.
*/
public function getComment(): string
{
return '';
}

/**
* Shortcut for AbstractColumn->type() method.
*
Expand Down Expand Up @@ -785,13 +794,4 @@ protected function formatDatetime(
default => $value,
};
}

/**
* Get column comment.
* An empty string will be returned if the feature is not supported by the driver.
*/
public function getComment(): string
{
return '';
}
}
61 changes: 61 additions & 0 deletions tests/Database/Functional/Driver/Common/Driver/DriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

namespace Cycle\Database\Tests\Functional\Driver\Common\Driver;

use Cycle\Database\Config\DriverConfig;
use Cycle\Database\Driver\Driver;
use Cycle\Database\Exception\StatementException;
use Cycle\Database\Tests\Functional\Driver\Common\BaseTest;

abstract class DriverTest extends BaseTest
Expand Down Expand Up @@ -59,4 +62,62 @@ public function datetimeDataProvider(): \Traversable
yield [new class('2000-01-23T01:23:45.678+09:00') extends \DateTimeImmutable {}];
yield [new class('2000-01-23T01:23:45.678+09:00') extends \DateTime {}];
}

public function testClearCache(): void
{
$driver = $this->mockDriver();

$driver->testPolluteCache();
self::assertNotEmpty($driver->testGetCache());

$driver->clearCache();

self::assertEmpty($driver->testGetCache());
}

public function testWithoutCache(): void
{
$driver = $this->mockDriver();
$driver->testPolluteCache();
self::assertNotEmpty($driver->testGetCache());

$new = $driver->withoutCache();

self::assertNotEmpty($driver->testGetCache());
self::assertEmpty($new->testGetCache());
}

private function mockDriver(): Driver
{
return new class extends Driver {
public function __construct() {}

public function testPolluteCache(): void
{
$this->queryCache[] = ['sql' => 'SELECT * FROM table', 'params' => []];
}

public function testGetCache(): array
{
return $this->queryCache;
}

protected function mapException(\Throwable $exception, string $query): StatementException
{
throw new \Exception('not needed');
}

public static function create(DriverConfig $config): \Cycle\Database\Driver\DriverInterface
{
throw new \Exception('not needed');
}

public function getType(): string
{
throw new \Exception('not needed');
}

public function __clone(): void {}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Cycle\Database\Tests\Functional\Driver\Common\Schema;

// phpcs:ignore
use Cycle\Database\ColumnInterface;
use Cycle\Database\Tests\Functional\Driver\Common\BaseTest;
use Cycle\Database\Tests\Utils\DontGenerateAttribute;

Expand Down
8 changes: 4 additions & 4 deletions tests/generate.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
use Cycle\Database\Tests\Utils\DontGenerateAttribute;
use Spiral\Tokenizer;

error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', '1');
\error_reporting(E_ALL | E_STRICT);
\ini_set('display_errors', '1');

//Composer
require_once dirname(__DIR__) . '/vendor/autoload.php';
require_once \dirname(__DIR__) . '/vendor/autoload.php';

$tokenizer = new Tokenizer\Tokenizer(new Tokenizer\Config\TokenizerConfig([
'directories' => [__DIR__ . '/Database/Functional/Driver/Common'],
Expand Down Expand Up @@ -67,7 +67,7 @@
\str_replace('\\', '/', $class->getFileName()),
);

$path = ltrim($path, '/');
$path = \ltrim($path, '/');

foreach ($databases as $driver => $details) {
$filename = $details['directory'] . $path;
Expand Down
Loading