|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Yiisoft\Db\Tests; |
|
6
|
|
|
|
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
|
8
|
|
|
use Yiisoft\Db\Connection\ConnectionInterface; |
|
9
|
|
|
|
|
10
|
|
|
abstract class AbstractCommandQueryCacheTest extends TestCase |
|
11
|
|
|
{ |
|
12
|
|
|
public function testQueryCache(): void |
|
13
|
|
|
{ |
|
14
|
|
|
$db = $this->getConnection(); |
|
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
$command = $db->createCommand('SELECT [[name]] FROM {{customer}} WHERE [[id]] = :id'); |
|
17
|
|
|
|
|
18
|
|
|
$this->assertSame('user1', $command->bindValue(':id', 1)->queryScalar()); |
|
19
|
|
|
|
|
20
|
|
|
$update = $db->createCommand('UPDATE {{customer}} SET [[name]] = :name WHERE [[id]] = :id'); |
|
21
|
|
|
$update->bindValues([':id' => 1, ':name' => 'user11'])->execute(); |
|
22
|
|
|
|
|
23
|
|
|
$this->assertSame('user11', $command->bindValue(':id', 1)->queryScalar()); |
|
24
|
|
|
|
|
25
|
|
|
$db->cache(function (ConnectionInterface $db) use ($command, $update) { |
|
26
|
|
|
$this->assertSame('user2', $command->bindValue(':id', 2)->queryScalar()); |
|
27
|
|
|
|
|
28
|
|
|
$update->bindValues([':id' => 2, ':name' => 'user22'])->execute(); |
|
29
|
|
|
|
|
30
|
|
|
$this->assertSame('user2', $command->bindValue(':id', 2)->queryScalar()); |
|
31
|
|
|
|
|
32
|
|
|
$db->noCache(function () use ($command) { |
|
33
|
|
|
$this->assertSame('user22', $command->bindValue(':id', 2)->queryScalar()); |
|
34
|
|
|
}); |
|
35
|
|
|
|
|
36
|
|
|
$this->assertSame('user2', $command->bindValue(':id', 2)->queryScalar()); |
|
37
|
|
|
}, 10); |
|
38
|
|
|
|
|
39
|
|
|
$db->queryCacheEnable(false); |
|
40
|
|
|
|
|
41
|
|
|
$db->cache(function () use ($command, $update) { |
|
42
|
|
|
$this->assertSame('user22', $command->bindValue(':id', 2)->queryScalar()); |
|
43
|
|
|
$update->bindValues([':id' => 2, ':name' => 'user2'])->execute(); |
|
44
|
|
|
$this->assertSame('user2', $command->bindValue(':id', 2)->queryScalar()); |
|
45
|
|
|
}, 10); |
|
46
|
|
|
|
|
47
|
|
|
$db->queryCacheEnable(true); |
|
48
|
|
|
$command = $db->createCommand('SELECT [[name]] FROM {{customer}} WHERE [[id]] = :id')->cache(); |
|
49
|
|
|
|
|
50
|
|
|
$this->assertSame('user11', $command->bindValue(':id', 1)->queryScalar()); |
|
51
|
|
|
|
|
52
|
|
|
$update->bindValues([':id' => 1, ':name' => 'user1'])->execute(); |
|
53
|
|
|
|
|
54
|
|
|
$this->assertSame('user11', $command->bindValue(':id', 1)->queryScalar()); |
|
55
|
|
|
$this->assertSame('user1', $command->noCache()->bindValue(':id', 1)->queryScalar()); |
|
56
|
|
|
|
|
57
|
|
|
$command = $db->createCommand('SELECT [[name]] FROM {{customer}} WHERE [[id]] = :id'); |
|
58
|
|
|
$db->cache(function () use ($command) { |
|
59
|
|
|
$this->assertSame('user11', $command->bindValue(':id', 1)->queryScalar()); |
|
60
|
|
|
$this->assertSame('user1', $command->noCache()->bindValue(':id', 1)->queryScalar()); |
|
61
|
|
|
}, 10); |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.