Skip to content

Commit 80b0a55

Browse files
xabbuhfabpot
authored andcommitted
do not use uniqid() in tests
1 parent 623291c commit 80b0a55

14 files changed

+91
-106
lines changed

Tests/LockTest.php

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class LockTest extends TestCase
3232
{
3333
public function testAcquireNoBlocking()
3434
{
35-
$key = new Key(uniqid(__METHOD__, true));
35+
$key = new Key(__METHOD__);
3636
$store = $this->createMock(PersistingStoreInterface::class);
3737
$lock = new Lock($key, $store);
3838

@@ -48,7 +48,7 @@ public function testAcquireNoBlocking()
4848

4949
public function testAcquireNoBlockingWithPersistingStoreInterface()
5050
{
51-
$key = new Key(uniqid(__METHOD__, true));
51+
$key = new Key(__METHOD__);
5252
$store = $this->createMock(PersistingStoreInterface::class);
5353
$lock = new Lock($key, $store);
5454

@@ -64,7 +64,7 @@ public function testAcquireNoBlockingWithPersistingStoreInterface()
6464

6565
public function testAcquireBlockingWithPersistingStoreInterface()
6666
{
67-
$key = new Key(uniqid(__METHOD__, true));
67+
$key = new Key(__METHOD__);
6868
$store = $this->createMock(PersistingStoreInterface::class);
6969
$lock = new Lock($key, $store);
7070

@@ -80,7 +80,7 @@ public function testAcquireBlockingWithPersistingStoreInterface()
8080

8181
public function testAcquireBlockingRetryWithPersistingStoreInterface()
8282
{
83-
$key = new Key(uniqid(__METHOD__, true));
83+
$key = new Key(__METHOD__);
8484
$store = $this->createMock(PersistingStoreInterface::class);
8585
$lock = new Lock($key, $store);
8686

@@ -102,7 +102,7 @@ public function testAcquireBlockingRetryWithPersistingStoreInterface()
102102

103103
public function testAcquireReturnsFalse()
104104
{
105-
$key = new Key(uniqid(__METHOD__, true));
105+
$key = new Key(__METHOD__);
106106
$store = $this->createMock(PersistingStoreInterface::class);
107107
$lock = new Lock($key, $store);
108108

@@ -119,7 +119,7 @@ public function testAcquireReturnsFalse()
119119

120120
public function testAcquireReturnsFalseStoreInterface()
121121
{
122-
$key = new Key(uniqid(__METHOD__, true));
122+
$key = new Key(__METHOD__);
123123
$store = $this->createMock(PersistingStoreInterface::class);
124124
$lock = new Lock($key, $store);
125125

@@ -136,7 +136,7 @@ public function testAcquireReturnsFalseStoreInterface()
136136

137137
public function testAcquireBlockingWithBlockingStoreInterface()
138138
{
139-
$key = new Key(uniqid(__METHOD__, true));
139+
$key = new Key(__METHOD__);
140140
$store = $this->createMock(BlockingStoreInterface::class);
141141
$lock = new Lock($key, $store);
142142

@@ -155,7 +155,7 @@ public function testAcquireBlockingWithBlockingStoreInterface()
155155

156156
public function testAcquireSetsTtl()
157157
{
158-
$key = new Key(uniqid(__METHOD__, true));
158+
$key = new Key(__METHOD__);
159159
$store = $this->createMock(PersistingStoreInterface::class);
160160
$lock = new Lock($key, $store, 10);
161161

@@ -175,7 +175,7 @@ public function testAcquireSetsTtl()
175175

176176
public function testRefresh()
177177
{
178-
$key = new Key(uniqid(__METHOD__, true));
178+
$key = new Key(__METHOD__);
179179
$store = $this->createMock(PersistingStoreInterface::class);
180180
$lock = new Lock($key, $store, 10);
181181

@@ -192,7 +192,7 @@ public function testRefresh()
192192

193193
public function testRefreshCustom()
194194
{
195-
$key = new Key(uniqid(__METHOD__, true));
195+
$key = new Key(__METHOD__);
196196
$store = $this->createMock(PersistingStoreInterface::class);
197197
$lock = new Lock($key, $store, 10);
198198

@@ -209,7 +209,7 @@ public function testRefreshCustom()
209209

210210
public function testIsAquired()
211211
{
212-
$key = new Key(uniqid(__METHOD__, true));
212+
$key = new Key(__METHOD__);
213213
$store = $this->createMock(PersistingStoreInterface::class);
214214
$lock = new Lock($key, $store, 10);
215215

@@ -223,7 +223,7 @@ public function testIsAquired()
223223

224224
public function testRelease()
225225
{
226-
$key = new Key(uniqid(__METHOD__, true));
226+
$key = new Key(__METHOD__);
227227
$store = $this->createMock(PersistingStoreInterface::class);
228228
$lock = new Lock($key, $store, 10);
229229

@@ -243,7 +243,7 @@ public function testRelease()
243243

244244
public function testReleaseStoreInterface()
245245
{
246-
$key = new Key(uniqid(__METHOD__, true));
246+
$key = new Key(__METHOD__);
247247
$store = $this->createMock(PersistingStoreInterface::class);
248248
$lock = new Lock($key, $store, 10);
249249

@@ -263,7 +263,7 @@ public function testReleaseStoreInterface()
263263

264264
public function testReleaseOnDestruction()
265265
{
266-
$key = new Key(uniqid(__METHOD__, true));
266+
$key = new Key(__METHOD__);
267267
$store = $this->createMock(BlockingStoreInterface::class);
268268
$lock = new Lock($key, $store, 10);
269269

@@ -282,7 +282,7 @@ public function testReleaseOnDestruction()
282282

283283
public function testNoAutoReleaseWhenNotConfigured()
284284
{
285-
$key = new Key(uniqid(__METHOD__, true));
285+
$key = new Key(__METHOD__);
286286
$store = $this->createMock(BlockingStoreInterface::class);
287287
$lock = new Lock($key, $store, 10, false);
288288

@@ -302,7 +302,7 @@ public function testNoAutoReleaseWhenNotConfigured()
302302
public function testReleaseThrowsExceptionWhenDeletionFail()
303303
{
304304
$this->expectException(LockReleasingException::class);
305-
$key = new Key(uniqid(__METHOD__, true));
305+
$key = new Key(__METHOD__);
306306
$store = $this->createMock(PersistingStoreInterface::class);
307307
$lock = new Lock($key, $store, 10);
308308

@@ -324,7 +324,7 @@ public function testReleaseThrowsExceptionWhenDeletionFail()
324324
public function testReleaseThrowsExceptionIfNotWellDeleted()
325325
{
326326
$this->expectException(LockReleasingException::class);
327-
$key = new Key(uniqid(__METHOD__, true));
327+
$key = new Key(__METHOD__);
328328
$store = $this->createMock(PersistingStoreInterface::class);
329329
$lock = new Lock($key, $store, 10);
330330

@@ -345,7 +345,7 @@ public function testReleaseThrowsExceptionIfNotWellDeleted()
345345
public function testReleaseThrowsAndLog()
346346
{
347347
$this->expectException(LockReleasingException::class);
348-
$key = new Key(uniqid(__METHOD__, true));
348+
$key = new Key(__METHOD__);
349349
$store = $this->createMock(PersistingStoreInterface::class);
350350
$logger = $this->createMock(LoggerInterface::class);
351351
$lock = new Lock($key, $store, 10, true);
@@ -402,7 +402,7 @@ public function logs(): array
402402
*/
403403
public function testExpiration($ttls, $expected)
404404
{
405-
$key = new Key(uniqid(__METHOD__, true));
405+
$key = new Key(__METHOD__);
406406
$store = $this->createMock(PersistingStoreInterface::class);
407407
$lock = new Lock($key, $store, 10);
408408

@@ -421,7 +421,7 @@ public function testExpiration($ttls, $expected)
421421
*/
422422
public function testExpirationStoreInterface($ttls, $expected)
423423
{
424-
$key = new Key(uniqid(__METHOD__, true));
424+
$key = new Key(__METHOD__);
425425
$store = $this->createMock(PersistingStoreInterface::class);
426426
$lock = new Lock($key, $store, 10);
427427

@@ -448,7 +448,7 @@ public static function provideExpiredDates()
448448

449449
public function testAcquireReadNoBlockingWithSharedLockStoreInterface()
450450
{
451-
$key = new Key(uniqid(__METHOD__, true));
451+
$key = new Key(__METHOD__);
452452
$store = $this->createMock(SharedLockStoreInterface::class);
453453
$lock = new Lock($key, $store);
454454

@@ -467,7 +467,7 @@ public function testAcquireReadNoBlockingWithSharedLockStoreInterface()
467467
*/
468468
public function testAcquireReadTwiceWithExpiration()
469469
{
470-
$key = new Key(uniqid(__METHOD__, true));
470+
$key = new Key(__METHOD__);
471471
$store = new class() implements PersistingStoreInterface {
472472
use ExpiringStoreTrait;
473473
private array $keys = [];
@@ -511,7 +511,7 @@ public function putOffExpiration(Key $key, $ttl): void
511511
*/
512512
public function testAcquireTwiceWithExpiration()
513513
{
514-
$key = new Key(uniqid(__METHOD__, true));
514+
$key = new Key(__METHOD__);
515515
$store = new class() implements PersistingStoreInterface {
516516
use ExpiringStoreTrait;
517517
private array $keys = [];
@@ -552,7 +552,7 @@ public function putOffExpiration(Key $key, $ttl): void
552552

553553
public function testAcquireReadBlockingWithBlockingSharedLockStoreInterface()
554554
{
555-
$key = new Key(uniqid(__METHOD__, true));
555+
$key = new Key(__METHOD__);
556556
$store = $this->createMock(BlockingSharedLockStoreInterface::class);
557557
$lock = new Lock($key, $store);
558558

@@ -568,7 +568,7 @@ public function testAcquireReadBlockingWithBlockingSharedLockStoreInterface()
568568

569569
public function testAcquireReadBlockingWithSharedLockStoreInterface()
570570
{
571-
$key = new Key(uniqid(__METHOD__, true));
571+
$key = new Key(__METHOD__);
572572
$store = $this->createMock(SharedLockStoreInterface::class);
573573
$lock = new Lock($key, $store);
574574

@@ -590,7 +590,7 @@ public function testAcquireReadBlockingWithSharedLockStoreInterface()
590590

591591
public function testAcquireReadBlockingWithBlockingLockStoreInterface()
592592
{
593-
$key = new Key(uniqid(__METHOD__, true));
593+
$key = new Key(__METHOD__);
594594
$store = $this->createMock(BlockingStoreInterface::class);
595595
$lock = new Lock($key, $store);
596596

@@ -606,7 +606,7 @@ public function testAcquireReadBlockingWithBlockingLockStoreInterface()
606606

607607
public function testAcquireReadBlockingWithPersistingStoreInterface()
608608
{
609-
$key = new Key(uniqid(__METHOD__, true));
609+
$key = new Key(__METHOD__);
610610
$store = $this->createMock(PersistingStoreInterface::class);
611611
$lock = new Lock($key, $store);
612612

Tests/Store/AbstractRedisStoreTestCase.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,8 @@ public function getStore(): PersistingStoreInterface
3939

4040
public function testBackwardCompatibility()
4141
{
42-
$resource = uniqid(__METHOD__, true);
43-
$key1 = new Key($resource);
44-
$key2 = new Key($resource);
42+
$key1 = new Key(__METHOD__);
43+
$key2 = new Key(__METHOD__);
4544

4645
$oldStore = new Symfony51Store($this->getRedisConnection());
4746
$newStore = $this->getStore();

Tests/Store/AbstractStoreTestCase.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function testSave()
2727
{
2828
$store = $this->getStore();
2929

30-
$key = new Key(uniqid(__METHOD__, true));
30+
$key = new Key(__METHOD__);
3131

3232
$this->assertFalse($store->exists($key));
3333
$store->save($key);
@@ -40,8 +40,8 @@ public function testSaveWithDifferentResources()
4040
{
4141
$store = $this->getStore();
4242

43-
$key1 = new Key(uniqid(__METHOD__, true));
44-
$key2 = new Key(uniqid(__METHOD__, true));
43+
$key1 = new Key(__METHOD__.'1');
44+
$key2 = new Key(__METHOD__.'2');
4545

4646
$store->save($key1);
4747
$this->assertTrue($store->exists($key1));
@@ -64,9 +64,8 @@ public function testSaveWithDifferentKeysOnSameResources()
6464
{
6565
$store = $this->getStore();
6666

67-
$resource = uniqid(__METHOD__, true);
68-
$key1 = new Key($resource);
69-
$key2 = new Key($resource);
67+
$key1 = new Key(__METHOD__);
68+
$key2 = new Key(__METHOD__);
7069

7170
$store->save($key1);
7271
$this->assertTrue($store->exists($key1));
@@ -99,8 +98,7 @@ public function testSaveTwice()
9998
{
10099
$store = $this->getStore();
101100

102-
$resource = uniqid(__METHOD__, true);
103-
$key = new Key($resource);
101+
$key = new Key(__METHOD__);
104102

105103
$store->save($key);
106104
$store->save($key);
@@ -114,8 +112,8 @@ public function testDeleteIsolated()
114112
{
115113
$store = $this->getStore();
116114

117-
$key1 = new Key(uniqid(__METHOD__, true));
118-
$key2 = new Key(uniqid(__METHOD__, true));
115+
$key1 = new Key(__METHOD__.'1');
116+
$key2 = new Key(__METHOD__.'2');
119117

120118
$store->save($key1);
121119
$this->assertTrue($store->exists($key1));

Tests/Store/BlockingStoreTestTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function testBlockingLocks()
4343
// Amount of microseconds we should wait without slowing things down too much
4444
$clockDelay = 50000;
4545

46-
$key = new Key(uniqid(__METHOD__, true));
46+
$key = new Key(__METHOD__);
4747
$parentPID = posix_getpid();
4848

4949
// Block SIGHUP signal

0 commit comments

Comments
 (0)