Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit abad7cf

Browse files
committed
[Cache] Make sure PdoAdapter::prune() always returns a bool
Signed-off-by: Alexander M. Turek <[email protected]>
1 parent dd45efc commit abad7cf

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/Symfony/Component/Cache/Tests/Adapter/AdapterTestCase.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ public function testPrune()
217217
$doSet('qux', 'qux-val', new \DateInterval('PT20S'));
218218

219219
sleep(30);
220-
$cache->prune();
220+
$this->assertTrue($cache->prune());
221221
$this->assertTrue($this->isPruned($cache, 'foo'));
222222
$this->assertTrue($this->isPruned($cache, 'bar'));
223223
$this->assertTrue($this->isPruned($cache, 'baz'));
@@ -228,27 +228,27 @@ public function testPrune()
228228
$doSet('baz', 'baz-val', new \DateInterval('PT40S'));
229229
$doSet('qux', 'qux-val', new \DateInterval('PT80S'));
230230

231-
$cache->prune();
231+
$this->assertTrue($cache->prune());
232232
$this->assertFalse($this->isPruned($cache, 'foo'));
233233
$this->assertFalse($this->isPruned($cache, 'bar'));
234234
$this->assertFalse($this->isPruned($cache, 'baz'));
235235
$this->assertFalse($this->isPruned($cache, 'qux'));
236236

237237
sleep(30);
238-
$cache->prune();
238+
$this->assertTrue($cache->prune());
239239
$this->assertFalse($this->isPruned($cache, 'foo'));
240240
$this->assertTrue($this->isPruned($cache, 'bar'));
241241
$this->assertFalse($this->isPruned($cache, 'baz'));
242242
$this->assertFalse($this->isPruned($cache, 'qux'));
243243

244244
sleep(30);
245-
$cache->prune();
245+
$this->assertTrue($cache->prune());
246246
$this->assertFalse($this->isPruned($cache, 'foo'));
247247
$this->assertTrue($this->isPruned($cache, 'baz'));
248248
$this->assertFalse($this->isPruned($cache, 'qux'));
249249

250250
sleep(30);
251-
$cache->prune();
251+
$this->assertTrue($cache->prune());
252252
$this->assertFalse($this->isPruned($cache, 'foo'));
253253
$this->assertTrue($this->isPruned($cache, 'qux'));
254254
}

src/Symfony/Component/Cache/Traits/PdoTrait.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Doctrine\DBAL\Exception\TableNotFoundException;
2020
use Doctrine\DBAL\ParameterType;
2121
use Doctrine\DBAL\Schema\Schema;
22+
use Doctrine\DBAL\Statement;
2223
use Symfony\Component\Cache\Exception\InvalidArgumentException;
2324
use Symfony\Component\Cache\Marshaller\DefaultMarshaller;
2425
use Symfony\Component\Cache\Marshaller\MarshallerInterface;
@@ -183,6 +184,13 @@ public function prune()
183184
$delete->bindValue(':namespace', sprintf('%s%%', $this->namespace), $useDbalConstants ? ParameterType::STRING : \PDO::PARAM_STR);
184185
}
185186
try {
187+
// Doctrine DBAL ^2.13 || >= 3.1
188+
if ($delete instanceof Statement && \method_exists($delete, 'executeStatement')) {
189+
$delete->executeStatement();
190+
191+
return true;
192+
}
193+
186194
return $delete->execute();
187195
} catch (TableNotFoundException $e) {
188196
return true;

0 commit comments

Comments
 (0)