|
6 | 6 |
|
7 | 7 | use Cycle\Database\Exception\BuilderException; |
8 | 8 | use Cycle\Database\Injection\Expression; |
| 9 | +use Cycle\Database\Injection\Parameter; |
9 | 10 | use Cycle\Database\Query\ConflictAction; |
10 | 11 | use Cycle\Database\Query\OnConflict; |
11 | 12 | use Cycle\Database\Query\QueryParameters; |
@@ -170,4 +171,51 @@ public function testCacheKeyDiffersForDifferentUpdateColumns(): void |
170 | 171 | $b->getCacheKey(new QueryParameters()), |
171 | 172 | ); |
172 | 173 | } |
| 174 | + |
| 175 | + public function testCacheKeyPushesFragmentParametersFromUpdateMap(): void |
| 176 | + { |
| 177 | + $expr = new Expression('counters.n + ?', 5); |
| 178 | + $c = OnConflict::target('key')->doUpdate(['n' => $expr]); |
| 179 | + |
| 180 | + $params = new QueryParameters(); |
| 181 | + $key = $c->getCacheKey($params); |
| 182 | + |
| 183 | + $this->assertCount(1, $params->getParameters()); |
| 184 | + $this->assertStringContainsString((string) $expr, $key); |
| 185 | + } |
| 186 | + |
| 187 | + public function testCacheKeyWrapsScalarUpdateValueAsParameter(): void |
| 188 | + { |
| 189 | + $c = OnConflict::target('key')->doUpdate(['n' => 42]); |
| 190 | + |
| 191 | + $params = new QueryParameters(); |
| 192 | + $key = $c->getCacheKey($params); |
| 193 | + |
| 194 | + $pushed = $params->getParameters(); |
| 195 | + $this->assertCount(1, $pushed); |
| 196 | + $this->assertInstanceOf(Parameter::class, $pushed[0]); |
| 197 | + $this->assertSame(42, $pushed[0]->getValue()); |
| 198 | + $this->assertStringContainsString('P?', $key); |
| 199 | + } |
| 200 | + |
| 201 | + public function testCacheKeyAcceptsExistingParameterInterfaceWithoutRewrapping(): void |
| 202 | + { |
| 203 | + $param = new Parameter(7); |
| 204 | + $c = OnConflict::target('key')->doUpdate(['n' => $param]); |
| 205 | + |
| 206 | + $params = new QueryParameters(); |
| 207 | + $key = $c->getCacheKey($params); |
| 208 | + |
| 209 | + $pushed = $params->getParameters(); |
| 210 | + $this->assertCount(1, $pushed); |
| 211 | + $this->assertSame($param, $pushed[0]); |
| 212 | + $this->assertStringContainsString('P?', $key); |
| 213 | + } |
| 214 | + |
| 215 | + public function testFromReturnsSameInstance(): void |
| 216 | + { |
| 217 | + $c = OnConflict::target('email')->doUpdate(['name']); |
| 218 | + |
| 219 | + $this->assertSame($c, OnConflict::from($c)); |
| 220 | + } |
173 | 221 | } |
0 commit comments