From a1e3be1cb6caceb6afc00ff8ffaa3f4870d42068 Mon Sep 17 00:00:00 2001 From: github-actions Date: Tue, 18 Mar 2025 10:49:11 +0000 Subject: [PATCH 1/5] style(php-cs-fixer): fix coding standards --- src/Driver/Jsoner.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Driver/Jsoner.php b/src/Driver/Jsoner.php index 7bc50eaa..fe08c02c 100644 --- a/src/Driver/Jsoner.php +++ b/src/Driver/Jsoner.php @@ -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.'); } From a43105e50f9af4350cedefaa2bf80d66e5c8c0af Mon Sep 17 00:00:00 2001 From: Igor Markin Date: Tue, 18 Mar 2025 13:54:45 +0300 Subject: [PATCH 2/5] Add public clearCache method --- src/Driver/Driver.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Driver/Driver.php b/src/Driver/Driver.php index 6e86a839..40f3787f 100644 --- a/src/Driver/Driver.php +++ b/src/Driver/Driver.php @@ -110,6 +110,11 @@ public function withoutCache(): static return $driver; } + public function clearCache(): void + { + $this->queryCache = []; + } + /** * Get driver source database or file name. * @@ -132,7 +137,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; } @@ -171,7 +176,7 @@ public function isConnected(): bool public function disconnect(): void { try { - $this->queryCache = []; + $this->clearCache(); $this->pdo = null; } catch (\Throwable $e) { // disconnect error From ab6e5c23dc96defff655d3ddd426c82e376d9744 Mon Sep 17 00:00:00 2001 From: github-actions Date: Thu, 27 Mar 2025 14:59:31 +0000 Subject: [PATCH 3/5] style(php-cs-fixer): fix coding standards --- src/Schema/AbstractColumn.php | 18 +++++++++--------- .../Driver/Common/Schema/CommentTest.php | 1 - tests/generate.php | 8 ++++---- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/Schema/AbstractColumn.php b/src/Schema/AbstractColumn.php index a9078841..f83ceb79 100644 --- a/src/Schema/AbstractColumn.php +++ b/src/Schema/AbstractColumn.php @@ -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. * @@ -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 ''; - } } diff --git a/tests/Database/Functional/Driver/Common/Schema/CommentTest.php b/tests/Database/Functional/Driver/Common/Schema/CommentTest.php index 963065c1..2671d3f9 100644 --- a/tests/Database/Functional/Driver/Common/Schema/CommentTest.php +++ b/tests/Database/Functional/Driver/Common/Schema/CommentTest.php @@ -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; diff --git a/tests/generate.php b/tests/generate.php index 6661267b..eff3e9ac 100644 --- a/tests/generate.php +++ b/tests/generate.php @@ -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'], @@ -67,7 +67,7 @@ \str_replace('\\', '/', $class->getFileName()), ); - $path = ltrim($path, '/'); + $path = \ltrim($path, '/'); foreach ($databases as $driver => $details) { $filename = $details['directory'] . $path; From cad1ce449ca7a8bfc76d69381e24a33cccc5689e Mon Sep 17 00:00:00 2001 From: roxblnfk Date: Thu, 27 Mar 2025 19:21:06 +0400 Subject: [PATCH 4/5] tests: cove Driver::cleanCache() and ::withoutCache() --- src/Driver/Driver.php | 7 ++- .../Driver/Common/Driver/DriverTest.php | 61 +++++++++++++++++++ 2 files changed, 65 insertions(+), 3 deletions(-) diff --git a/src/Driver/Driver.php b/src/Driver/Driver.php index 40f3787f..72ca2904 100644 --- a/src/Driver/Driver.php +++ b/src/Driver/Driver.php @@ -106,11 +106,12 @@ public function withoutCache(): static $driver = clone $this; $driver->useCache = false; + $driver->queryCache = []; return $driver; } - public function clearCache(): void + public function cleanCache(): void { $this->queryCache = []; } @@ -137,7 +138,7 @@ public function getTimezone(): \DateTimeZone public function getSchemaHandler(): HandlerInterface { // do not allow to carry prepared statements between schema changes - $this->clearCache(); + $this->cleanCache(); return $this->schemaHandler; } @@ -176,7 +177,7 @@ public function isConnected(): bool public function disconnect(): void { try { - $this->clearCache(); + $this->cleanCache(); $this->pdo = null; } catch (\Throwable $e) { // disconnect error diff --git a/tests/Database/Functional/Driver/Common/Driver/DriverTest.php b/tests/Database/Functional/Driver/Common/Driver/DriverTest.php index 509a16ef..32f7f7b6 100644 --- a/tests/Database/Functional/Driver/Common/Driver/DriverTest.php +++ b/tests/Database/Functional/Driver/Common/Driver/DriverTest.php @@ -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 @@ -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 testCleanCache(): void + { + $driver = $this->mockDriver(); + + $driver->testPolluteCache(); + self::assertNotEmpty($driver->testGetCache()); + + $driver->cleanCache(); + + 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 {} + }; + } } From 6c7d4c1f31eab6165084605bab20211ee53e6f3c Mon Sep 17 00:00:00 2001 From: roxblnfk Date: Thu, 27 Mar 2025 19:28:50 +0400 Subject: [PATCH 5/5] chore: rename Driver::cleanCache to clearCache --- src/Driver/Driver.php | 6 +++--- .../Database/Functional/Driver/Common/Driver/DriverTest.php | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Driver/Driver.php b/src/Driver/Driver.php index 72ca2904..852239ac 100644 --- a/src/Driver/Driver.php +++ b/src/Driver/Driver.php @@ -111,7 +111,7 @@ public function withoutCache(): static return $driver; } - public function cleanCache(): void + public function clearCache(): void { $this->queryCache = []; } @@ -138,7 +138,7 @@ public function getTimezone(): \DateTimeZone public function getSchemaHandler(): HandlerInterface { // do not allow to carry prepared statements between schema changes - $this->cleanCache(); + $this->clearCache(); return $this->schemaHandler; } @@ -177,7 +177,7 @@ public function isConnected(): bool public function disconnect(): void { try { - $this->cleanCache(); + $this->clearCache(); $this->pdo = null; } catch (\Throwable $e) { // disconnect error diff --git a/tests/Database/Functional/Driver/Common/Driver/DriverTest.php b/tests/Database/Functional/Driver/Common/Driver/DriverTest.php index 32f7f7b6..e09519b9 100644 --- a/tests/Database/Functional/Driver/Common/Driver/DriverTest.php +++ b/tests/Database/Functional/Driver/Common/Driver/DriverTest.php @@ -63,14 +63,14 @@ public function datetimeDataProvider(): \Traversable yield [new class('2000-01-23T01:23:45.678+09:00') extends \DateTime {}]; } - public function testCleanCache(): void + public function testClearCache(): void { $driver = $this->mockDriver(); $driver->testPolluteCache(); self::assertNotEmpty($driver->testGetCache()); - $driver->cleanCache(); + $driver->clearCache(); self::assertEmpty($driver->testGetCache()); }