Skip to content

Commit 8888741

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

File tree

9 files changed

+36
-30
lines changed

9 files changed

+36
-30
lines changed

Tests/File/FileTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\HttpFoundation\Tests\File;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException;
1516
use Symfony\Component\HttpFoundation\File\File;
1617

1718
/**
@@ -41,7 +42,7 @@ public function testGuessExtensionIsBasedOnMimeType()
4142

4243
public function testConstructWhenFileNotExists()
4344
{
44-
$this->expectException(\Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException::class);
45+
$this->expectException(FileNotFoundException::class);
4546

4647
new File(__DIR__.'/Fixtures/not_here');
4748
}

Tests/File/MimeType/MimeTypeTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
namespace Symfony\Component\HttpFoundation\Tests\File\MimeType;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\HttpFoundation\File\Exception\AccessDeniedException;
16+
use Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException;
1517
use Symfony\Component\HttpFoundation\File\MimeType\FileBinaryMimeTypeGuesser;
1618
use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser;
1719

@@ -39,7 +41,7 @@ public function testGuessImageWithoutExtension()
3941

4042
public function testGuessImageWithDirectory()
4143
{
42-
$this->expectException(\Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException::class);
44+
$this->expectException(FileNotFoundException::class);
4345

4446
MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/directory');
4547
}
@@ -68,7 +70,7 @@ public function testGuessWithDuplicatedFileType()
6870

6971
public function testGuessWithIncorrectPath()
7072
{
71-
$this->expectException(\Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException::class);
73+
$this->expectException(FileNotFoundException::class);
7274
MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/not_here');
7375
}
7476

@@ -87,7 +89,7 @@ public function testGuessWithNonReadablePath()
8789
@chmod($path, 0333);
8890

8991
if ('0333' == substr(sprintf('%o', fileperms($path)), -4)) {
90-
$this->expectException(\Symfony\Component\HttpFoundation\File\Exception\AccessDeniedException::class);
92+
$this->expectException(AccessDeniedException::class);
9193
MimeTypeGuesser::getInstance()->guess($path);
9294
} else {
9395
$this->markTestSkipped('Can not verify chmod operations, change of file permissions failed');

Tests/RequestTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\HttpFoundation\Tests;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\HttpFoundation\Exception\ConflictingHeadersException;
1516
use Symfony\Component\HttpFoundation\Exception\SuspiciousOperationException;
1617
use Symfony\Component\HttpFoundation\Request;
1718
use Symfony\Component\HttpFoundation\Session\Session;
@@ -1087,7 +1088,7 @@ public function getClientIpsProvider()
10871088
*/
10881089
public function testGetClientIpsWithConflictingHeaders($httpForwarded, $httpXForwardedFor)
10891090
{
1090-
$this->expectException(\Symfony\Component\HttpFoundation\Exception\ConflictingHeadersException::class);
1091+
$this->expectException(ConflictingHeadersException::class);
10911092
$request = new Request();
10921093

10931094
$server = [

Tests/ResponseTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -946,7 +946,7 @@ public function testSettersAreChainable()
946946
public function testNoDeprecationsAreTriggered()
947947
{
948948
new DefaultResponse();
949-
$this->getMockBuilder(Response::class)->getMock();
949+
$this->createMock(Response::class);
950950

951951
// we just need to ensure that subclasses of Response can be created without any deprecations
952952
// being triggered if the subclass does not override any final methods

Tests/Session/SessionTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag;
1616
use Symfony\Component\HttpFoundation\Session\Flash\FlashBag;
17+
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
1718
use Symfony\Component\HttpFoundation\Session\Session;
1819
use Symfony\Component\HttpFoundation\Session\SessionBagProxy;
20+
use Symfony\Component\HttpFoundation\Session\Storage\MetadataBag;
1921
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
2022

2123
/**
@@ -212,7 +214,7 @@ public function testGetId()
212214

213215
public function testGetFlashBag()
214216
{
215-
$this->assertInstanceOf(\Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface::class, $this->session->getFlashBag());
217+
$this->assertInstanceOf(FlashBagInterface::class, $this->session->getFlashBag());
216218
}
217219

218220
public function testGetIterator()
@@ -241,7 +243,7 @@ public function testGetCount()
241243

242244
public function testGetMeta()
243245
{
244-
$this->assertInstanceOf(\Symfony\Component\HttpFoundation\Session\Storage\MetadataBag::class, $this->session->getMetadataBag());
246+
$this->assertInstanceOf(MetadataBag::class, $this->session->getMetadataBag());
245247
}
246248

247249
public function testIsEmpty()

Tests/Session/Storage/Handler/MemcachedSessionHandlerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ protected function setUp(): void
3838
$this->markTestSkipped('Tests can only be run with memcached extension 2.1.0 or lower, or 3.0.0b1 or higher');
3939
}
4040

41-
$this->memcached = $this->getMockBuilder(\Memcached::class)->getMock();
41+
$this->memcached = $this->createMock(\Memcached::class);
4242
$this->storage = new MemcachedSessionHandler(
4343
$this->memcached,
4444
['prefix' => self::PREFIX, 'expiretime' => self::TTL]

Tests/Session/Storage/Handler/PdoSessionHandlerTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public function testReadWriteReadWithNullByte()
131131
public function testReadConvertsStreamToString()
132132
{
133133
$pdo = new MockPdo('pgsql');
134-
$pdo->prepareResult = $this->getMockBuilder(\PDOStatement::class)->getMock();
134+
$pdo->prepareResult = $this->createMock(\PDOStatement::class);
135135

136136
$content = 'foobar';
137137
$stream = $this->createStream($content);
@@ -152,8 +152,8 @@ public function testReadLockedConvertsStreamToString()
152152
}
153153

154154
$pdo = new MockPdo('pgsql');
155-
$selectStmt = $this->getMockBuilder(\PDOStatement::class)->getMock();
156-
$insertStmt = $this->getMockBuilder(\PDOStatement::class)->getMock();
155+
$selectStmt = $this->createMock(\PDOStatement::class);
156+
$insertStmt = $this->createMock(\PDOStatement::class);
157157

158158
$pdo->prepareResult = function ($statement) use ($selectStmt, $insertStmt) {
159159
return 0 === strpos($statement, 'INSERT') ? $insertStmt : $selectStmt;

Tests/Session/Storage/Handler/StrictSessionHandlerTest.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class StrictSessionHandlerTest extends TestCase
1919
{
2020
public function testOpen()
2121
{
22-
$handler = $this->getMockBuilder(\SessionHandlerInterface::class)->getMock();
22+
$handler = $this->createMock(\SessionHandlerInterface::class);
2323
$handler->expects($this->once())->method('open')
2424
->with('path', 'name')->willReturn(true);
2525
$proxy = new StrictSessionHandler($handler);
@@ -31,7 +31,7 @@ public function testOpen()
3131

3232
public function testCloseSession()
3333
{
34-
$handler = $this->getMockBuilder(\SessionHandlerInterface::class)->getMock();
34+
$handler = $this->createMock(\SessionHandlerInterface::class);
3535
$handler->expects($this->once())->method('close')
3636
->willReturn(true);
3737
$proxy = new StrictSessionHandler($handler);
@@ -41,7 +41,7 @@ public function testCloseSession()
4141

4242
public function testValidateIdOK()
4343
{
44-
$handler = $this->getMockBuilder(\SessionHandlerInterface::class)->getMock();
44+
$handler = $this->createMock(\SessionHandlerInterface::class);
4545
$handler->expects($this->once())->method('read')
4646
->with('id')->willReturn('data');
4747
$proxy = new StrictSessionHandler($handler);
@@ -51,7 +51,7 @@ public function testValidateIdOK()
5151

5252
public function testValidateIdKO()
5353
{
54-
$handler = $this->getMockBuilder(\SessionHandlerInterface::class)->getMock();
54+
$handler = $this->createMock(\SessionHandlerInterface::class);
5555
$handler->expects($this->once())->method('read')
5656
->with('id')->willReturn('');
5757
$proxy = new StrictSessionHandler($handler);
@@ -61,7 +61,7 @@ public function testValidateIdKO()
6161

6262
public function testRead()
6363
{
64-
$handler = $this->getMockBuilder(\SessionHandlerInterface::class)->getMock();
64+
$handler = $this->createMock(\SessionHandlerInterface::class);
6565
$handler->expects($this->once())->method('read')
6666
->with('id')->willReturn('data');
6767
$proxy = new StrictSessionHandler($handler);
@@ -71,7 +71,7 @@ public function testRead()
7171

7272
public function testReadWithValidateIdOK()
7373
{
74-
$handler = $this->getMockBuilder(\SessionHandlerInterface::class)->getMock();
74+
$handler = $this->createMock(\SessionHandlerInterface::class);
7575
$handler->expects($this->once())->method('read')
7676
->with('id')->willReturn('data');
7777
$proxy = new StrictSessionHandler($handler);
@@ -82,7 +82,7 @@ public function testReadWithValidateIdOK()
8282

8383
public function testReadWithValidateIdMismatch()
8484
{
85-
$handler = $this->getMockBuilder(\SessionHandlerInterface::class)->getMock();
85+
$handler = $this->createMock(\SessionHandlerInterface::class);
8686
$handler->expects($this->exactly(2))->method('read')
8787
->withConsecutive(['id1'], ['id2'])
8888
->will($this->onConsecutiveCalls('data1', 'data2'));
@@ -94,7 +94,7 @@ public function testReadWithValidateIdMismatch()
9494

9595
public function testUpdateTimestamp()
9696
{
97-
$handler = $this->getMockBuilder(\SessionHandlerInterface::class)->getMock();
97+
$handler = $this->createMock(\SessionHandlerInterface::class);
9898
$handler->expects($this->once())->method('write')
9999
->with('id', 'data')->willReturn(true);
100100
$proxy = new StrictSessionHandler($handler);
@@ -104,7 +104,7 @@ public function testUpdateTimestamp()
104104

105105
public function testWrite()
106106
{
107-
$handler = $this->getMockBuilder(\SessionHandlerInterface::class)->getMock();
107+
$handler = $this->createMock(\SessionHandlerInterface::class);
108108
$handler->expects($this->once())->method('write')
109109
->with('id', 'data')->willReturn(true);
110110
$proxy = new StrictSessionHandler($handler);
@@ -114,7 +114,7 @@ public function testWrite()
114114

115115
public function testWriteEmptyNewSession()
116116
{
117-
$handler = $this->getMockBuilder(\SessionHandlerInterface::class)->getMock();
117+
$handler = $this->createMock(\SessionHandlerInterface::class);
118118
$handler->expects($this->once())->method('read')
119119
->with('id')->willReturn('');
120120
$handler->expects($this->never())->method('write');
@@ -128,7 +128,7 @@ public function testWriteEmptyNewSession()
128128

129129
public function testWriteEmptyExistingSession()
130130
{
131-
$handler = $this->getMockBuilder(\SessionHandlerInterface::class)->getMock();
131+
$handler = $this->createMock(\SessionHandlerInterface::class);
132132
$handler->expects($this->once())->method('read')
133133
->with('id')->willReturn('data');
134134
$handler->expects($this->never())->method('write');
@@ -141,7 +141,7 @@ public function testWriteEmptyExistingSession()
141141

142142
public function testDestroy()
143143
{
144-
$handler = $this->getMockBuilder(\SessionHandlerInterface::class)->getMock();
144+
$handler = $this->createMock(\SessionHandlerInterface::class);
145145
$handler->expects($this->once())->method('destroy')
146146
->with('id')->willReturn(true);
147147
$proxy = new StrictSessionHandler($handler);
@@ -151,7 +151,7 @@ public function testDestroy()
151151

152152
public function testDestroyNewSession()
153153
{
154-
$handler = $this->getMockBuilder(\SessionHandlerInterface::class)->getMock();
154+
$handler = $this->createMock(\SessionHandlerInterface::class);
155155
$handler->expects($this->once())->method('read')
156156
->with('id')->willReturn('');
157157
$handler->expects($this->once())->method('destroy')->willReturn(true);
@@ -163,7 +163,7 @@ public function testDestroyNewSession()
163163

164164
public function testDestroyNonEmptyNewSession()
165165
{
166-
$handler = $this->getMockBuilder(\SessionHandlerInterface::class)->getMock();
166+
$handler = $this->createMock(\SessionHandlerInterface::class);
167167
$handler->expects($this->once())->method('read')
168168
->with('id')->willReturn('');
169169
$handler->expects($this->once())->method('write')
@@ -179,7 +179,7 @@ public function testDestroyNonEmptyNewSession()
179179

180180
public function testGc()
181181
{
182-
$handler = $this->getMockBuilder(\SessionHandlerInterface::class)->getMock();
182+
$handler = $this->createMock(\SessionHandlerInterface::class);
183183
$handler->expects($this->once())->method('gc')
184184
->with(123)->willReturn(true);
185185
$proxy = new StrictSessionHandler($handler);

Tests/Session/Storage/Proxy/SessionHandlerProxyTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class SessionHandlerProxyTest extends TestCase
3636

3737
protected function setUp(): void
3838
{
39-
$this->mock = $this->getMockBuilder(\SessionHandlerInterface::class)->getMock();
39+
$this->mock = $this->createMock(\SessionHandlerInterface::class);
4040
$this->proxy = new SessionHandlerProxy($this->mock);
4141
}
4242

@@ -127,7 +127,7 @@ public function testGc()
127127
*/
128128
public function testValidateId()
129129
{
130-
$mock = $this->getMockBuilder(TestSessionHandler::class)->getMock();
130+
$mock = $this->createMock(TestSessionHandler::class);
131131
$mock->expects($this->once())
132132
->method('validateId');
133133

@@ -142,7 +142,7 @@ public function testValidateId()
142142
*/
143143
public function testUpdateTimestamp()
144144
{
145-
$mock = $this->getMockBuilder(TestSessionHandler::class)->getMock();
145+
$mock = $this->createMock(TestSessionHandler::class);
146146
$mock->expects($this->once())
147147
->method('updateTimestamp')
148148
->willReturn(false);

0 commit comments

Comments
 (0)