|
4 | 4 |
|
5 | 5 | namespace Cycle\Database\Tests\Functional\Driver\Common\Driver;
|
6 | 6 |
|
| 7 | +use Cycle\Database\Config\DriverConfig; |
| 8 | +use Cycle\Database\Driver\Driver; |
| 9 | +use Cycle\Database\Exception\StatementException; |
7 | 10 | use Cycle\Database\Tests\Functional\Driver\Common\BaseTest;
|
8 | 11 |
|
9 | 12 | abstract class DriverTest extends BaseTest
|
@@ -59,4 +62,62 @@ public function datetimeDataProvider(): \Traversable
|
59 | 62 | yield [new class('2000-01-23T01:23:45.678+09:00') extends \DateTimeImmutable {}];
|
60 | 63 | yield [new class('2000-01-23T01:23:45.678+09:00') extends \DateTime {}];
|
61 | 64 | }
|
| 65 | + |
| 66 | + public function testClearCache(): void |
| 67 | + { |
| 68 | + $driver = $this->mockDriver(); |
| 69 | + |
| 70 | + $driver->testPolluteCache(); |
| 71 | + self::assertNotEmpty($driver->testGetCache()); |
| 72 | + |
| 73 | + $driver->clearCache(); |
| 74 | + |
| 75 | + self::assertEmpty($driver->testGetCache()); |
| 76 | + } |
| 77 | + |
| 78 | + public function testWithoutCache(): void |
| 79 | + { |
| 80 | + $driver = $this->mockDriver(); |
| 81 | + $driver->testPolluteCache(); |
| 82 | + self::assertNotEmpty($driver->testGetCache()); |
| 83 | + |
| 84 | + $new = $driver->withoutCache(); |
| 85 | + |
| 86 | + self::assertNotEmpty($driver->testGetCache()); |
| 87 | + self::assertEmpty($new->testGetCache()); |
| 88 | + } |
| 89 | + |
| 90 | + private function mockDriver(): Driver |
| 91 | + { |
| 92 | + return new class extends Driver { |
| 93 | + public function __construct() {} |
| 94 | + |
| 95 | + public function testPolluteCache(): void |
| 96 | + { |
| 97 | + $this->queryCache[] = ['sql' => 'SELECT * FROM table', 'params' => []]; |
| 98 | + } |
| 99 | + |
| 100 | + public function testGetCache(): array |
| 101 | + { |
| 102 | + return $this->queryCache; |
| 103 | + } |
| 104 | + |
| 105 | + protected function mapException(\Throwable $exception, string $query): StatementException |
| 106 | + { |
| 107 | + throw new \Exception('not needed'); |
| 108 | + } |
| 109 | + |
| 110 | + public static function create(DriverConfig $config): \Cycle\Database\Driver\DriverInterface |
| 111 | + { |
| 112 | + throw new \Exception('not needed'); |
| 113 | + } |
| 114 | + |
| 115 | + public function getType(): string |
| 116 | + { |
| 117 | + throw new \Exception('not needed'); |
| 118 | + } |
| 119 | + |
| 120 | + public function __clone(): void {} |
| 121 | + }; |
| 122 | + } |
62 | 123 | }
|
0 commit comments