Skip to content

Commit a1843f3

Browse files
Remove calls to getMockForAbstractClass()
1 parent 6d21a59 commit a1843f3

File tree

22 files changed

+165
-90
lines changed

22 files changed

+165
-90
lines changed

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -233,14 +233,11 @@ private function getManager($em, $name = null)
233233

234234
private function getObjectManager($repository)
235235
{
236-
$em = $this->getMockBuilder(ObjectManager::class)
237-
->onlyMethods(['getClassMetadata', 'getRepository'])
238-
->getMockForAbstractClass();
239-
$em->expects($this->any())
240-
->method('getRepository')
236+
$objectManager = $this->createMock(ObjectManager::class);
237+
$objectManager->method('getRepository')
241238
->willReturn($repository);
242239

243-
return $em;
240+
return $objectManager;
244241
}
245242

246243
private function createSchema($em)

src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Security/Factory/AbstractFactoryTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,12 @@ public static function getSuccessHandlers()
145145

146146
protected function callFactory($id, $config, $userProviderId, $defaultEntryPointId)
147147
{
148-
$factory = $this->getMockForAbstractClass(AbstractFactory::class);
148+
$factory = $this->getMockBuilder(AbstractFactory::class)->onlyMethods([
149+
'createAuthProvider',
150+
'getListenerId',
151+
'getKey',
152+
'getPosition',
153+
])->getMock();
149154

150155
$factory
151156
->expects($this->once())

src/Symfony/Component/Config/Tests/Definition/BaseNodeTest.php

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,36 @@ public function testGetPathForChildNode(string $expected, array $params)
3636
}
3737
}
3838

39-
$node = $this->getMockForAbstractClass(BaseNode::class, $constructorArgs);
39+
$node = new class(...$constructorArgs) extends BaseNode {
40+
protected function validateType($value): void
41+
{
42+
}
43+
44+
protected function normalizeValue($value)
45+
{
46+
return null;
47+
}
48+
49+
protected function mergeValues($leftSide, $rightSide)
50+
{
51+
return null;
52+
}
53+
54+
protected function finalizeValue($value)
55+
{
56+
return null;
57+
}
58+
59+
public function hasDefaultValue(): bool
60+
{
61+
return true;
62+
}
63+
64+
public function getDefaultValue()
65+
{
66+
return null;
67+
}
68+
};
4069

4170
$this->assertSame($expected, $node->getPath());
4271
}

