Skip to content

Commit 00a36a7

Browse files
committed
minor symfony#57665 [Config][Lock][SecurityBundle]  do not use uniqid() in tests (xabbuh)
This PR was merged into the 7.2 branch. Discussion ---------- [Config][Lock][SecurityBundle]  do not use uniqid() in tests | Q | A | ------------- | --- | Branch? | 7.2 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | part of symfony#57588 | License | MIT Commits ------- 1b3d6bf do not use uniqid() in tests
2 parents 0d77a05 + 1b3d6bf commit 00a36a7

18 files changed

+138
-152
lines changed

src/Symfony/Bundle/SecurityBundle/Tests/Functional/CsrfFormLoginTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ private function callInRequestContext(KernelBrowser $client, callable $callable)
142142

143143
$eventDispatcher->addListener(KernelEvents::REQUEST, $wrappedCallable);
144144
try {
145-
$client->request('GET', '/'.uniqid('', true));
145+
$client->request('GET', '/not-existent');
146146
} finally {
147147
$eventDispatcher->removeListener(KernelEvents::REQUEST, $wrappedCallable);
148148
}

src/Symfony/Bundle/SecurityBundle/Tests/Functional/LogoutTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ private function callInRequestContext(KernelBrowser $client, callable $callable)
9090

9191
$eventDispatcher->addListener(KernelEvents::REQUEST, $wrappedCallable);
9292
try {
93-
$client->request('GET', '/'.uniqid('', true));
93+
$client->request('GET', '/not-existent');
9494
} finally {
9595
$eventDispatcher->removeListener(KernelEvents::REQUEST, $wrappedCallable);
9696
}

src/Symfony/Bundle/SecurityBundle/Tests/Functional/SecurityTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public function testLogoutWithCsrf()
134134
};
135135
$eventDispatcher->addListener(KernelEvents::REQUEST, $setCsrfToken);
136136
try {
137-
$client->request('GET', '/'.uniqid('', true));
137+
$client->request('GET', '/not-existent');
138138
} finally {
139139
$eventDispatcher->removeListener(KernelEvents::REQUEST, $setCsrfToken);
140140
}

src/Symfony/Component/Config/Tests/Resource/ReflectionClassResourceTest.php

