8000 Merge branch '5.2' into 5.3 · symfony/symfony@d67dc12 · GitHub
[go: up one dir, main page]

Skip to content

Commit d67dc12

Browse files
committed
Merge branch '5.2' into 5.3
* 5.2: clean up remaining event mocks
2 parents e33714b + 79cd966 commit d67dc12

File tree

4 files changed

+15
-69
lines changed

4 files changed

+15
-69
lines changed

src/Symfony/Component/Security/Guard/Tests/Firewall/GuardAuthenticationListenerTest.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\HttpFoundation\Request;
1717
use Symfony\Component\HttpFoundation\Response;
1818
use Symfony\Component\HttpKernel\Event\RequestEvent;
19+
use Symfony\Component\HttpKernel\HttpKernelInterface;
1920
use Symfony\Component\Security\Core\Authentication\AuthenticationProviderManager;
2021
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
2122
use Symfony\Component\Security\Core\Exception\AuthenticationException;
@@ -323,14 +324,7 @@ protected function setUp(): void
323324
$this->guardAuthenticatorHandler = $this->createMock(GuardAuthenticatorHandler::class);
324325
$this->request = new Request([], [], [], [], [], []);
325326

326-
$this->event = $this->getMockBuilder(RequestEvent::class)
327-
->disableOriginalConstructor()
328-
->setMethods(['getRequest'])
329-
->getMock();
330-
$this->event
331-
->expects($this->any())
332-
->method('getRequest')
333-
->willReturn($this->request);
327+
$this->event = new RequestEvent($this->createMock(HttpKernelInterface::class), $this->request, HttpKernelInterface::MASTER_REQUEST);
334328

335329
$this->logger = $this->createMock(LoggerInterface::class);
336330
$this->rememberMeServices = $this->createMock(RememberMeServicesInterface::class);

src/Symfony/Component/Security/Http/Tests/Firewall/RememberMeListenerTest.php

Lines changed: 9 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function testOnCoreSecurityDoesNotTryToPopulateNonEmptyTokenStorage()
4848
->method('setToken')
4949
;
5050

51-
$this->assertNull($listener($this->getRequestEvent()));
51+
$this->assertNull($listener(new RequestEvent($this->createMock(HttpKernelInterface::class), new Request(), HttpKernelInterface::MASTER_REQUEST)));
5252
}
5353

5454
public function testOnCoreSecurityDoesNothingWhenNoCookieIsSet()
@@ -67,9 +67,7 @@ public function testOnCoreSecurityDoesNothingWhenNoCookieIsSet()
6767
->willReturn(null)
6868
;
6969

70-
$event = $this->getRequestEvent();
71-
72-
$this->assertNull($listener($event));
70+
$this->assertNull($listener(new RequestEvent($this->createMock(HttpKernelInterface::class), new Request(), HttpKernelInterface::MASTER_REQUEST)));
7371
}
7472

7573
public function testOnCoreSecurityIgnoresAuthenticationExceptionThrownByAuthenticationManagerImplementation()
@@ -102,9 +100,7 @@ public function testOnCoreSecurityIgnoresAuthenticationExceptionThrownByAuthenti
102100
->willThrowException($exception)
103101
;
104102

105-
$event = $this->getRequestEvent($request);
106-
107-
$listener($event);
103+
$listener(new RequestEvent($this->createMock(HttpKernelInterface::class), $request, HttpKernelInterface::MASTER_REQUEST));
108104
}
109105

110106
public function testOnCoreSecurityIgnoresAuthenticationOptionallyRethrowsExceptionThrownAuthenticationManagerImplementation()
@@ -137,9 +133,7 @@ public function testOnCoreSecurityIgnoresAuthenticationOptionallyRethrowsExcepti
137133
->willThrowException($exception)
138134
;
139135

140-
$event = $this->getRequestEvent();
141-
142-
$listener($event);
136+
$listener(new RequestEvent($this->createMock(HttpKernelInterface::class), new Request(), HttpKernelInterface::MASTER_REQUEST));
143137
}
144138

145139
public function testOnCoreSecurityAuthenticationExceptionDuringAutoLoginTriggersLoginFail()
@@ -169,9 +163,7 @@ public function testOnCoreSecurityAuthenticationExceptionDuringAutoLoginTriggers
169163
->method('authenticate')
170164
;
171165

172-
$event = $this->getRequestEvent();
173-
174-
$listener($event);
166+
$listener(new RequestEvent($this->createMock(HttpKernelInterface::class), new Request(), HttpKernelInterface::MASTER_REQUEST));
175167
}
176168

177169
public function testOnCoreSecurity()
@@ -203,9 +195,7 @@ public function testOnCoreSecurity()
203195
->willReturn($token)
204196
;
205197

