Skip to content

Commit

Permalink
Remove calls to getMockForAbstractClass()
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandre-daubois committed May 15, 2024
1 parent 51ffc08 commit 77810d5
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
9 changes: 8 additions & 1 deletion Tests/EventListener/SessionListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Session\SessionFactory;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;
use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorageFactory;
use Symfony\Component\HttpFoundation\Session\Storage\PhpBridgeSessionStorageFactory;
Expand Down Expand Up @@ -338,7 +339,13 @@ public function testSessionCookieSetWhenOtherNativeVariablesSet()

public function testOnlyTriggeredOnMainRequest()
{
$listener = $this->getMockForAbstractClass(AbstractSessionListener::class);
$listener = new class() extends AbstractSessionListener {
protected function getSession(): ?SessionInterface
{
return null;
}
};

$event = $this->createMock(RequestEvent::class);
$event->expects($this->once())->method('isMainRequest')->willReturn(false);
$event->expects($this->never())->method('getRequest');
Expand Down
18 changes: 14 additions & 4 deletions Tests/EventListener/TestSessionListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,21 @@ class TestSessionListenerTest extends TestCase

protected function setUp(): void
{
$this->listener = $this->getMockForAbstractClass(AbstractTestSessionListener::class);
$this->session = $this->getSession();
$this->listener->expects($this->any())
->method('getSession')
->willReturn($this->session);
$this->listener = new class($this->session) extends AbstractTestSessionListener {
private $session;

public function __construct($session)
{
parent::__construct();
$this->session = $session;
}

public function getSession(): ?SessionInterface
{
return $this->session;
}
};
}

public function testShouldSaveMainRequestSession()
Expand Down
2 changes: 1 addition & 1 deletion Tests/Fragment/RoutableFragmentRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public static function getGenerateFragmentUriDataWithNonScalar()

private function callGenerateFragmentUriMethod(ControllerReference $reference, Request $request, $absolute = false)
{
$renderer = $this->getMockForAbstractClass(RoutableFragmentRenderer::class);
$renderer = $this->createStub(RoutableFragmentRenderer::class);
$r = new \ReflectionObject($renderer);
$m = $r->getMethod('generateFragmentUri');
$m->setAccessible(true);
Expand Down
11 changes: 5 additions & 6 deletions Tests/KernelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ public function testLocateResourceOnDirectories()
$kernel
->expects($this->exactly(2))
->method('getBundle')
->willReturn($this->getBundle(__DIR__.'/Fixtures/Bundle1Bundle', null, null, 'Bundle1Bundle'))
->willReturn($this->getBundle(__DIR__.'/Fixtures/Bundle1Bundle', null, 'Bundle1Bundle'))
;

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

$kernel = $this->getKernel([], [$fooBundle, $barBundle]);
$kernel->boot();
Expand Down Expand Up @@ -628,19 +628,18 @@ public function getContainerClass(): string
/**
* Returns a mock for the BundleInterface.
*/
protected function getBundle($dir = null, $parent = null, $className = null, $bundleName = null): BundleInterface
protected function getBundle($dir = null, $className = null, $bundleName = null): BundleInterface
{
$bundle = $this
->getMockBuilder(BundleInterface::class)
->onlyMethods(['getPath', 'getName'])
->disableOriginalConstructor()
;

if ($className) {
$bundle->setMockClassName($className);
}

$bundle = $bundle->getMockForAbstractClass();
$bundle = $bundle->getMock();

$bundle
->expects($this->any())
Expand Down

0 comments on commit 77810d5

Please sign in to comment.