@@ 78-111 (lines=34) @@ | ||
75 | self::assertNotEmpty($cacheKey, 'The generated cache key should not be empty'); |
|
76 | } |
|
77 | ||
78 | public function testShouldGenerateDifferentKeysForSameQueryAndParamsAndDifferentConnections() |
|
79 | { |
|
80 | $query = 'SELECT * FROM foo WHERE bar = ?'; |
|
81 | $params = [666]; |
|
82 | $types = [PDO::PARAM_INT]; |
|
83 | ||
84 | $connectionParams = array( |
|
85 | 'dbname' => 'database_name', |
|
86 | 'user' => 'database_user', |
|
87 | 'password' => 'database_password', |
|
88 | 'host' => 'database_host', |
|
89 | 'driver' => 'database_driver' |
|
90 | ); |
|
91 | ||
92 | $this->queryCacheProfile = $this->queryCacheProfile->setCacheKey(null); |
|
93 | ||
94 | list($firstCacheKey) = $this->queryCacheProfile->generateCacheKeys( |
|
95 | $query, |
|
96 | $params, |
|
97 | $types, |
|
98 | $connectionParams |
|
99 | ); |
|
100 | ||
101 | $connectionParams['host'] = 'a_different_host'; |
|
102 | ||
103 | list($secondCacheKey) = $this->queryCacheProfile->generateCacheKeys( |
|
104 | $query, |
|
105 | $params, |
|
106 | $types, |
|
107 | $connectionParams |
|
108 | ); |
|
109 | ||
110 | self::assertNotEquals($firstCacheKey, $secondCacheKey, 'Cache keys should be different'); |
|
111 | } |
|
112 | ||
113 | public function testShouldGenerateSameKeysIfNoneOfTheParamsChanges() |
|
114 | { |
|
@@ 113-144 (lines=32) @@ | ||
110 | self::assertNotEquals($firstCacheKey, $secondCacheKey, 'Cache keys should be different'); |
|
111 | } |
|
112 | ||
113 | public function testShouldGenerateSameKeysIfNoneOfTheParamsChanges() |
|
114 | { |
|
115 | $query = 'SELECT * FROM foo WHERE bar = ?'; |
|
116 | $params = [666]; |
|
117 | $types = [PDO::PARAM_INT]; |
|
118 | ||
119 | $connectionParams = array( |
|
120 | 'dbname' => 'database_name', |
|
121 | 'user' => 'database_user', |
|
122 | 'password' => 'database_password', |
|
123 | 'host' => 'database_host', |
|
124 | 'driver' => 'database_driver' |
|
125 | ); |
|
126 | ||
127 | $this->queryCacheProfile = $this->queryCacheProfile->setCacheKey(null); |
|
128 | ||
129 | list($firstCacheKey) = $this->queryCacheProfile->generateCacheKeys( |
|
130 | $query, |
|
131 | $params, |
|
132 | $types, |
|
133 | $connectionParams |
|
134 | ); |
|
135 | ||
136 | list($secondCacheKey) = $this->queryCacheProfile->generateCacheKeys( |
|
137 | $query, |
|
138 | $params, |
|
139 | $types, |
|
140 | $connectionParams |
|
141 | ); |
|
142 | ||
143 | self::assertEquals($firstCacheKey, $secondCacheKey, 'Cache keys should be the same'); |
|
144 | } |
|
145 | } |
|
146 |