Skip to content

Commit 790f1db

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

34 files changed

+217
-202
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()
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/CacheWarmer/TemplateFinderTest.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Bundle\FrameworkBundle\Templating\TemplateFilenameParser;
1616
use Symfony\Bundle\FrameworkBundle\Tests\Fixtures\BaseBundle\BaseBundle;
1717
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
18+
use Symfony\Component\HttpKernel\Kernel;
1819

1920
/**
2021
* @group legacy
@@ -23,12 +24,7 @@ class TemplateFinderTest extends TestCase
2324
{
2425
public function testFindAllTemplates()
2526
{
26-
$kernel = $this
27-
->getMockBuilder(\Symfony\Component\HttpKernel\Kernel::class)
28-
->disableOriginalConstructor()
29-
->getMock()
30-
;
31-
27+
$kernel = $this->createMock(Kernel::class);
3228
$kernel
3329
->expects($this->any())
3430
->method('getBundle')

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()
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()
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()
8076
*/
8177
private function getPruneableInterfaceMock()
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
@@ -18,6 +18,11 @@
1818
use Symfony\Component\DependencyInjection\Container;
1919
use Symfony\Component\Filesystem\Filesystem;
2020
use Symfony\Component\HttpKernel;
21+
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
22+
use Symfony\Component\HttpKernel\KernelInterface;
23+
use Symfony\Component\Translation\Extractor\ExtractorInterface;
24+
use Symfony\Component\Translation\Reader\TranslationReader;
25+
use Symfony\Component\Translation\Translator;
2126

