Skip to content

Commit 397a1df

Browse files
Merge branch '4.4' into 5.1
* 4.4: Use createMock() and use import instead of FQCN
2 parents cfbaafd + efcf444 commit 397a1df

File tree

7 files changed

+35
-30
lines changed

7 files changed

+35
-30
lines changed

Tests/LockFactoryTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ class LockFactoryTest extends TestCase
2424
{
2525
public function testCreateLock()
2626
{
27-
$store = $this->getMockBuilder(PersistingStoreInterface::class)->getMock();
28-
$logger = $this->getMockBuilder(LoggerInterface::class)->getMock();
27+
$store = $this->createMock(PersistingStoreInterface::class);
28+
$logger = $this->createMock(LoggerInterface::class);
2929
$factory = new LockFactory($store);
3030
$factory->setLogger($logger);
3131

Tests/LockTest.php

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Psr\Log\LoggerInterface;
1616
use Symfony\Component\Lock\BlockingStoreInterface;
1717
use Symfony\Component\Lock\Exception\LockConflictedException;
18+
use Symfony\Component\Lock\Exception\LockReleasingException;
1819
use Symfony\Component\Lock\Key;
1920
use Symfony\Component\Lock\Lock;
2021
use Symfony\Component\Lock\PersistingStoreInterface;
@@ -28,7 +29,7 @@ class LockTest extends TestCase
2829
public function testAcquireNoBlocking()
2930
{
3031
$key = new Key(uniqid(__METHOD__, true));
31-
$store = $this->getMockBuilder(PersistingStoreInterface::class)->getMock();
32+
$store = $this->createMock(PersistingStoreInterface::class);
3233
$lock = new Lock($key, $store);
3334

3435
$store
@@ -44,7 +45,7 @@ public function testAcquireNoBlocking()
4445
public function testAcquireNoBlockingStoreInterface()
4546
{
4647
$key = new Key(uniqid(__METHOD__, true));
47-
$store = $this->getMockBuilder(PersistingStoreInterface::class)->getMock();
48+
$store = $this->createMock(PersistingStoreInterface::class);
4849
$lock = new Lock($key, $store);
4950

5051
$store
@@ -60,7 +61,7 @@ public function testAcquireNoBlockingStoreInterface()
6061
public function testAcquireReturnsFalse()
6162
{
6263
$key = new Key(uniqid(__METHOD__, true));
63-
$store = $this->getMockBuilder(PersistingStoreInterface::class)->getMock();
64+
$store = $this->createMock(PersistingStoreInterface::class);
6465
$lock = new Lock($key, $store);
6566

6667
$store
@@ -77,7 +78,7 @@ public function testAcquireReturnsFalse()
7778
public function testAcquireReturnsFalseStoreInterface()
7879
{
7980
$key = new Key(uniqid(__METHOD__, true));
80-
$store = $this->getMockBuilder(PersistingStoreInterface::class)->getMock();
81+
$store = $this->createMock(PersistingStoreInterface::class);
8182
$lock = new Lock($key, $store);
8283

8384
$store
@@ -113,7 +114,7 @@ public function testAcquireBlocking()
113114
public function testAcquireSetsTtl()
114115
{
115116
$key = new Key(uniqid(__METHOD__, true));
116-
$store = $this->getMockBuilder(PersistingStoreInterface::class)->getMock();
117+
$store = $this->createMock(PersistingStoreInterface::class);
117118
$lock = new Lock($key, $store, 10);
118119

119120
$store
@@ -133,7 +134,7 @@ public function testAcquireSetsTtl()
133134
public function testRefresh()
134135
{
135136
$key = new Key(uniqid(__METHOD__, true));
136-
$store = $this->getMockBuilder(PersistingStoreInterface::class)->getMock();
137+
$store = $this->createMock(PersistingStoreInterface::class);
137138
$lock = new Lock($key, $store, 10);
138139

139140
$store
@@ -150,7 +151,7 @@ public function testRefresh()
150151
public function testRefreshCustom()
151152
{
152153
$key = new Key(uniqid(__METHOD__, true));
153-
$store = $this->getMockBuilder(PersistingStoreInterface::class)->getMock();
154+
$store = $this->createMock(PersistingStoreInterface::class);
154155
$lock = new Lock($key, $store, 10);
155156

156157
$store
@@ -167,7 +168,7 @@ public function testRefreshCustom()
167168
public function testIsAquired()
168169
{
169170
$key = new Key(uniqid(__METHOD__, true));
170-
$store = $this->getMockBuilder(PersistingStoreInterface::class)->getMock();
171+
$store = $this->createMock(PersistingStoreInterface::class);
171172
$lock = new Lock($key, $store, 10);
172173

173174
$store
@@ -181,7 +182,7 @@ public function testIsAquired()
181182
public function testRelease()
182183
{
183184
$key = new Key(uniqid(__METHOD__, true));
184-
$store = $this->getMockBuilder(PersistingStoreInterface::class)->getMock();
185+
$store = $this->createMock(PersistingStoreInterface::class);
185186
$lock = new Lock($key, $store, 10);
186187

187188
$store
@@ -201,7 +202,7 @@ public function testRelease()
201202
public function testReleaseStoreInterface()
202203
{
203204
$key = new Key(uniqid(__METHOD__, true));
204-
$store = $this->getMockBuilder(PersistingStoreInterface::class)->getMock();
205+
$store = $this->createMock(PersistingStoreInterface::class);
205206
$lock = new Lock($key, $store, 10);
206207

207208
$store
@@ -258,9 +259,9 @@ public function testNoAutoReleaseWhenNotConfigured()
258259

259260
public function testReleaseThrowsExceptionWhenDeletionFail()
260261
{
261-
$this->expectException(\Symfony\Component\Lock\Exception\LockReleasingException::class);
262+
$this->expectException(LockReleasingException::class);
262263
$key = new Key(uniqid(__METHOD__, true));
263-
$store = $this->getMockBuilder(PersistingStoreInterface::class)->getMock();
264+
$store = $this->createMock(PersistingStoreInterface::class);
264265
$lock = new Lock($key, $store, 10);
265266

266267
$store
@@ -279,9 +280,9 @@ public function testReleaseThrowsExceptionWhenDeletionFail()
279280

280281
public function testReleaseThrowsExceptionIfNotWellDeleted()
281282
{
282-
$this->expectException(\Symfony\Component\Lock\Exception\LockReleasingException::class);
283+
$this->expectException(LockReleasingException::class);
283284
$key = new Key(uniqid(__METHOD__, true));
284-
$store = $this->getMockBuilder(PersistingStoreInterface::class)->getMock();
285+
$store = $this->createMock(PersistingStoreInterface::class);
285286
$lock = new Lock($key, $store, 10);
286287

287288
$store
@@ -300,10 +301,10 @@ public function testReleaseThrowsExceptionIfNotWellDeleted()
300301

301302
public function testReleaseThrowsAndLog()
302303
{
303-
$this->expectException(\Symfony\Component\Lock\Exception\LockReleasingException::class);
304+
$this->expectException(LockReleasingException::class);
304305
$key = new Key(uniqid(__METHOD__, true));
305-
$store = $this->getMockBuilder(PersistingStoreInterface::class)->getMock();
306-
$logger = $this->getMockBuilder(LoggerInterface::class)->getMock();
306+
$store = $this->createMock(PersistingStoreInterface::class);
307+
$logger = $this->createMock(LoggerInterface::class);
307308
$lock = new Lock($key, $store, 10, true);
308309
$lock->setLogger($logger);
309310

@@ -331,7 +332,7 @@ public function testReleaseThrowsAndLog()
331332
public function testExpiration($ttls, $expected)
332333
{
333334
$key = new Key(uniqid(__METHOD__, true));
334-
$store = $this->getMockBuilder(PersistingStoreInterface::class)->getMock();
335+
$store = $this->createMock(PersistingStoreInterface::class);
335336
$lock = new Lock($key, $store, 10);
336337

337338
foreach ($ttls as $ttl) {
@@ -350,7 +351,7 @@ public function testExpiration($ttls, $expected)
350351
public function testExpirationStoreInterface($ttls, $expected)
351352
{
352353
$key = new Key(uniqid(__METHOD__, true));
353-
$store = $this->getMockBuilder(PersistingStoreInterface::class)->getMock();
354+
$store = $this->createMock(PersistingStoreInterface::class);
354355
$lock = new Lock($key, $store, 10);
355356

356357
foreach ($ttls as $ttl) {

Tests/Store/CombinedStoreTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function getStore(): PersistingStoreInterface
6262

6363
protected function setUp(): void
6464
{
65-
$this->strategy = $this->getMockBuilder(StrategyInterface::class)->getMock();
65+
$this->strategy = $this->createMock(StrategyInterface::class);
6666
$this->store1 = $this->createMock(BlockingStoreInterface::class);
6767
$this->store2 = $this->createMock(BlockingStoreInterface::class);
6868

@@ -264,8 +264,8 @@ public function testputOffExpirationAbortWhenStrategyCantBeMet()
264264

265265
public function testPutOffExpirationIgnoreNonExpiringStorage()
266266
{
267-
$store1 = $this->getMockBuilder(PersistingStoreInterface::class)->getMock();
268-
$store2 = $this->getMockBuilder(PersistingStoreInterface::class)->getMock();
267+
$store1 = $this->createMock(PersistingStoreInterface::class);
268+
$store2 = $this->createMock(PersistingStoreInterface::class);
269269

270270
$store = new CombinedStore([$store1, $store2], $this->strategy);
271271

Tests/Store/FlockStoreTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Lock\Tests\Store;
1313

14+
use Symfony\Component\Lock\Exception\InvalidArgumentException;
1415
use Symfony\Component\Lock\Key;
1516
use Symfony\Component\Lock\PersistingStoreInterface;
1617
use Symfony\Component\Lock\Store\FlockStore;
@@ -32,7 +33,7 @@ protected function getStore(): PersistingStoreInterface
3233

3334
public function testConstructWhenRepositoryDoesNotExist()
3435
{
35-
$this->expectException(\Symfony\Component\Lock\Exception\InvalidArgumentException::class);
36+
$this->expectException(InvalidArgumentException::class);
3637
$this->expectExceptionMessage('The directory "/a/b/c/d/e" is not writable.');
3738
if (!getenv('USER') || 'root' === getenv('USER')) {
3839
$this->markTestSkipped('This test will fail if run under superuser');
@@ -43,7 +44,7 @@ public function testConstructWhenRepositoryDoesNotExist()
4344

4445
public function testConstructWhenRepositoryIsNotWriteable()
4546
{
46-
$this->expectException(\Symfony\Component\Lock\Exception\InvalidArgumentException::class);
47+
$this->expectException(InvalidArgumentException::class);
4748
$this->expectExceptionMessage('The directory "/" is not writable.');
4849
if (!getenv('USER') || 'root' === getenv('USER')) {
4950
$this->markTestSkipped('This test will fail if run under superuser');

Tests/Store/MemcachedStoreTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Lock\Tests\Store;
1313

14+
use Symfony\Component\Lock\Exception\InvalidTtlException;
1415
use Symfony\Component\Lock\Key;
1516
use Symfony\Component\Lock\PersistingStoreInterface;
1617
use Symfony\Component\Lock\Store\MemcachedStore;
@@ -63,7 +64,7 @@ public function testAbortAfterExpiration()
6364

6465
public function testInvalidTtl()
6566
{
66-
$this->expectException(\Symfony\Component\Lock\Exception\InvalidTtlException::class);
67+
$this->expectException(InvalidTtlException::class);
6768
$store = $this->getStore();
6869
$store->putOffExpiration(new Key('toto'), 0.1);
6970
}

Tests/Store/PdoStoreTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Lock\Tests\Store;
1313

14+
use Symfony\Component\Lock\Exception\InvalidTtlException;
1415
use Symfony\Component\Lock\Key;
1516
use Symfony\Component\Lock\PersistingStoreInterface;
1617
use Symfony\Component\Lock\Store\PdoStore;
@@ -62,14 +63,14 @@ public function testAbortAfterExpiration()
6263

6364
public function testInvalidTtl()
6465
{
65-
$this->expectException(\Symfony\Component\Lock\Exception\InvalidTtlException::class);
66+
$this->expectException(InvalidTtlException::class);
6667
$store = $this->getStore();
6768
$store->putOffExpiration(new Key('toto'), 0.1);
6869
}
6970

7071
public function testInvalidTtlConstruct()
7172
{
72-
$this->expectException(\Symfony\Component\Lock\Exception\InvalidTtlException::class);
73+
$this->expectException(InvalidTtlException::class);
7374

7475
return new PdoStore('sqlite:'.self::$dbFile, [], 0.1, 0.1);
7576
}

Tests/Store/RedisStoreTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Lock\Tests\Store;
1313

14+
use Symfony\Component\Lock\Exception\InvalidTtlException;
1415
use Symfony\Component\Lock\Store\RedisStore;
1516

1617
/**
@@ -43,7 +44,7 @@ protected function getRedisConnection(): object
4344

4445
public function testInvalidTtl()
4546
{
46-
$this->expectException(\Symfony\Component\Lock\Exception\InvalidTtlException::class);
47+
$this->expectException(InvalidTtlException::class);
4748
new RedisStore($this->getRedisConnection(), -1);
4849
}
4950
}

0 commit comments

Comments
 (0)