|
12 | 12 | namespace Symfony\Component\Lock\Tests;
|
13 | 13 |
|
14 | 14 | use PHPUnit\Framework\TestCase;
|
| 15 | +use Psr\Log\AbstractLogger; |
15 | 16 | use Psr\Log\LoggerInterface;
|
16 | 17 | use Symfony\Component\Lock\BlockingSharedLockStoreInterface;
|
17 | 18 | use Symfony\Component\Lock\BlockingStoreInterface;
|
|
22 | 23 | use Symfony\Component\Lock\PersistingStoreInterface;
|
23 | 24 | use Symfony\Component\Lock\SharedLockStoreInterface;
|
24 | 25 | use Symfony\Component\Lock\Store\ExpiringStoreTrait;
|
| 26 | +use Symfony\Component\Lock\Store\InMemoryStore; |
25 | 27 |
|
26 | 28 | /**
|
27 | 29 | * @author Jérémy Derussé <jeremy@derusse.com>
|
@@ -366,6 +368,34 @@ public function testReleaseThrowsAndLog()
|
366 | 368 | $lock->release();
|
367 | 369 | }
|
368 | 370 |
|
| 371 | + public function testSuccessReleaseLog() |
| 372 | + { |
| 373 | + $key = new Key((string) random_int(100, 1000)); |
| 374 | + $store = new InMemoryStore(); |
| 375 | + $logger = new class() extends AbstractLogger { |
| 376 | + private array $logs = []; |
| 377 | + |
| 378 | + public function log($level, $message, array $context = []): void |
| 379 | + { |
| 380 | + $this->logs[] = [ |
| 381 | + $level, |
| 382 | + (string) $message, |
| 383 | + $context, |
| 384 | + ]; |
| 385 | + } |
| 386 | + |
| 387 | + public function logs(): array |
| 388 | + { |
| 389 | + return $this->logs; |
| 390 | + } |
| 391 | + }; |
| 392 | + $lock = new Lock($key, $store, 10, true); |
| 393 | + $lock->setLogger($logger); |
| 394 | + $lock->release(); |
| 395 | + |
| 396 | + $this->assertSame([['debug', 'Successfully released the "{resource}" lock.', ['resource' => $key]]], $logger->logs()); |
| 397 | + } |
| 398 | + |
369 | 399 | /**
|
370 | 400 | * @dataProvider provideExpiredDates
|
371 | 401 | */
|
|
0 commit comments