src/Symfony/Component/Console/Tests/Question/QuestionTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,15 @@ public function testSetAutocompleterValuesInvalid($values)
157157
public function testSetAutocompleterValuesWithTraversable()
158158
{
159159
$question1 = new Question('Test question 1');
160-
$iterator1 = $this->getMockForAbstractClass(\IteratorAggregate::class);
160+
$iterator1 = $this->createMock(\IteratorAggregate::class);
161161
$iterator1
162162
->expects($this->once())
163163
->method('getIterator')
164164
->willReturn(new \ArrayIterator(['Potato']));
165165
$question1->setAutocompleterValues($iterator1);
166166

167167
$question2 = new Question('Test question 2');
168-
$iterator2 = $this->getMockForAbstractClass(\IteratorAggregate::class);
168+
$iterator2 = $this->createMock(\IteratorAggregate::class);
169169
$iterator2
170170
->expects($this->once())
171171
->method('getIterator')

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Proxy/AbstractProxyTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class AbstractProxyTest extends TestCase
2929

3030
protected function setUp(): void
3131
{
32-
$this->proxy = $this->getMockForAbstractClass(AbstractProxy::class);
32+
$this->proxy = new class() extends AbstractProxy {};
3333
}
3434

3535
protected function tearDown(): void

src/Symfony/Component/HttpKernel/Tests/EventListener/SessionListenerTest.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Symfony\Component\HttpFoundation\Response;
2222
use Symfony\Component\HttpFoundation\Session\Session;
2323
use Symfony\Component\HttpFoundation\Session\SessionFactory;
24+
use Symfony\Component\HttpFoundation\Session\SessionInterface;
2425
use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;
2526
use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorageFactory;
2627
use Symfony\Component\HttpFoundation\Session\Storage\PhpBridgeSessionStorageFactory;
@@ -338,7 +339,13 @@ public function testSessionCookieSetWhenOtherNativeVariablesSet()
338339

339340
public function testOnlyTriggeredOnMainRequest()
340341
{
341-
$listener = $this->getMockForAbstractClass(AbstractSessionListener::class);
342+
$listener = new class() extends AbstractSessionListener {
343+
protected function getSession(): ?SessionInterface
344+
{
345+
return null;
346+
}
347+
};
348+
342349
$event = $this->createMock(RequestEvent::class);
343350
$event->expects($this->once())->method('isMainRequest')->willReturn(false);
344351
$event->expects($this->never())->method('getRequest');

src/Symfony/Component/HttpKernel/Tests/EventListener/TestSessionListenerTest.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,21 @@ class TestSessionListenerTest extends TestCase
4545

4646
protected function setUp(): void
4747
{
48-
$this->listener = $this->getMockForAbstractClass(AbstractTestSessionListener::class);
4948
$this->session = $this->getSession();
50-
$this->listener->expects($this->any())
51-
->method('getSession')
52-
->willReturn($this->session);
49+
$this->listener = new class($this->session) extends AbstractTestSessionListener {
50+
private $session;
51+
52+
public function __construct($session)
53+
{
54+
parent::__construct();
55+
$this->session = $session;
56+
}
57+
58+
public function getSession(): ?SessionInterface
59+
{
60+
return $this->session;
61+
}
62+
};
5363
}
5464

5565
public function testShouldSaveMainRequestSession()

src/Symfony/Component/HttpKernel/Tests/Fragment/RoutableFragmentRendererTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public static function getGenerateFragmentUriDataWithNonScalar()
7575

7676
private function callGenerateFragmentUriMethod(ControllerReference $reference, Request $request, $absolute = false)
7777
{
78-
$renderer = $this->getMockForAbstractClass(RoutableFragmentRenderer::class);
78+
$renderer = $this->createStub(RoutableFragmentRenderer::class);
7979
$r = new \ReflectionObject($renderer);
8080
$m = $r->getMethod('generateFragmentUri');
8181
$m->setAccessible(true);

src/Symfony/Component/HttpKernel/Tests/KernelTest.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ public function testLocateResourceOnDirectories()
400400
$kernel
401401
->expects($this->exactly(2))
402402
->method('getBundle')
403-
->willReturn($this->getBundle(__DIR__.'/Fixtures/Bundle1Bundle', null, null, 'Bundle1Bundle'))
403+
->willReturn($this->getBundle(__DIR__.'/Fixtures/Bundle1Bundle', null, 'Bundle1Bundle'))
404404
;
405405

406406
$this->assertEquals(
@@ -417,8 +417,8 @@ public function testInitializeBundleThrowsExceptionWhenRegisteringTwoBundlesWith
417417
{
418418
$this->expectException(\LogicException::class);
419419
$this->expectExceptionMessage('Trying to register two bundles with the same name "DuplicateName"');
420-
$fooBundle = $this->getBundle(__DIR__.'/Fixtures/FooBundle', null, 'FooBundle', 'DuplicateName');
421-
$barBundle = $this->getBundle(__DIR__.'/Fixtures/BarBundle', null, 'BarBundle', 'DuplicateName');
420+
$fooBundle = $this->getBundle(__DIR__.'/Fixtures/FooBundle', 'FooBundle', 'DuplicateName');
421+
$barBundle = $this->getBundle(__DIR__.'/Fixtures/BarBundle', 'BarBundle', 'DuplicateName');
422422

423423
$kernel = $this->getKernel([], [$fooBundle, $barBundle]);
424424
$kernel->boot();
@@ -628,19 +628,18 @@ public function getContainerClass(): string
628628
/**
629629
* Returns a mock for the BundleInterface.
630630
*/
631-
protected function getBundle($dir = null, $parent = null, $className = null, $bundleName = null): BundleInterface
631+
protected function getBundle($dir = null, $className = null, $bundleName = null): BundleInterface
632632
{
633633
$bundle = $this
634634
->getMockBuilder(BundleInterface::class)
635-
->onlyMethods(['getPath', 'getName'])
636635
->disableOriginalConstructor()
637636
;
638637

639638
if ($className) {
640639
$bundle->setMockClassName($className);
641640
}
642641

643-
$bundle = $bundle->getMockForAbstractClass();
642+
$bundle = $bundle->getMock();
644643

645644
$bundle
646645
->expects($this->any())

src/Symfony/Component/Mailer/Tests/Transport/Smtp/SmtpTransportTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public function testAssertResponseCodeWithNotValidCode()
158158

159159
private function invokeAssertResponseCode(string $response, array $codes): void
160160
{
161-
$transport = new SmtpTransport($this->getMockForAbstractClass(AbstractStream::class));
161+
$transport = new SmtpTransport($this->createStub(AbstractStream::class));
162162
$m = new \ReflectionMethod($transport, 'assertResponseCode');
163163
$m->setAccessible(true);
164164
$m->invoke($transport, $response, $codes);

0 commit comments

Comments
 (0)