Skip to content

Commit 8f20e31

Browse files
Adjust to changes in yiisoft/cache
1 parent 0847b33 commit 8f20e31

4 files changed

Lines changed: 33 additions & 32 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ composer require yiisoft/db-pgsql
3939

4040
## Configuration
4141

42-
Using yiisoft/composer-config-plugin automatically get the settings of `Psr\SimpleCache\CacheInterface::class`, `LoggerInterface::class`, and `Profiler::class`.
42+
Using yiisoft/composer-config-plugin automatically get the settings of `Yiisoft\Cache\CacheInterface::class`, `LoggerInterface::class`, and `Profiler::class`.
4343

4444
Di-Container:
4545

src/Schema.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,13 @@
44

55
namespace Yiisoft\Db\Pgsql;
66

7-
use function array_change_key_case;
8-
use function array_merge;
9-
use function array_unique;
10-
use function array_values;
11-
use function bindec;
12-
use function explode;
13-
use function implode;
147
use JsonException;
158
use PDO;
16-
use function preg_match;
17-
use function preg_replace;
18-
use function str_replace;
19-
use function substr;
209
use Throwable;
2110
use Yiisoft\Arrays\ArrayHelper;
2211
use Yiisoft\Db\Constraint\CheckConstraint;
2312
use Yiisoft\Db\Constraint\Constraint;
2413
use Yiisoft\Db\Constraint\ConstraintFinderInterface;
25-
2614
use Yiisoft\Db\Constraint\ConstraintFinderTrait;
2715
use Yiisoft\Db\Constraint\DefaultValueConstraint;
2816
use Yiisoft\Db\Constraint\ForeignKeyConstraint;
@@ -35,6 +23,18 @@
3523
use Yiisoft\Db\Schema\Schema as AbstractSchema;
3624
use Yiisoft\Db\View\ViewFinderTrait;
3725

