Skip to content

Commit 1854728

Browse files
Merge branch '4.4' into 5.1
* 4.4: Use createMock() and use import instead of FQCN
2 parents c89a153 + 790f1db commit 1854728

20 files changed

+112
-114
lines changed

Tests/CacheWarmer/AnnotationsCacheWarmerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public function testClassAutoloadExceptionWithUnrelatedException()
125125
*/
126126
private function getReadOnlyReader(): object
127127
{
128-
$readerMock = $this->getMockBuilder(Reader::class)->getMock();
128+
$readerMock = $this->createMock(Reader::class);
129129
$readerMock->expects($this->exactly(0))->method('getClassAnnotations');
130130
$readerMock->expects($this->exactly(0))->method('getClassAnnotation');
131131
$readerMock->expects($this->exactly(0))->method('getMethodAnnotations');

Tests/Command/CachePoolDeleteCommandTest.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Symfony\Bundle\FrameworkBundle\Console\Application;
1818
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
1919
use Symfony\Component\Console\Tester\CommandTester;
20+
use Symfony\Component\DependencyInjection\ContainerInterface;
2021
use Symfony\Component\HttpKernel\CacheClearer\Psr6CacheClearer;
2122
use Symfony\Component\HttpKernel\KernelInterface;
2223

@@ -26,8 +27,7 @@ class CachePoolDeleteCommandTest extends TestCase
2627

2728
protected function setUp(): void
2829
{
29-
$this->cachePool = $this->getMockBuilder(CacheItemPoolInterface::class)
30-
->getMock();
30+
$this->cachePool = $this->createMock(CacheItemPoolInterface::class);
3131
}
3232

3333
public function testCommandWithValidKey()
@@ -88,14 +88,9 @@ public function testCommandDeleteFailed()
8888
*/
8989
private function getKernel(): object
9090
{
91-
$container = $this
92-
->getMockBuilder(\Symfony\Component\DependencyInjection\ContainerInterface::class)
93-
->getMock();
94-
95-
$kernel = $this
96-
->getMockBuilder(KernelInterface::class)
97-
->getMock();
91+
$container = $this->createMock(ContainerInterface::class);
9892

93+
$kernel = $this->createMock(KernelInterface::class);
9994
$kernel
10095
->expects($this->any())
10196
->method('getContainer')

Tests/Command/CachePruneCommandTest.php

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Symfony\Component\Cache\PruneableInterface;
1919
use Symfony\Component\Console\Tester\CommandTester;
2020
use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
21+
use Symfony\Component\DependencyInjection\ContainerInterface;
2122
use Symfony\Component\HttpKernel\KernelInterface;
2223

2324
class CachePruneCommandTest extends TestCase
@@ -54,14 +55,9 @@ private function getEmptyRewindableGenerator(): RewindableGenerator
5455
*/
5556
private function getKernel(): object
5657
{
57-
$container = $this
58-
->getMockBuilder(\Symfony\Component\DependencyInjection\ContainerInterface::class)
59-
->getMock();
60-
61-
$kernel = $this
62-
->getMockBuilder(KernelInterface::class)
63-
->getMock();
58+
$container = $this->createMock(ContainerInterface::class);
6459

60+
$kernel = $this->createMock(KernelInterface::class);
6561
$kernel
6662
->expects($this->any())
6763
->method('getContainer')
@@ -80,10 +76,7 @@ private function getKernel(): object
8076
*/
8177
private function getPruneableInterfaceMock(): object
8278
{
83-
$pruneable = $this
84-
->getMockBuilder(PruneableInterface::class)
85-
->getMock();
86-
79+
$pruneable = $this->createMock(PruneableInterface::class);
8780
$pruneable
8881
->expects($this->atLeastOnce())
8982
->method('prune');

Tests/Command/RouterMatchCommandTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616
use Symfony\Bundle\FrameworkBundle\Command\RouterMatchCommand;
1717
use Symfony\Bundle\FrameworkBundle\Console\Application;
1818
use Symfony\Component\Console\Tester\CommandTester;
19+
use Symfony\Component\DependencyInjection\ContainerInterface;
1920
use Symfony\Component\HttpKernel\KernelInterface;
2021
use Symfony\Component\Routing\RequestContext;
2122
use Symfony\Component\Routing\Route;
2223
use Symfony\Component\Routing\RouteCollection;
24+
use Symfony\Component\Routing\RouterInterface;
2325

2426
class RouterMatchCommandTest extends TestCase
2527
{
@@ -55,7 +57,7 @@ private function getRouter()
5557
$routeCollection = new RouteCollection();
5658
$routeCollection->add('foo', new Route('foo'));
5759
$requestContext = new RequestContext();
58-
$router = $this->getMockBuilder(\Symfony\Component\Routing\RouterInterface::class)->getMock();
60+
$router = $this->createMock(RouterInterface::class);
5961
$router
6062
->expects($this->any())
6163
->method('getRouteCollection')
@@ -70,7 +72,7 @@ private function getRouter()
7072

7173
private function getKernel()
7274
{
73-
$container = $this->getMockBuilder(\Symfony\Component\DependencyInjection\ContainerInterface::class)->getMock();
75+
$container = $this->createMock(ContainerInterface::class);
7476
$container
7577
->expects($this->atLeastOnce())
7678
->method('has')
@@ -85,7 +87,7 @@ private function getKernel()
8587
->willReturn($this->getRouter())
8688
;
8789

88-
$kernel = $this->getMockBuilder(KernelInterface::class)->getMock();
90+
$kernel = $this->createMock(KernelInterface::class);
8991
$kernel
9092
->expects($this->any())
9193
->method('getContainer')

Tests/Command/TranslationDebugCommandTest.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
use Symfony\Component\Console\Tester\CommandTester;
1818
use Symfony\Component\DependencyInjection\Container;
1919
use Symfony\Component\Filesystem\Filesystem;
20+
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
21+
use Symfony\Component\HttpKernel\KernelInterface;
22+
use Symfony\Component\Translation\Extractor\ExtractorInterface;
23+
use Symfony\Component\Translation\Reader\TranslationReader;
24+
use Symfony\Component\Translation\Translator;
2025

2126
class TranslationDebugCommandTest extends TestCase
2227
{
@@ -92,7 +97,7 @@ public function testDebugCustomDirectory()
9297
{
9398
$this->fs->mkdir($this->translationDir.'/customDir/translations');
9499
$this->fs->mkdir($this->translationDir.'/customDir/templates');
95-
$kernel = $this->getMockBuilder(\Symfony\Component\HttpKernel\KernelInterface::class)->getMock();
100+
$kernel = $this->createMock(KernelInterface::class);
96101
$kernel->expects($this->once())
97102
->method('getBundle')
98103
->with($this->equalTo($this->translationDir.'/customDir'))
@@ -111,7 +116,7 @@ public function testDebugCustomDirectory()
111116
public function testDebugInvalidDirectory()
112117
{
113118
$this->expectException(\InvalidArgumentException::class);
114-
$kernel = $this->getMockBuilder(\Symfony\Component\HttpKernel\KernelInterface::class)->getMock();
119+
$kernel = $this->createMock(KernelInterface::class);
115120
$kernel->expects($this->once())
116121
->method('getBundle')
117122
->with($this->equalTo('dir'))
@@ -136,16 +141,13 @@ protected function tearDown(): void
136141

137142
private function createCommandTester($extractedMessages = [], $loadedMessages = [], $kernel = null, array $transPaths = [], array $viewsPaths = []): CommandTester
138143
{
139-
$translator = $this->getMockBuilder(\Symfony\Component\Translation\Translator::class)
140-
->disableOriginalConstructor()
141-
->getMock();
142-
144+
$translator = $this->createMock(Translator::class);
143145
$translator
144146
->expects($this->any())
145147
->method('getFallbackLocales')
146148
->willReturn(['en']);
147149

148-
$extractor = $this->getMockBuilder(\Symfony\Component\Translation\Extractor\ExtractorInterface::class)->getMock();
150+
$extractor = $this->createMock(ExtractorInterface::class);
149151
$extractor
150152
->expects($this->any())
151153
->method('extract')
@@ -155,7 +157,7 @@ function ($path, $catalogue) use ($extractedMessages) {
155157
}
156158
);
157159

158-
$loader = $this->getMockBuilder(\Symfony\Component\Translation\Reader\TranslationReader::class)->getMock();
160+
$loader = $this->createMock(TranslationReader::class);
159161
$loader
160162
->expects($this->any())
161163
->method('read')
@@ -170,7 +172,7 @@ function ($path, $catalogue) use ($loadedMessages) {
170172
['foo', $this->getBundle($this->translationDir)],
171173
['test', $this->getBundle('test')],
172174
];
173-
$kernel = $this->getMockBuilder(\Symfony\Component\HttpKernel\KernelInterface::class)->getMock();
175+
$kernel = $this->createMock(KernelInterface::class);
174176
$kernel
175177
->expects($this->any())
176178
->method('getBundle')
@@ -198,7 +200,7 @@ function ($path, $catalogue) use ($loadedMessages) {
198200

199201
private function getBundle($path)
200202
{
201-
$bundle = $this->getMockBuilder(\Symfony\Component\HttpKernel\Bundle\BundleInterface::class)->getMock();
203+
$bundle = $this->createMock(BundleInterface::class);
202204
$bundle
203205
->expects($this->any())
204206
->method('getPath')

Tests/Command/TranslationUpdateCommandTest.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@
1717
use Symfony\Component\Console\Tester\CommandTester;
1818
use Symfony\Component\DependencyInjection\Container;
1919
use Symfony\Component\Filesystem\Filesystem;
20-
use Symfony\Component\HttpKernel;
20+
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
21+
use Symfony\Component\HttpKernel\KernelInterface;
22+
use Symfony\Component\Translation\Extractor\ExtractorInterface;
23+
use Symfony\Component\Translation\Reader\TranslationReader;
24+
use Symfony\Component\Translation\Translator;
25+
use Symfony\Component\Translation\Writer\TranslationWriter;
2126

2227
class TranslationUpdateCommandTest extends TestCase
2328
{
@@ -135,18 +140,15 @@ protected function tearDown(): void
135140
/**
136141
* @return CommandTester
137142
*/
138-
private function createCommandTester($extractedMessages = [], $loadedMessages = [], HttpKernel\KernelInterface $kernel = null, array $transPaths = [], array $viewsPaths = [])
143+
private function createCommandTester($extractedMessages = [], $loadedMessages = [], KernelInterface $kernel = null, array $transPaths = [], array $viewsPaths = [])
139144
{
140-
$translator = $this->getMockBuilder(\Symfony\Component\Translation\Translator::class)
141-
->disableOriginalConstructor()
142-
->getMock();
143-
145+
$translator = $this->createMock(Translator::class);
144146
$translator
145147
->expects($this->any())
146148
->method('getFallbackLocales')
147149
->willReturn(['en']);
148150

149-
$extractor = $this->getMockBuilder(\Symfony\Component\Translation\Extractor\ExtractorInterface::class)->getMock();
151+
$extractor = $this->createMock(ExtractorInterface::class);
150152
$extractor
151153
->expects($this->any())
152154
->method('extract')
@@ -158,7 +160,7 @@ function ($path, $catalogue) use ($extractedMessages) {
158160
}
159161
);
160162

161-
$loader = $this->getMockBuilder(\Symfony\Component\Translation\Reader\TranslationReader::class)->getMock();
163+
$loader = $this->createMock(TranslationReader::class);
162164
$loader
163165
->expects($this->any())
164166
->method('read')
@@ -168,7 +170,7 @@ function ($path, $catalogue) use ($loadedMessages) {
168170
}
169171
);
170172

171-
$writer = $this->getMockBuilder(\Symfony\Component\Translation\Writer\TranslationWriter::class)->getMock();
173+
$writer = $this->createMock(TranslationWriter::class);
172174
$writer
173175
->expects($this->any())
174176
->method('getFormats')
@@ -181,7 +183,7 @@ function ($path, $catalogue) use ($loadedMessages) {
181183
['foo', $this->getBundle($this->translationDir)],
182184
['test', $this->getBundle('test')],
183185
];
184-
$kernel = $this->getMockBuilder(\Symfony\Component\HttpKernel\KernelInterface::class)->getMock();
186+
$kernel = $this->createMock(KernelInterface::class);
185187
$kernel
186188
->expects($this->any())
187189
->method('getBundle')
@@ -209,7 +211,7 @@ function ($path, $catalogue) use ($loadedMessages) {
209211

210212
private function getBundle($path)
211213
{
212-
$bundle = $this->getMockBuilder(\Symfony\Component\HttpKernel\Bundle\BundleInterface::class)->getMock();
214+
$bundle = $this->createMock(BundleInterface::class);
213215
$bundle
214216
->expects($this->any())
215217
->method('getPath')

Tests/Command/XliffLintCommandTest.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,20 +73,14 @@ private function createCommandTester($application = null): CommandTester
7373

7474
private function getKernelAwareApplicationMock()
7575
{
76-
$kernel = $this->getMockBuilder(KernelInterface::class)
77-
->disableOriginalConstructor()
78-
->getMock();
79-
76+
$kernel = $this->createMock(KernelInterface::class);
8077
$kernel
8178
->expects($this->once())
8279
->method('locateResource')
8380
->with('@AppBundle/Resources')
8481
->willReturn(sys_get_temp_dir().'/xliff-lint-test');
8582

86-
$application = $this->getMockBuilder(Application::class)
87-
->disableOriginalConstructor()
88-
->getMock();
89-
83+
$application = $this->createMock(Application::class);
9084
$application
9185
->expects($this->once())
9286
->method('getKernel')

Tests/Command/YamlLintCommandTest.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,20 +120,14 @@ private function createCommandTester($application = null): CommandTester
120120

121121
private function getKernelAwareApplicationMock()
122122
{
123-
$kernel = $this->getMockBuilder(KernelInterface::class)
124-
->disableOriginalConstructor()
125-
->getMock();
126-
123+
$kernel = $this->createMock(KernelInterface::class);
127124
$kernel
128125
->expects($this->once())
129126
->method('locateResource')
130127
->with('@AppBundle/Resources')
131128
->willReturn(sys_get_temp_dir().'/yml-lint-test');
132129

133-
$application = $this->getMockBuilder(Application::class)
134-
->disableOriginalConstructor()
135-
->getMock();
136-
130+
$application = $this->createMock(Application::class);
137131
$application
138132
->expects($this->once())
139133
->method('getKernel')

Tests/Console/ApplicationTest.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,18 @@
2323
use Symfony\Component\Console\Output\OutputInterface;
2424
use Symfony\Component\Console\Tester\ApplicationTester;
2525
use Symfony\Component\DependencyInjection\ContainerBuilder;
26+
use Symfony\Component\DependencyInjection\ContainerInterface;
2627
use Symfony\Component\EventDispatcher\EventDispatcher;
28+
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
29+
use Symfony\Component\HttpKernel\Bundle\Bundle;
30+
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
2731
use Symfony\Component\HttpKernel\KernelInterface;
2832

2933
class ApplicationTest extends TestCase
3034
{
3135
public function testBundleInterfaceImplementation()
3236
{
33-
$bundle = $this->getMockBuilder(\Symfony\Component\HttpKernel\Bundle\BundleInterface::class)->getMock();
37+
$bundle = $this->createMock(BundleInterface::class);
3438

3539
$kernel = $this->getKernel([$bundle], true);
3640

@@ -126,7 +130,7 @@ public function testRunOnlyWarnsOnUnregistrableCommand()
126130
$container->register(ThrowingCommand::class, ThrowingCommand::class);
127131
$container->setParameter('console.command.ids', [ThrowingCommand::class => ThrowingCommand::class]);
128132

129-
$kernel = $this->getMockBuilder(KernelInterface::class)->getMock();
133+
$kernel = $this->createMock(KernelInterface::class);
130134
$kernel
131135
->method('getBundles')
132136
->willReturn([$this->createBundleMock(
@@ -154,7 +158,7 @@ public function testRegistrationErrorsAreDisplayedOnCommandNotFound()
154158
$container = new ContainerBuilder();
155159
$container->register('event_dispatcher', EventDispatcher::class);
156160

157-
$kernel = $this->getMockBuilder(KernelInterface::class)->getMock();
161+
$kernel = $this->createMock(KernelInterface::class);
158162
$kernel
159163
->method('getBundles')
160164
->willReturn([$this->createBundleMock(
@@ -183,7 +187,7 @@ public function testRunOnlyWarnsOnUnregistrableCommandAtTheEnd()
183187
$container->register(ThrowingCommand::class, ThrowingCommand::class);
184188
$container->setParameter('console.command.ids', [ThrowingCommand::class => ThrowingCommand::class]);
185189

186-
$kernel = $this->getMockBuilder(KernelInterface::class)->getMock();
190+
$kernel = $this->createMock(KernelInterface::class);
187191
$kernel->expects($this->once())->method('boot');
188192
$kernel
189193
->method('getBundles')
@@ -236,10 +240,10 @@ private function createEventForSuggestingPackages(string $command, array $altern
236240

237241
private function getKernel(array $bundles, $useDispatcher = false)
238242
{
239-
$container = $this->getMockBuilder(\Symfony\Component\DependencyInjection\ContainerInterface::class)->getMock();
243+
$container = $this->createMock(ContainerInterface::class);
240244

241245
if ($useDispatcher) {
242-
$dispatcher = $this->getMockBuilder(\Symfony\Component\EventDispatcher\EventDispatcherInterface::class)->getMock();
246+
$dispatcher = $this->createMock(EventDispatcherInterface::class);
243247
$dispatcher
244248
->expects($this->atLeastOnce())
245249
->method('dispatch')
@@ -264,7 +268,7 @@ private function getKernel(array $bundles, $useDispatcher = false)
264268
->willReturnOnConsecutiveCalls([], [])
265269
;
266270

267-
$kernel = $this->getMockBuilder(KernelInterface::class)->getMock();
271+
$kernel = $this->createMock(KernelInterface::class);
268272
$kernel->expects($this->once())->method('boot');
269273
$kernel
270274
->expects($this->any())
@@ -282,7 +286,7 @@ private function getKernel(array $bundles, $useDispatcher = false)
282286

283287
private function createBundleMock(array $commands)
284288
{
285-
$bundle = $this->getMockBuilder(\Symfony\Component\HttpKernel\Bundle\Bundle::class)->getMock();
289+
$bundle = $this->createMock(Bundle::class);
286290
$bundle
287291
->expects($this->once())
288292
->method('registerCommands')

0 commit comments

Comments
 (0)