Lines changed: 44 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function testIsFreshForDeletedResources()
6363
/**
6464
* @dataProvider provideHashedSignature
6565
*/
66-
public function testHashedSignature(bool $changeExpected, int $changedLine, ?string $changedCode, ?\Closure $setContext = null)
66+
public function testHashedSignature(bool $changeExpected, int $changedLine, ?string $changedCode, int $resourceClassNameSuffix, ?\Closure $setContext = null)
6767
{
6868
if ($setContext) {
6969
$setContext();
@@ -94,7 +94,7 @@ public function testHashedSignature(bool $changeExpected, int $changedLine, ?str
9494
static $expectedSignature, $generateSignature;
9595

9696
if (null === $expectedSignature) {
97-
eval(\sprintf($code, $class = 'Foo'.str_replace('.', '_', uniqid('', true))));
97+
eval(\sprintf($code, $class = 'Foo'.(string) $resourceClassNameSuffix));
9898
$r = new \ReflectionClass(ReflectionClassResource::class);
9999
$generateSignature = $r->getMethod('generateSignature');
100100
$generateSignature = $generateSignature->getClosure($r->newInstanceWithoutConstructor());
@@ -105,7 +105,7 @@ public function testHashedSignature(bool $changeExpected, int $changedLine, ?str
105105
if (null !== $changedCode) {
106106
$code[$changedLine] = $changedCode;
107107
}
108-
eval(\sprintf(implode("\n", $code), $class = 'Foo'.str_replace('.', '_', uniqid('', true))));
108+
eval(\sprintf(implode("\n", $code), $class = 'Bar'.(string) $resourceClassNameSuffix));
109109
$signature = implode("\n", iterator_to_array($generateSignature(new \ReflectionClass($class))));
110110

111111
if ($changeExpected) {
@@ -117,49 +117,50 @@ public function testHashedSignature(bool $changeExpected, int $changedLine, ?str
117117

118118
public static function provideHashedSignature(): iterable
119119
{
120-
yield [false, 0, "// line change\n\n"];
121-
yield [true, 0, '/** class docblock */'];
122-
yield [true, 0, '#[Foo]'];
123-
yield [true, 0, '#[Foo(new MissingClass)]'];
124-
yield [true, 1, 'abstract class %s'];
125-
yield [true, 1, 'final class %s'];
126-
yield [true, 1, 'class %s extends Exception'];
127-
yield [true, 1, 'class %s implements '.DummyInterface::class];
128-
yield [true, 3, 'const FOO = 456;'];
129-
yield [true, 3, 'const BAR = 123;'];
130-
yield [true, 4, '/** pub docblock */'];
131-
yield [true, 5, 'protected $pub = [];'];
132-
yield [true, 5, 'public $pub = [123];'];
133-
yield [true, 5, '#[Foo(new MissingClass)] public $pub = [];'];
134-
yield [true, 6, '/** prot docblock */'];
135-
yield [true, 7, 'private $prot;'];
136-
yield [false, 8, '/** priv docblock */'];
137-
yield [false, 9, 'private $priv = 123;'];
138-
yield [true, 10, '/** pub docblock */'];
139-
yield [true, 11, 'public function pub(...$arg) {}'];
140-
yield [true, 11, 'public function pub($arg = null): Foo {}'];
141-
yield [false, 11, "public function pub(\$arg = null) {\nreturn 123;\n}"];
142-
yield [true, 12, '/** prot docblock */'];
143-
yield [true, 13, 'protected function prot($a = [123]) {}'];
144-
yield [true, 13, '#[Foo] protected function prot($a = []) {}'];
145-
yield [true, 13, 'protected function prot(#[Foo] $a = []) {}'];
146-
yield [true, 13, '#[Foo(new MissingClass)] protected function prot($a = []) {}'];
147-
yield [true, 13, 'protected function prot(#[Foo(new MissingClass)] $a = []) {}'];
148-
yield [false, 14, '/** priv docblock */'];
149-
yield [false, 15, ''];
120+
$i = 0;
121+
yield [false, 0, "// line change\n\n", ++$i];
122+
yield [true, 0, '/** class docblock */', ++$i];
123+
yield [true, 0, '#[Foo]', ++$i];
124+
yield [true, 0, '#[Foo(new MissingClass)]', ++$i];
125+
yield [true, 1, 'abstract class %s', ++$i];
126+
yield [true, 1, 'final class %s', ++$i];
127+
yield [true, 1, 'class %s extends Exception', ++$i];
128+
yield [true, 1, 'class %s implements '.DummyInterface::class, ++$i];
129+
yield [true, 3, 'const FOO = 456;', ++$i];
130+
yield [true, 3, 'const BAR = 123;', ++$i];
131+
yield [true, 4, '/** pub docblock */', ++$i];
132+
yield [true, 5, 'protected $pub = [];', ++$i];
133+
yield [true, 5, 'public $pub = [123];', ++$i];
134+
yield [true, 5, '#[Foo(new MissingClass)] public $pub = [];', ++$i];
135+
yield [true, 6, '/** prot docblock */', ++$i];
136+
yield [true, 7, 'private $prot;', ++$i];
137+
yield [false, 8, '/** priv docblock */', ++$i];
138+
yield [false, 9, 'private $priv = 123;', ++$i];
139+
yield [true, 10, '/** pub docblock */', ++$i];
140+
yield [true, 11, 'public function pub(...$arg) {}', ++$i];
141+
yield [true, 11, 'public function pub($arg = null): Foo {}', ++$i];
142+
yield [false, 11, "public function pub(\$arg = null) {\nreturn 123;\n}", ++$i];
143+
yield [true, 12, '/** prot docblock */', ++$i];
144+
yield [true, 13, 'protected function prot($a = [123]) {}', ++$i];
145+
yield [true, 13, '#[Foo] protected function prot($a = []) {}', ++$i];
146+
yield [true, 13, 'protected function prot(#[Foo] $a = []) {}', ++$i];
147+
yield [true, 13, '#[Foo(new MissingClass)] protected function prot($a = []) {}', ++$i];
148+
yield [true, 13, 'protected function prot(#[Foo(new MissingClass)] $a = []) {}', ++$i];
149+
yield [false, 14, '/** priv docblock */', ++$i];
150+
yield [false, 15, null, ++$i];
150151

151152
// PHP7.4 typed properties without default value are
152153
// undefined, make sure this doesn't throw an error
153-
yield [true, 5, 'public array $pub;'];
154-
yield [false, 7, 'protected int $prot;'];
155-
yield [false, 9, 'private string $priv;'];
156-
yield [true, 17, 'public function __construct(private $bar = new \stdClass()) {}'];
157-
yield [true, 17, 'public function ccc($bar = new \stdClass()) {}'];
158-
yield [true, 17, 'public function ccc($bar = new MissingClass()) {}'];
159-
yield [true, 17, 'public function ccc($bar = 187) {}'];
160-
yield [true, 17, 'public function ccc($bar = ANOTHER_ONE_THAT_WILL_NEVER_BE_DEFINED_CCCCCCCCC) {}'];
161-
yield [true, 17, 'public function ccc($bar = parent::BOOM) {}'];
162-
yield [false, 17, null, static function () { \define('A_CONSTANT_THAT_FOR_SURE_WILL_NEVER_BE_DEFINED_CCCCCC', 'foo'); }];
154+
yield [true, 5, 'public array $pub;', ++$i];
155+
yield [false, 7, 'protected int $prot;', ++$i];
156+
yield [false, 9, 'private string $priv;', ++$i];
157+
yield [true, 17, 'public function __construct(private $bar = new \stdClass()) {}', ++$i];
158+
yield [true, 17, 'public function ccc($bar = new \stdClass()) {}', ++$i];
159+
yield [true, 17, 'public function ccc($bar = new MissingClass()) {}', ++$i];
160+
yield [true, 17, 'public function ccc($bar = 187) {}', ++$i];
161+
yield [true, 17, 'public function ccc($bar = ANOTHER_ONE_THAT_WILL_NEVER_BE_DEFINED_CCCCCCCCC) {}', ++$i];
162+
yield [true, 17, 'public function ccc($bar = parent::BOOM) {}', ++$i];
163+
yield [false, 17, null, ++$i, static function () { \define('A_CONSTANT_THAT_FOR_SURE_WILL_NEVER_BE_DEFINED_CCCCCC', 'foo'); }];
163164
}
164165

165166
public function testEventSubscriber()

src/Symfony/Component/Lock/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

src/Symfony/Component/Lock/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();

0 commit comments

Comments
 (0)