2227
class TranslationDebugCommandTest extends TestCase
2328
{
@@ -101,7 +106,7 @@ public function testDebugCustomDirectory()
101106
{
102107
$this->fs->mkdir($this->translationDir.'/customDir/translations');
103108
$this->fs->mkdir($this->translationDir.'/customDir/templates');
104-
$kernel = $this->getMockBuilder(\Symfony\Component\HttpKernel\KernelInterface::class)->getMock();
109+
$kernel = $this->createMock(KernelInterface::class);
105110
$kernel->expects($this->once())
106111
->method('getBundle')
107112
->with($this->equalTo($this->translationDir.'/customDir'))
@@ -117,7 +122,7 @@ public function testDebugCustomDirectory()
117122
public function testDebugInvalidDirectory()
118123
{
119124
$this->expectException(\InvalidArgumentException::class);
120-
$kernel = $this->getMockBuilder(\Symfony\Component\HttpKernel\KernelInterface::class)->getMock();
125+
$kernel = $this->createMock(KernelInterface::class);
121126
$kernel->expects($this->once())
122127
->method('getBundle')
123128
->with($this->equalTo('dir'))
@@ -142,16 +147,13 @@ protected function tearDown(): void
142147

143148
private function createCommandTester($extractedMessages = [], $loadedMessages = [], $kernel = null, array $transPaths = [], array $viewsPaths = []): CommandTester
144149
{
145-
$translator = $this->getMockBuilder(\Symfony\Component\Translation\Translator::class)
146-
->disableOriginalConstructor()
147-
->getMock();
148-
150+
$translator = $this->createMock(Translator::class);
149151
$translator
150152
->expects($this->any())
151153
->method('getFallbackLocales')
152154
->willReturn(['en']);
153155

154-
$extractor = $this->getMockBuilder(\Symfony\Component\Translation\Extractor\ExtractorInterface::class)->getMock();
156+
$extractor = $this->createMock(ExtractorInterface::class);
155157
$extractor
156158
->expects($this->any())
157159
->method('extract')
@@ -161,7 +163,7 @@ function ($path, $catalogue) use ($extractedMessages) {
161163
}
162164
);
163165

164-
$loader = $this->getMockBuilder(\Symfony\Component\Translation\Reader\TranslationReader::class)->getMock();
166+
$loader = $this->createMock(TranslationReader::class);
165167
$loader
166168
->expects($this->any())
167169
->method('read')
@@ -182,7 +184,7 @@ function ($path, $catalogue) use ($loadedMessages) {
182184
['test', true, $this->getBundle('test')],
183185
];
184186
}
185-
$kernel = $this->getMockBuilder(\Symfony\Component\HttpKernel\KernelInterface::class)->getMock();
187+
$kernel = $this->createMock(KernelInterface::class);
186188
$kernel
187189
->expects($this->any())
188190
->method('getBundle')
@@ -212,7 +214,7 @@ function ($path, $catalogue) use ($loadedMessages) {
212214

213215
private function getBundle($path)
214216
{
215-
$bundle = $this->getMockBuilder(\Symfony\Component\HttpKernel\Bundle\BundleInterface::class)->getMock();
217+
$bundle = $this->createMock(BundleInterface::class);
216218
$bundle
217219
->expects($this->any())
218220
->method('getPath')

Tests/Command/TranslationUpdateCommandTest.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@
1818
use Symfony\Component\DependencyInjection\Container;
1919
use Symfony\Component\Filesystem\Filesystem;
2020
use Symfony\Component\HttpKernel;
21+
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
22+
use Symfony\Component\HttpKernel\KernelInterface;
23+
use Symfony\Component\Translation\Extractor\ExtractorInterface;
24+
use Symfony\Component\Translation\Reader\TranslationReader;
25+
use Symfony\Component\Translation\Translator;
26+
use Symfony\Component\Translation\Writer\TranslationWriter;
2127

2228
class TranslationUpdateCommandTest extends TestCase
2329
{
@@ -152,18 +158,15 @@ protected function tearDown(): void
152158
/**
153159
* @return CommandTester
154160
*/
155-
private function createCommandTester($extractedMessages = [], $loadedMessages = [], HttpKernel\KernelInterface $kernel = null, array $transPaths = [], array $viewsPaths = [])
161+
private function createCommandTester($extractedMessages = [], $loadedMessages = [], KernelInterface $kernel = null, array $transPaths = [], array $viewsPaths = [])
156162
{
157-
$translator = $this->getMockBuilder(\Symfony\Component\Translation\Translator::class)
158-
->disableOriginalConstructor()
159-
->getMock();
160-
163+
$translator = $this->createMock(Translator::class);
161164
$translator
162165
->expects($this->any())
163166
->method('getFallbackLocales')
164167
->willReturn(['en']);
165168

166-
$extractor = $this->getMockBuilder(\Symfony\Component\Translation\Extractor\ExtractorInterface::class)->getMock();
169+
$extractor = $this->createMock(ExtractorInterface::class);
167170
$extractor
168171
->expects($this->any())
169172
->method('extract')
@@ -175,7 +178,7 @@ function ($path, $catalogue) use ($extractedMessages) {
175178
}
176179
);
177180

178-
$loader = $this->getMockBuilder(\Symfony\Component\Translation\Reader\TranslationReader::class)->getMock();
181+
$loader = $this->createMock(TranslationReader::class);
179182
$loader
180183
->expects($this->any())
181184
->method('read')
@@ -185,7 +188,7 @@ function ($path, $catalogue) use ($loadedMessages) {
185188
}
186189
);
187190

188-
$writer = $this->getMockBuilder(\Symfony\Component\Translation\Writer\TranslationWriter::class)->getMock();
191+
$writer = $this->createMock(TranslationWriter::class);
189192
$writer
190193
->expects($this->any())
191194
->method('getFormats')
@@ -204,7 +207,7 @@ function ($path, $catalogue) use ($loadedMessages) {
204207
['test', true, $this->getBundle('test')],
205208
];
206209
}
207-
$kernel = $this->getMockBuilder(\Symfony\Component\HttpKernel\KernelInterface::class)->getMock();
210+
$kernel = $this->createMock(KernelInterface::class);
208211
$kernel
209212
->expects($this->any())
210213
->method('getBundle')
@@ -233,7 +236,7 @@ function ($path, $catalogue) use ($loadedMessages) {
233236

234237
private function getBundle($path)
235238
{
236-
$bundle = $this->getMockBuilder(\Symfony\Component\HttpKernel\Bundle\BundleInterface::class)->getMock();
239+
$bundle = $this->createMock(BundleInterface::class);
237240
$bundle
238241
->expects($this->any())
239242
->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')

0 commit comments

Comments
 (0)