206-
$event = $this->getRequestEvent();
207-
208-
$listener($event);
198+
$listener(new RequestEvent($this->createMock(HttpKernelInterface::class), new Request(), HttpKernelInterface::MASTER_REQUEST));
209199
}
210200

211201
public function testSessionStrategy()
@@ -247,15 +237,13 @@ public function testSessionStrategy()
247237
$request = new Request();
248238
$request->setSession($session);
249239

250-
$event = $this->getRequestEvent($request);
251-
252240
$sessionStrategy
253241
->expects($this->once())
254242
->method('onAuthentication')
255243
->willReturn(null)
256244
;
257245

258-
$listener($event);
246+
$listener(new RequestEvent($this->createMock(HttpKernelInterface::class), $request, HttpKernelInterface::MASTER_REQUEST));
259247
}
260248

261249
public function testSessionIsMigratedByDefault()
@@ -301,9 +289,7 @@ public function testSessionIsMigratedByDefault()
301289
$request = new Request();
302290
$request->setSession($session);
303291

304-
$event = $this->getRequestEvent($request);
305-
306-
$listener($event);
292+
$listener(new RequestEvent($this->createMock(HttpKernelInterface::class), $request, HttpKernelInterface::MASTER_REQUEST));
307293
}
308294

309295
public function testOnCoreSecurityInteractiveLoginEventIsDispatchedIfDispatcherIsPresent()
@@ -335,8 +321,6 @@ public function testOnCoreSecurityInteractiveLoginEventIsDispatchedIfDispatcherI
335321
->willReturn($token)
336322
;
337323

338-
$event = $this->getRequestEvent();
339-
340324
$dispatcher
341325
->expects($this->once())
342326
->method('dispatch')
@@ -346,23 +330,7 @@ public function testOnCoreSecurityInteractiveLoginEventIsDispatchedIfDispatcherI
346330
)
347331
;
348332

349-
$listener($event);
350-
}
351-
352-
protected function getRequestEvent(Request $request = null): RequestEvent
353-
{
354-
$request = $request ?? new Request();
355-
356-
$event = $this->getMockBuilder(RequestEvent::class)
357-
->setConstructorArgs([$this->createMock(HttpKernelInterface::class), $request, HttpKernelInterface::MAIN_REQUEST])
358-
->getMock();
359-
$event
360-
->expects($this->any())
361-
->method('getRequest')
362-
->willReturn($request)
363-
;
364-
365-
return $event;
333+
$listener(new RequestEvent($this->createMock(HttpKernelInterface::class), new Request(), HttpKernelInterface::MAIN_REQUEST));
366334
}
367335

368336
protected function getListener($withDispatcher = false, $catchExceptions = true, $withSessionStrategy = false)

src/Symfony/Component/Security/Http/Tests/FirewallTest.php

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
1616
use Symfony\Component\HttpFoundation\Request;
17+
use Symfony\Component\HttpFoundation\Response;
1718
use Symfony\Component\HttpKernel\Event\RequestEvent;
1819
use Symfony\Component\HttpKernel\HttpKernelInterface;
1920
use Symfony\Component\Security\Http\Firewall;
@@ -68,20 +69,8 @@ public function testOnKernelRequestStopsWhenThereIsAResponse()
6869
->willReturn([[$first, $second], null, null])
6970
;
7071

71-
$event = $this->getMockBuilder(RequestEvent::class)
72-
->setMethods(['hasResponse'])
73-
->setConstructorArgs([
74-
$this->createMock(HttpKernelInterface::class),
75-
$this->createMock(Request::class),
76-
HttpKernelInterface::MAIN_REQUEST,
77-
])
78-
->getMock()
79-
;
80-
$event
81-
->expects($this->once())
82-
->method('hasResponse')
83-
->willReturn(true)
84-
;
72+
$event = new RequestEvent($this->createMock(HttpKernelInterface::class), new Request(), HttpKernelInterface::MAIN_REQUEST);
73+
$event->setResponse(new Response());
8574

8675
$firewall = new Firewall($map, $this->createMock(EventDispatcherInterface::class));
8776
$firewall->onKernelRequest($event);

src/Symfony/Component/Stopwatch/Tests/StopwatchTest.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,7 @@ public function testIsNotStartedEvent()
7171
$events = new \ReflectionProperty(Section::class, 'events');
7272
$events->setAccessible(true);
7373

74-
$stopwatchMockEvent = $this->getMockBuilder(StopwatchEvent::class)
75-
->setConstructorArgs([microtime(true) * 1000])
76-
->getMock()
77-
;
78-
79-
$events->setValue(end($section), ['foo' => $stopwatchMockEvent]);
74+
$events->setValue(end($section), ['foo' => new StopwatchEvent(microtime(true) * 1000)]);
8075

8176
$this->assertFalse($stopwatch->isStarted('foo'));
8277
}

0 commit comments

Comments
 (0)
0