Skip to content

Commit efcf444

Browse files
OskarStarknicolas-grekas
authored andcommitted
Use createMock() and use import instead of FQCN
1 parent 5fa20ca commit efcf444

File tree

8 files changed

+40
-35
lines changed

8 files changed

+40
-35
lines changed

Tests/FactoryTest.php

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

Tests/LockFactoryTest.php

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

@@ -40,8 +40,8 @@ public function testCreateLock()
4040
*/
4141
public function testCreateLockWithLegacyStoreImplementation()
4242
{
43-
$store = $this->getMockBuilder(StoreInterface::class)->getMock();
44-
$logger = $this->getMockBuilder(LoggerInterface::class)->getMock();
43+
$store = $this->createMock(StoreInterface::class);
44+
$logger = $this->createMock(LoggerInterface::class);
4545
$factory = new LockFactory($store);
4646
$factory->setLogger($logger);
4747

Tests/LockTest.php

Lines changed: 21 additions & 20 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;
@@ -29,7 +30,7 @@ class LockTest extends TestCase
2930
public function testAcquireNoBlocking()
3031
{
3132
$key = new Key(uniqid(__METHOD__, true));
32-
$store = $this->getMockBuilder(PersistingStoreInterface::class)->getMock();
33+
$store = $this->createMock(PersistingStoreInterface::class);
3334
$lock = new Lock($key, $store);
3435

3536
$store
@@ -45,7 +46,7 @@ public function testAcquireNoBlocking()
4546
public function testAcquireNoBlockingStoreInterface()
4647
{
4748
$key = new Key(uniqid(__METHOD__, true));
48-
$store = $this->getMockBuilder(PersistingStoreInterface::class)->getMock();
49+
$store = $this->createMock(PersistingStoreInterface::class);
4950
$lock = new Lock($key, $store);
5051

5152
$store
@@ -64,7 +65,7 @@ public function testAcquireNoBlockingStoreInterface()
6465
public function testPassingOldStoreInterface()
6566
{
6667
$key = new Key(uniqid(__METHOD__, true));
67-
$store = $this->getMockBuilder(StoreInterface::class)->getMock();
68+
$store = $this->createMock(StoreInterface::class);
6869
$lock = new Lock($key, $store);
6970

7071
$store
@@ -80,7 +81,7 @@ public function testPassingOldStoreInterface()
8081
public function testAcquireReturnsFalse()
8182
{
8283
$key = new Key(uniqid(__METHOD__, true));
83-
$store = $this->getMockBuilder(PersistingStoreInterface::class)->getMock();
84+
$store = $this->createMock(PersistingStoreInterface::class);
8485
$lock = new Lock($key, $store);
8586

8687
$store
@@ -97,7 +98,7 @@ public function testAcquireReturnsFalse()
9798
public function testAcquireReturnsFalseStoreInterface()
9899
{
99100
$key = new Key(uniqid(__METHOD__, true));
100-
$store = $this->getMockBuilder(PersistingStoreInterface::class)->getMock();
101+
$store = $this->createMock(PersistingStoreInterface::class);
101102
$lock = new Lock($key, $store);
102103

103104
$store
@@ -133,7 +134,7 @@ public function testAcquireBlocking()
133134
public function testAcquireSetsTtl()
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
@@ -153,7 +154,7 @@ public function testAcquireSetsTtl()
153154
public function testRefresh()
154155
{
155156
$key = new Key(uniqid(__METHOD__, true));
156-
$store = $this->getMockBuilder(PersistingStoreInterface::class)->getMock();
157+
$store = $this->createMock(PersistingStoreInterface::class);
157158
$lock = new Lock($key, $store, 10);
158159

159160
$store
@@ -170,7 +171,7 @@ public function testRefresh()
170171
public function testRefreshCustom()
171172
{
172173
$key = new Key(uniqid(__METHOD__, true));
173-
$store = $this->getMockBuilder(PersistingStoreInterface::class)->getMock();
174+
$store = $this->createMock(PersistingStoreInterface::class);
174175
$lock = new Lock($key, $store, 10);
175176

176177
$store
@@ -187,7 +188,7 @@ public function testRefreshCustom()
187188
public function testIsAquired()
188189
{
189190
$key = new Key(uniqid(__METHOD__, true));
190-
$store = $this->getMockBuilder(PersistingStoreInterface::class)->getMock();
191+
$store = $this->createMock(PersistingStoreInterface::class);
191192
$lock = new Lock($key, $store, 10);
192193

193194
$store
@@ -201,7 +202,7 @@ public function testIsAquired()
201202
public function testRelease()
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
@@ -221,7 +222,7 @@ public function testRelease()
221222
public function testReleaseStoreInterface()
222223
{
223224
$key = new Key(uniqid(__METHOD__, true));
224-
$store = $this->getMockBuilder(PersistingStoreInterface::class)->getMock();
225+
$store = $this->createMock(PersistingStoreInterface::class);
225226
$lock = new Lock($key, $store, 10);
226227

227228
$store
@@ -278,9 +279,9 @@ public function testNoAutoReleaseWhenNotConfigured()
278279

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

286287
$store
@@ -299,9 +300,9 @@ public function testReleaseThrowsExceptionWhenDeletionFail()
299300

300301
public function testReleaseThrowsExceptionIfNotWellDeleted()
301302
{
302-
$this->expectException(\Symfony\Component\Lock\Exception\LockReleasingException::class);
303+
$this->expectException(LockReleasingException::class);
303304
$key = new Key(uniqid(__METHOD__, true));
304-
$store = $this->getMockBuilder(PersistingStoreInterface::class)->getMock();
305+
$store = $this->createMock(PersistingStoreInterface::class);
305306
$lock = new Lock($key, $store, 10);
306307

307308
$store
@@ -320,10 +321,10 @@ public function testReleaseThrowsExceptionIfNotWellDeleted()
320321

321322
public function testReleaseThrowsAndLog()
322323
{
323-
$this->expectException(\Symfony\Component\Lock\Exception\LockReleasingException::class);
324+
$this->expectException(LockReleasingException::class);
324325
$key = new Key(uniqid(__METHOD__, true));
325-
$store = $this->getMockBuilder(PersistingStoreInterface::class)->getMock();
326-
$logger = $this->getMockBuilder(LoggerInterface::class)->getMock();
326+
$store = $this->createMock(PersistingStoreInterface::class);
327+
$logger = $this->createMock(LoggerInterface::class);
327328
$lock = new Lock($key, $store, 10, true);
328329
$lock->setLogger($logger);
329330

@@ -351,7 +352,7 @@ public function testReleaseThrowsAndLog()
351352
public function testExpiration($ttls, $expected)
352353
{
353354
$key = new Key(uniqid(__METHOD__, true));
354-
$store = $this->getMockBuilder(PersistingStoreInterface::class)->getMock();
355+
$store = $this->createMock(PersistingStoreInterface::class);
355356
$lock = new Lock($key, $store, 10);
356357

357358
foreach ($ttls as $ttl) {
@@ -370,7 +371,7 @@ public function testExpiration($ttls, $expected)
370371
public function testExpirationStoreInterface($ttls, $expected)
371372
{
372373
$key = new Key(uniqid(__METHOD__, true));
373-
$store = $this->getMockBuilder(PersistingStoreInterface::class)->getMock();
374+
$store = $this->createMock(PersistingStoreInterface::class);
374375
$lock = new Lock($key, $store, 10);
375376

376377
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
/**
@@ -40,7 +41,7 @@ protected function getRedisConnection()
4041

4142
public function testInvalidTtl()
4243
{
43-
$this->expectException(\Symfony\Component\Lock\Exception\InvalidTtlException::class);
44+
$this->expectException(InvalidTtlException::class);
4445
new RedisStore($this->getRedisConnection(), -1);
4546
}
4647
}

0 commit comments

Comments
 (0)