8000 minor #49624 [Tests] Replace `setMethods()` by `onlyMethods()` and `a… · symfony/symfony@f2ccff6 · GitHub
[go: up one dir, main page]

Skip to content

Commit f2ccff6

Browse files
minor #49624 [Tests] Replace setMethods() by onlyMethods() and addMethods() (alexandre-daubois)
This PR was merged into the 5.4 branch. Discussion ---------- [Tests] Replace `setMethods()` by `onlyMethods()` and `addMethods()` | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - `setMethods()` is deprecated and must be replaced by `onlyMethods()` and `addMethods()`. This PR fixes this 🙂 Commits ------- d8ec2af [Tests] Replace `setMethods()` by `onlyMethods()` and `addMethods()`
2 parents 1b114f4 + d8ec2af commit f2ccff6

File tree

47 files changed

+128
-102
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+128
-102
lines changed

src/Symfony/Bridge/Doctrine/Tests/DependencyInjection/DoctrineExtensionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ protected function setUp(): void
3434

3535
$this->extension = $this
3636
->getMockBuilder(AbstractDoctrineExtension::class)
37-
->setMethods([
37+
->onlyMethods([
3838
'getMappingResourceConfigDirectory',
3939
'getObjectManagerElementName',
4040
'getMappingObjectDefaultName',

src/Symfony/Bridge/Doctrine/Tests/Form/ChoiceList/ORMQueryBuilderLoaderTest.php

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
namespace Symfony\Bridge\Doctrine\Tests\Form\ChoiceList;
1313

1414
use Doctrine\DBAL\Connection;
15+
use Doctrine\DBAL\Result;
1516
use Doctrine\DBAL\Types\GuidType;
1617
use Doctrine\DBAL\Types\Type;
18+
use Doctrine\ORM\AbstractQuery;
1719
use Doctrine\ORM\Version;
1820
use PHPUnit\Framework\TestCase;
1921
use Symfony\Bridge\Doctrine\Form\ChoiceList\ORMQueryBuilderLoader;
@@ -46,8 +48,8 @@ protected function checkIdentifierType($classname, $expectedType)
4648
{
4749
$em = DoctrineTestHelper::createTestEntityManager();
4850

49-
$query = $this->getMockBuilder(\QueryMock::class)
50-
->setMethods(['setParameter', 'getResult', 'getSql', '_doExecute'])
51+
$query = $this->getMockBuilder(QueryMock::class)
52+
->onlyMethods(['setParameter', 'getResult', 'getSql', '_doExecute'])
5153 ->getMock();
5254

5355
$query
@@ -61,7 +63,7 @@ protected function checkIdentifierType($classname, $expectedType)
6163

6264
$qb = $this->getMockBuilder(\Doctrine\ORM\QueryBuilder::class)
6365
->setConstructorArgs([$em])
64-
->setMethods(['getQuery'])
66+
->onlyMethods(['getQuery'])
6567
->getMock();
6668

6769
$qb->expects($this->once())
@@ -79,8 +81,8 @@ public function testFilterNonIntegerValues()
7981
{
8082
$em = DoctrineTestHelper::createTestEntityManager();
8183

82-
$query = $this->getMockBuilder(\QueryMock::class)
83-
->setMethods(['setParameter', 'getResult', 'getSql', '_doExecute'])
84+
$query = $this->getMockBuilder(QueryMock::class)
85+
->onlyMethods(['setParameter', 'getResult', 'getSql', '_doExecute'])
8486
->getMock();
8587

8688
$query
@@ -94,7 +96,7 @@ public function testFilterNonIntegerValues()
9496

9597
$qb = $this->getMockBuilder(\Doctrine\ORM\QueryBuilder::class)
9698
->setConstructorArgs([$em])
97-
->setMethods(['getQuery'])
99+
->onlyMethods(['getQuery'])
98100
->getMock();
99101

100102
$qb->expects($this->once())
@@ -115,8 +117,8 @@ public function testFilterEmptyUuids($entityClass)
115117
{
116118
$em = DoctrineTestHelper::createTestEntityManager();
117119

118-
$query = $this->getMockBuilder(\QueryMock::class)
119-
->setMethods(['setParameter', 'getResult', 'getSql', '_doExecute'])
120+
$query = $this->getMockBuilder(QueryMock::class)
121+
->onlyMethods(['setParameter', 'getResult', 'getSql', '_doExecute'])
120122
->getMock();
121123

122124
$query
@@ -130,7 +132,7 @@ public function testFilterEmptyUuids($entityClass)
130132

131133
$qb = $this->getMockBuilder(\Doctrine\ORM\QueryBuilder::class)
132134
->setConstructorArgs([$em])
133-
->setMethods(['getQuery'])
135+
->onlyMethods(['getQuery'])
134136
->getMock();
135137

136138
$qb->expects($this->once())
@@ -160,8 +162,8 @@ public function testFilterUid($entityClass)
160162

161163
$em = DoctrineTestHelper::createTestEntityManager();
162164

163-
$query = $this->getMockBuilder(\QueryMock::class)
164-
->setMethods(['setParameter', 'getResult', 'getSql', '_doExecute'])
165+
$query = $this->getMockBuilder(QueryMock::class)
166+
->onlyMethods(['setParameter', 'getResult', 'getSql', '_doExecute'])
165167
->getMock();
166168

167169
$query
@@ -175,7 +177,7 @@ public function testFilterUid($entityClass)
175177

176178
$qb = $this->getMockBuilder(\Doctrine\ORM\QueryBuilder::class)
177179
->setConstructorArgs([$em])
178-
->setMethods(['getQuery'])
180+
->onlyMethods(['getQuery'])
179181
->getMock();
180182

181183
$qb->expects($this->once())
@@ -207,7 +209,7 @@ public function testUidThrowProperException($entityClass)
207209

208210
$qb = $this->getMockBuilder(\Doctrine\ORM\QueryBuilder::class)
209211
->setConstructorArgs([$em])
210-
->setMethods(['getQuery'])
212+
->onlyMethods(['getQuery'])
211213
->getMock();
212214

213215
$qb->expects($this->never())
@@ -234,8 +236,8 @@ public function testEmbeddedIdentifierName()
234236

235237
$em = DoctrineTestHelper::createTestEntityManager();
236238

237-
$query = $this->getMockBuilder(\QueryMock::class)
238-
->setMethods(['setParameter', 'getResult', 'getSql', '_doExecute'])
239+
$query = $this->getMockBuilder(QueryMock::class)
240+
->onlyMethods(['setParameter', 'getResult', 'getSql', '_doExecute'])
239241
->getMock();
240242

241243
$query
@@ -249,7 +251,7 @@ public function testEmbeddedIdentifierName()
249251

250252
$qb = $this->getMockBuilder(\Doctrine\ORM\QueryBuilder::class)
251253
->setConstructorArgs([$em])
252-
->setMethods(['getQuery'])
254+
->onlyMethods(['getQuery'])
253255
->getMock();
254256
$qb->expects($this->once())
255257
->method('getQuery')
@@ -278,3 +280,24 @@ public static function provideUidEntityClasses()
278280
];
279281
}
280282
}
283+
284+
class QueryMock extends AbstractQuery
285+
{
286+
public function __construct()
287+
{
288+
}
289+
290+
/**
291+
* @return array|string
292+
*/
293+
public function getSQL()
294+
{
295+
}
296+
297+
/**
298+
* @return Result|int
299+
*/
300+
protected function _doExecute()
301+
{
302+
}
303+
}

src/Symfony/Bridge/Doctrine/Tests/Logger/DbalLoggerTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function testLog($sql, $params, $logParams)
3030
$dbalLogger = $this
3131
->getMockBuilder(DbalLogger::class)
3232
->setConstructorArgs([$logger, null])
33-
->setMethods(['log'])
33+
->onlyMethods(['log'])
3434
->getMock()
3535
;
3636

@@ -62,7 +62,7 @@ public function testLogNonUtf8()
6262
$dbalLogger = $this
6363
->getMockBuilder(DbalLogger::class)
6464
->setConstructorArgs([$logger, null])
65-
->setMethods(['log'])
65+
->onlyMethods(['log'])
6666
->getMock()
6767
;
6868

@@ -85,7 +85,7 @@ public function testLogNonUtf8Array()
8585
$dbalLogger = $this
8686
->getMockBuilder(DbalLogger::class)
8787
->setConstructorArgs([$logger, null])
88-
->setMethods(['log'])
88+
->onlyMethods(['log'])
8989
->getMock()
9090
;
9191

@@ -116,7 +116,7 @@ public function testLogLongString()
116116
$dbalLogger = $this
117117
->getMockBuilder(DbalLogger::class)
118118
->setConstructorArgs([$logger, null])
119-
->setMethods(['log'])
119+
->onlyMethods(['log'])
120120
->getMock()
121121
;
122122

@@ -144,7 +144,7 @@ public function testLogUTF8LongString()
144144
$dbalLogger = $this
145145
->getMockBuilder(DbalLogger::class)
146146
->setConstructorArgs([$logger, null])
147-
->setMethods(['log'])
147+
->onlyMethods(['log'])
148148
->getMock()
149149
;
150150

src/Symfony/Bridge/Doctrine/Tests/Security/User/EntityUserProviderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ private function getManager($em, $name = null)
211211
private function getObjectManager($repository)
212212
{
213213
$em = $this->getMockBuilder(ObjectManager::class)
214-
->setMethods(['getClassMetadata', 'getRepository'])
214+
->onlyMethods(['getClassMetadata', 'getRepository'])
215215
->getMockForAbstractClass();
216216
$em->expects($this->any())
217217
->method('getRepository')

src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueEntityValidatorTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ protected function createRegistryMock($em = null)
9696
protected function createRepositoryMock()
9797
{
9898
$repository = $this->getMockBuilder(ObjectRepository::class)
99-
->setMethods(['findByCustom', 'find', 'findAll', 'findOneBy', 'findBy', 'getClassName'])
99+
->onlyMethods(['find', 'findAll', 'findOneBy', 'findBy', 'getClassName'])
100+
->addMethods(['findByCustom'])
100101
->getMock()
101102
;
102103

src/Symfony/Bridge/Monolog/Tests/Handler/ConsoleHandlerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function testVerbosityMapping($verbosity, $level, $isHandling, array $map
6464
$levelName = Logger::getLevelName($level);
6565
$levelName = sprintf('%-9s', $levelName);
6666

67-
$realOutput = $this->getMockBuilder(Output::class)->setMethods(['doWrite'])->getMock();
67+
$realOutput = $this->getMockBuilder(Output::class)->onlyMethods(['doWrite'])->getMock();
6868
$realOutput->setVerbosity($verbosity);
6969
if ($realOutput->isDebug()) {
7070
$log = "16:21:54 $levelName [app] My info message\n";

src/Symfony/Bundle/FrameworkBundle/Tests/CacheWarmer/AnnotationsCacheWarmerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public function testWarmupRemoveCacheMisses()
136136
$cacheFile = tempnam($this->cacheDir, __FUNCTION__);
137137
$warmer = $this->getMockBuilder(AnnotationsCacheWarmer::class)
138138
->setConstructorArgs([new AnnotationReader(), $cacheFile])
139-
->setMethods(['doWarmUp'])
139+
->onlyMethods(['doWarmUp'])
140140
->getMock();
141141

142142
$warmer->method('doWarmUp')->willReturnCallback(function ($cacheDir, ArrayAdapter $arrayAdapter) {

src/Symfony/Bundle/FrameworkBundle/Tests/CacheWarmer/RouterCacheWarmerTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ class RouterCacheWarmerTest extends TestCase
2121
{
2222
public function testWarmUpWithWarmebleInterface()
2323
{
24-
$containerMock = $this->getMockBuilder(ContainerInterface::class)->setMethods(['get', 'has'])->getMock();
24+
$containerMock = $this->getMockBuilder(ContainerInterface::class)->onlyMethods(['get', 'has'])->getMock();
2525

26-
$routerMock = $this->getMockBuilder(testRouterInterfaceWithWarmebleInterface::class)->setMethods(['match', 'generate', 'getContext', 'setContext', 'getRouteCollection', 'warmUp'])->getMock();
26+
$routerMock = $this->getMockBuilder(testRouterInterfaceWithWarmebleInterface::class)->onlyMethods(['match', 'generate', 'getContext', 'setContext', 'getRouteCollection', 'warmUp'])->getMock();
2727
$containerMock->expects($this->any())->method('get')->with('router')->willReturn($routerMock);
2828
$routerCacheWarmer = new RouterCacheWarmer($containerMock);
2929

@@ -34,9 +34,9 @@ public function testWarmUpWithWarmebleInterface()
3434

3535
public function testWarmUpWithoutWarmebleInterface()
3636
{
37-
$containerMock = $this->getMockBuilder(ContainerInterface::class)->setMethods(['get', 'has'])->getMock();
37+
$containerMock = $this->getMockBuilder(ContainerInterface::class)->onlyMethods(['get', 'has'])->getMock();
3838

39-
$routerMock = $this->getMockBuilder(testRouterInterfaceWithoutWarmebleInterface::class)->setMethods(['match', 'generate', 'getContext', 'setContext', 'getRouteCollection'])->getMock();
39+
$routerMock = $this->getMockBuilder(testRouterInterfaceWithoutWarmebleInterface::class)->onlyMethods(['match', 'generate', 'getContext', 'setContext', 'getRouteCollection'])->getMock();
4040
$containerMock->expects($this->any())->method('get')->with('router')->willReturn($routerMock);
4141
$routerCacheWarmer = new RouterCacheWarmer($containerMock);
4242
$this->expectException(\LogicException::class);

src/Symfony/Bundle/FrameworkBundle/Tests/KernelBrowserTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function testRequestAfterKernelShutdownAndPerformedRequest()
6464
private function getKernelMock()
6565
{
6666
$mock = $this->getMockBuilder($this->getKernelClass())
67-
->setMethods(['shutdown', 'boot', 'handle', 'getContainer'])
67+
->onlyMethods(['shutdown', 'boot', 'handle', 'getContainer'])
6868
->disableOriginalConstructor()
6969
->getMock();
7070

src/Symfony/Bundle/FrameworkBundle/Tests/Routing/RouterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ private function getServiceContainer(RouteCollection $routes): Container
609609
->willReturn($routes)
610610
;
611611

612-
$sc = $this->getMockBuilder(Container::class)->setMethods(['get'])->getMock();
612+
$sc = $this->getMockBuilder(Container::class)->onlyMethods(['get'])->getMock();
613613

614614
$sc
615615
->expects($this->once())

src/Symfony/Bundle/SecurityBundle/Tests/EventListener/VoteListenerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function testOnVoterVote()
2626
$traceableAccessDecisionManager = $this
2727
->getMockBuilder(TraceableAccessDecisionManager::class)
2828
->disableOriginalConstructor()
29-
->setMethods(['addVoterVote'])
29+
->onlyMethods(['addVoterVote'])
3030
->getMock();
3131

3232
$traceableAccessDecisionManager

src/Symfony/Component/Cache/Tests/Adapter/ChainAdapterTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ public function testExpirationOnAllAdapters()
215215

216216
$adapter1 = $this->getMockBuilder(FilesystemAdapter::class)
217217
->setConstructorArgs(['', 2])
218-
->setMethods(['save'])
218+
->onlyMethods(['save'])
219219
->getMock();
220220
$adapter1->expects($this->once())
221221
->method('save')
@@ -224,7 +224,7 @@ public function testExpirationOnAllAdapters()
224224

225225
$adapter2 = $this->getMockBuilder(FilesystemAdapter::class)
226226
->setConstructorArgs(['', 4])
227-
->setMethods(['save'])
227+
->onlyMethods(['save'])
228228
->getMock();
229229
$adapter2->expects($this->once())
230230
->method('save')

src/Symfony/Component/Cache/Tests/Adapter/MaxIdLengthAdapterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function testLongKey()
2121
{
2222
$cache = $this->getMockBuilder(MaxIdLengthAdapter::class)
2323
->setConstructorArgs([str_repeat('-', 10)])
24-
->setMethods(['doHave', 'doFetch', 'doDelete', 'doSave', 'doClear'])
24+
->onlyMethods(['doHave', 'doFetch', 'doDelete', 'doSave', 'doClear'])
2525
->getMock();
2626

2727
$cache->expects($this->exactly(2))

src/Symfony/Component/Console/Tests/ApplicationTest.php

Lines changed: 5 additions & 5 deletions
10000
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ public function testFindAlternativesOutput()
716716

717717
public function testFindNamespaceDoesNotFailOnDeepSimilarNamespaces()
718718
{
719-
$application = $this->getMockBuilder(Application::class)->setMethods(['getNamespaces'])->getMock();
719+
$application = $this->getMockBuilder(Application::class)->onlyMethods(['getNamespaces'])->getMock();
720720
$application->expects($this->once())
721721
->method('getNamespaces')
722722
->willReturn(['foo:sublong', 'bar:sub']);
@@ -876,7 +876,7 @@ public function testRenderExceptionEscapesLines()
876876

877877
public function testRenderExceptionLineBreaks()
878878
{
879-
$application = $this->getMockBuilder(Application::class)->setMethods(['getTerminalWidth'])->getMock();
879+
$application = $this->getMockBuilder(Application::class)->addMethods(['getTerminalWidth'])->getMock();
880880
$application->setAutoExit(false);
881881
$application->expects($this->any())
882882
->method('getTerminalWidth')
@@ -1103,7 +1103,7 @@ public function testRunReturnsIntegerExitCode()
11031103
{
11041104
$exception = new \Exception('', 4);
11051105

1106-
$application = $this->getMockBuilder(Application::class)->setMethods(['doRun'])->getMock();
1106+
$application = $this->getMockBuilder(Application::class)->onlyMethods(['doRun'])->getMock();
11071107
$application->setAutoExit(false);
11081108
$application->expects($this->once())
11091109
->method('doRun')
@@ -1142,7 +1142,7 @@ public function testRunReturnsExitCodeOneForExceptionCodeZero()
11421142
{
11431143
$exception = new \Exception('', 0);
11441144

1145-
$application = $this->getMockBuilder(Application::class)->setMethods(['doRun'])->getMock();
1145+
$application = $this->getMockBuilder(Application::class)->onlyMethods(['doRun'])->getMock();
11461146
$application->setAutoExit(false);
11471147
$application->expects($this->once())
11481148
->method('doRun')
@@ -1185,7 +1185,7 @@ public function testRunReturnsExitCodeOneForNegativeExceptionCode($exceptionCode
11851185
{
11861186
$exception = new \Exception('', $exceptionCode);
11871187

1188-
$application = $this->getMockBuilder(Application::class)->setMethods(['doRun'])->getMock();
1188+
$application = $this->getMockBuilder(Application::class)->onlyMethods(['doRun'])->getMock();
11891189
$application->setAutoExit(false);
11901190
$application->expects($this->once())
11911191
->method('doRun')

src/Symfony/Component/DependencyInjection/Tests/Compiler/MergeExtensionConfigurationPassTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function testExpressionLanguageProviderForwarding()
6161

6262
public function testExtensionLoadGetAMergeExtensionConfigurationContainerBuilderInstance()
6363
{
64-
$extension = $this->getMockBuilder(FooExtension::class)->setMethods(['load'])->getMock();
64+
$extension = $this->getMockBuilder(FooExtension::class)->onlyMethods(['load'])->getMock();
6565
$extension->expects($this->once())
6666
->method('load')
6767
->with($this->isType('array'), $this->isInstanceOf(MergeExtensionConfigurationContainerBuilder::class))
@@ -77,7 +77,7 @@ public function testExtensionLoadGetAMergeExtensionConfigurationContainerBuilder
7777

7878
public function testExtensionConfigurationIsTrackedByDefault()
7979
{
80-
$extension = $this->getMockBuilder(FooExtension::class)->setMethods(['getConfiguration'])->getMock();
80+
$extension = $this->getMockBuilder(FooExtension::class)->onlyMethods(['getConfiguration'])->getMock();
8181
$extension->expects($this->exactly(2))
8282
->method('getConfiguration')
8383
->willReturn(new FooConfiguration());

src/Symfony/Component/DomCrawler/Tests/FormTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,7 @@ protected function getFormFieldMock($name, $value = null)
874874
{
875875
$field = $this
876876
->getMockBuilder(FormField::class)
877-
->setMethods(['getName', 'getValue', 'setValue', 'initialize'])
877+
->onlyMethods(['getName', 'getValue', 'setValue', 'initialize'])
878878
->disableOriginalConstructor()
879879
->getMock()
880880
;

src/Symfony/Component/Form/Test/Traits/ValidatorExtensionTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ protected function getValidatorExtension(): ValidatorExtension
3535
}
3636

3737
$this->validator = $this->createMock(ValidatorInterface::class);
38-
$metadata = $this->getMockBuilder(ClassMetadata::class)->setConstructorArgs([''])->setMethods(['addPropertyConstraint'])->getMock();
38+
$metadata = $this->getMockBuilder(ClassMetadata::class)->setConstructorArgs([''])->onlyMethods(['addPropertyConstraint'])->getMock();
3939
$this->validator->expects($this->any())->method('getMetadataFor')->will($this->returnValue($metadata));
4040
$this->validator->expects($this->any())->method('validate')->will($this->returnValue(new ConstraintViolationList()));
4141

0 commit comments

Comments
 (0)
0