26+
use function array_change_key_case;
27+
use function array_merge;
28+
use function array_unique;
29+
use function array_values;
30+
use function bindec;
31+
use function explode;
32+
use function implode;
33+
use function preg_match;
34+
use function preg_replace;
35+
use function str_replace;
36+
use function substr;
37+
3838
final class Schema extends AbstractSchema implements ConstraintFinderInterface
3939
{
4040
use ConstraintFinderTrait;
@@ -763,7 +763,7 @@ public function insert(string $table, array $columns)
763763

764764
if (!empty($returnColumns)) {
765765
$returning = [];
766-
foreach ((array) $returnColumns as $name) {
766+
foreach ($returnColumns as $name) {
767767
$returning[] = $this->quoteColumnName($name);
768768
}
769769
$sql .= ' RETURNING ' . implode(', ', $returning);

tests/ConnectionTest.php

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,9 @@ public function testGetPdoAfterClose(): void
203203

204204
public function testServerStatusCacheWorks(): void
205205
{
206-
$db = $this->getConnection();
206+
$cacheKeyNormalizer = new CacheKeyNormalizer();
207+
208+
$db = $this->getConnection(true);
207209

208210
$db->setMasters(
209211
'1',
@@ -219,24 +221,24 @@ public function testServerStatusCacheWorks(): void
219221

220222
$db->setShuffleMasters(false);
221223

222-
$cacheKey = (new CacheKeyNormalizer())->normalize(
224+
$cacheKey = $cacheKeyNormalizer->normalize(
223225
['Yiisoft\Db\Connection\Connection::openFromPoolSequentially', $db->getDsn()]
224226
);
225227

226-
$this->assertFalse($this->cache->has($cacheKey));
228+
$this->assertFalse($this->cache->psr()->has($cacheKey));
227229

228230
$db->open();
229231

230232
$this->assertFalse(
231-
$this->cache->has($cacheKey),
233+
$this->cache->psr()->has($cacheKey),
232234
'Connection was successful – cache must not contain information about this DSN'
233235
);
234236

235237
$db->close();
236238

237239
$db = $this->getConnection();
238240

239-
$cacheKey = (new CacheKeyNormalizer())->normalize(
241+
$cacheKey = $cacheKeyNormalizer->normalize(
240242
['Yiisoft\Db\Connection\Connection::openFromPoolSequentially', 'host:invalid']
241243
);
242244

@@ -260,7 +262,7 @@ public function testServerStatusCacheWorks(): void
260262
}
261263

262264
$this->assertTrue(
263-
$this->cache->has($cacheKey),
265+
$this->cache->psr()->has($cacheKey),
264266
'Connection was not successful – cache must contain information about this DSN'
265267
);
266268

@@ -269,7 +271,9 @@ public function testServerStatusCacheWorks(): void
269271

270272
public function testServerStatusCacheCanBeDisabled(): void
271273
{
272-
$this->cache->clear();
274+
$cacheKeyNormalizer = new CacheKeyNormalizer();
275+
276+
$this->cache->psr()->clear();
273277

274278
$db = $this->getConnection();
275279

@@ -289,19 +293,19 @@ public function testServerStatusCacheCanBeDisabled(): void
289293

290294
$db->setShuffleMasters(false);
291295

292-
$cacheKey = (new CacheKeyNormalizer())->normalize(
296+
$cacheKey = $cacheKeyNormalizer->normalize(
293297
['Yiisoft\Db\Connection\Connection::openFromPoolSequentially', $db->getDsn()]
294298
);
295299

296-
$this->assertFalse($this->cache->has($cacheKey));
300+
$this->assertFalse($this->cache->psr()->has($cacheKey));
297301

298302
$db->open();
299303

300-
$this->assertFalse($this->cache->has($cacheKey), 'Caching is disabled');
304+
$this->assertFalse($this->cache->psr()->has($cacheKey), 'Caching is disabled');
301305

302306
$db->close();
303307

304-
$cacheKey = (new CacheKeyNormalizer())->normalize(
308+
$cacheKey = $cacheKeyNormalizer->normalize(
305309
['Yiisoft\Db\Connection\Connection::openFromPoolSequentially', 'host:invalid']
306310
);
307311

@@ -322,7 +326,7 @@ public function testServerStatusCacheCanBeDisabled(): void
322326
} catch (InvalidConfigException $e) {
323327
}
324328

325-
$this->assertFalse($this->cache->has($cacheKey), 'Caching is disabled');
329+
$this->assertFalse($this->cache->psr()->has($cacheKey), 'Caching is disabled');
326330

327331
$db->close();
328332
}

tests/TestCase.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
namespace Yiisoft\Db\Pgsql\Tests;
66

7+
use Exception;
78
use PHPUnit\Framework\TestCase as AbstractTestCase;
89
use Psr\Container\ContainerInterface;
910
use Psr\Log\LoggerInterface;
10-
use Psr\SimpleCache\CacheInterface as SimpleCacheInterface;
1111
use ReflectionClass;
1212
use ReflectionException;
1313
use ReflectionObject;
@@ -19,7 +19,6 @@
1919
use Yiisoft\Db\Cache\SchemaCache;
2020
use Yiisoft\Db\Connection\ConnectionInterface;
2121
use Yiisoft\Db\Connection\Dsn;
22-
use Yiisoft\Db\Exception\Exception;
2322
use Yiisoft\Db\Factory\DatabaseFactory;
2423
use Yiisoft\Db\Pgsql\Connection;
2524
use Yiisoft\Db\TestUtility\IsOneOfAssert;
@@ -36,7 +35,7 @@
3635
class TestCase extends AbstractTestCase
3736
{
3837
protected Aliases $aliases;
39-
protected SimpleCacheInterface $cache;
38+
protected CacheInterface $cache;
4039
protected Connection $connection;
4140
protected ContainerInterface $container;
4241
protected array $dataProvider;
@@ -108,7 +107,7 @@ protected function configContainer(): void
108107
$this->aliases = $this->container->get(Aliases::class);
109108
$this->logger = $this->container->get(LoggerInterface::class);
110109
$this->profiler = $this->container->get(Profiler::class);
111-
$this->cache = $this->container->get(SimpleCacheInterface::class);
110+
$this->cache = $this->container->get(CacheInterface::class);
112111
$this->connection = $this->container->get(ConnectionInterface::class);
113112
$this->queryCache = $this->container->get(QueryCache::class);
114113
$this->schemaCache = $this->container->get(SchemaCache::class);
@@ -291,8 +290,6 @@ private function config(): array
291290
],
292291
],
293292

294-
SimpleCacheInterface::class => CacheInterface::class,
295-
296293
LoggerInterface::class => Logger::class,
297294

298295
ConnectionInterface::class => [

0 commit comments

Comments
 (0)