Skip to content

Commit b29c191

Browse files
committed
Merge branch '4.4' into 5.2
* 4.4: do not mock the Request class do not mock event classes recover from failed deserializations [ErrorHandle] Remove a link from the exception page [Validator] Added Ukrainian translations [GHA] Clarify some bits in the deps=high script
2 parents 3de5da6 + 9ef9b5f commit b29c191

7 files changed

+54
-190
lines changed

Tests/Firewall/AbstractPreAuthenticatedListenerTest.php

Lines changed: 6 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\HttpFoundation\Request;
1616
use Symfony\Component\HttpKernel\Event\RequestEvent;
17+
use Symfony\Component\HttpKernel\HttpKernelInterface;
1718
use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface;
1819
use Symfony\Component\Security\Core\Authentication\Token\PreAuthenticatedToken;
1920
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
@@ -62,14 +63,7 @@ public function testHandleWithValidValues()
6263
->method('getPreAuthenticatedData')
6364
->willReturn($userCredentials);
6465

65-
$event = $this->createMock(RequestEvent::class);
66-
$event
67-
->expects($this->any())
68-
->method('getRequest')
69-
->willReturn($request)
70-
;
71-
72-
$listener($event);
66+
$listener(new RequestEvent($this->createMock(HttpKernelInterface::class), $request, HttpKernelInterface::MASTER_REQUEST));
7367
}
7468

7569
public function testHandleWhenAuthenticationFails()
@@ -109,14 +103,7 @@ public function testHandleWhenAuthenticationFails()
109103
->method('getPreAuthenticatedData')
110104
->willReturn($userCredentials);
111105

112-
$event = $this->createMock(RequestEvent::class);
113-
$event
114-
->expects($this->any())
115-
->method('getRequest')
116-
->willReturn($request)
117-
;
118-
119-
$listener($event);
106+
$listener(new RequestEvent($this->createMock(HttpKernelInterface::class), $request, HttpKernelInterface::MASTER_REQUEST));
120107
}
121108

122109
public function testHandleWhenAuthenticationFailsWithDifferentToken()
@@ -158,12 +145,7 @@ public function testHandleWhenAuthenticationFailsWithDifferentToken()
158145
->method('getPreAuthenticatedData')
159146
->willReturn($userCredentials);
160147

161-
$event = $this->createMock(RequestEvent::class);
162-
$event
163-
->expects($this->any())
164-
->method('getRequest')
165-
->willReturn($request)
166-
;
148+
$event = new RequestEvent($this->createMock(HttpKernelInterface::class), $request, HttpKernelInterface::MASTER_REQUEST);
167149

168150
$listener($event);
169151
}
@@ -200,14 +182,7 @@ public function testHandleWithASimilarAuthenticatedToken()
200182
->method('getPreAuthenticatedData')
201183
->willReturn($userCredentials);
202184

203-
$event = $this->createMock(RequestEvent::class);
204-
$event
205-
->expects($this->any())
206-
->method('getRequest')
207-
->willReturn($request)
208-
;
209-
210-
$listener($event);
185+
$listener(new RequestEvent($this->createMock(HttpKernelInterface::class), $request, HttpKernelInterface::MASTER_REQUEST));
211186
}
212187

213188
public function testHandleWithAnInvalidSimilarToken()
@@ -250,13 +225,6 @@ public function testHandleWithAnInvalidSimilarToken()
250225
->method('getPreAuthenticatedData')
251226
->willReturn($userCredentials);
252227

253-
$event = $this->createMock(RequestEvent::class);
254-
$event
255-
->expects($this->any())
256-
->method('getRequest')
257-
->willReturn($request)
258-
;
259-
260-
$listener($event);
228+
$listener(new RequestEvent($this->createMock(HttpKernelInterface::class), $request, HttpKernelInterface::MASTER_REQUEST));
261229
}
262230
}

Tests/Firewall/BasicAuthenticationListenerTest.php

Lines changed: 10 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\HttpFoundation\Request;
1616
use Symfony\Component\HttpFoundation\Response;
1717
use Symfony\Component\HttpKernel\Event\RequestEvent;
18+
use Symfony\Component\HttpKernel\HttpKernelInterface;
1819
use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface;
1920
use Symfony\Component\Security\Core\Authentication\AuthenticationProviderManager;
2021
use Symfony\Component\Security\Core\Authentication\Provider\AuthenticationProviderInterface;
@@ -64,14 +65,7 @@ public function testHandleWithValidUsernameAndPasswordServerParameters()
6465
$this->createMock(AuthenticationEntryPointInterface::class)
6566
);
6667

67-
$event = $this->createMock(RequestEvent::class);
68-
$event
69-
->expects($this->any())
70-
->method('getRequest')
71-
->willReturn($request)
72-
;
73-
74-
$listener($event);
68+
$listener(new RequestEvent($this->createMock(HttpKernelInterface::class), $request, HttpKernelInterface::MASTER_REQUEST));
7569
}
7670

7771
public function testHandleWhenAuthenticationFails()
@@ -109,19 +103,11 @@ public function testHandleWhenAuthenticationFails()
109103
$authenticationEntryPoint
110104
);
111105

112-
$event = $this->createMock(RequestEvent::class);
113-
$event
114-
->expects($this->any())
115-
->method('getRequest')
116-
->willReturn($request)
117-
;
118-
$event
119-
->expects($this->once())
120-
->method('setResponse')
121-
->with($this->equalTo($response))
122-
;
106+
$event = new RequestEvent($this->createMock(HttpKernelInterface::class), $request, HttpKernelInterface::MASTER_REQUEST);
123107

124108
$listener($event);
109+
110+
$this->assertSame($response, $event->getResponse());
125111
}
126112

127113
public function testHandleWithNoUsernameServerParameter()
@@ -141,14 +127,7 @@ public function testHandleWithNoUsernameServerParameter()
141127
$this->createMock(AuthenticationEntryPointInterface::class)
142128
);
143129

144-
$event = $this->createMock(RequestEvent::class);
145-
$event
146-
->expects($this->any())
147-
->method('getRequest')
148-
->willReturn($request)
149-
;
150-
151-
$listener($event);
130+
$listener(new RequestEvent($this->createMock(HttpKernelInterface::class), $request, HttpKernelInterface::MASTER_REQUEST));
152131
}
153132

154133
public function testHandleWithASimilarAuthenticatedToken()
@@ -177,14 +156,7 @@ public function testHandleWithASimilarAuthenticatedToken()
177156
$this->createMock(AuthenticationEntryPointInterface::class)
178157
);
179158

180-
$event = $this->createMock(RequestEvent::class);
181-
$event
182-
->expects($this->any())
183-
->method('getRequest')
184-
->willReturn($request)
185-
;
186-
187-
$listener($event);
159+
$listener(new RequestEvent($this->createMock(HttpKernelInterface::class), $request, HttpKernelInterface::MASTER_REQUEST));
188160
}
189161

190162
public function testItRequiresProviderKey()
@@ -236,18 +208,10 @@ public function testHandleWithADifferentAuthenticatedToken()
236208
$authenticationEntryPoint
237209
);
238210

239-
$event = $this->createMock(RequestEvent::class);
240-
$event
241-
->expects($this->any())
242-
->method('getRequest')
243-
->willReturn($request)
244-
;
245-
$event
246-
->expects($this->once())
247-
->method('setResponse')
248-
->with($this->equalTo($response))
249-
;
211+
$event = new RequestEvent($this->createMock(HttpKernelInterface::class), $request, HttpKernelInterface::MASTER_REQUEST);
250212

251213
$listener($event);
214+
215+
$this->assertSame($response, $event->getResponse());
252216
}
253217
}

Tests/Firewall/ChannelListenerTest.php

Lines changed: 13 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\HttpFoundation\Request;
1616
use Symfony\Component\HttpFoundation\Response;
1717
use Symfony\Component\HttpKernel\Event\RequestEvent;
18+
use Symfony\Component\HttpKernel\HttpKernelInterface;
1819
use Symfony\Component\Security\Http\AccessMapInterface;
1920
use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface;
2021
use Symfony\Component\Security\Http\Firewall\ChannelListener;
@@ -44,19 +45,12 @@ public function testHandleWithNotSecuredRequestAndHttpChannel()
4445
->method('start')
4546
;
4647

47-
$event = $this->createMock(RequestEvent::class);
48-
$event
49-
->expects($this->any())
50-
->method('getRequest')
51-
->willReturn($request)
52-
;
53-
$event
54-
->expects($this->never())
55-
->method('setResponse')
56-
;
48+
$event = new RequestEvent($this->createMock(HttpKernelInterface::class), $request, HttpKernelInterface::MASTER_REQUEST);
5749

5850
$listener = new ChannelListener($accessMap, $entryPoint);
5951
$listener($event);
52+
53+
$this->assertNull($event->getResponse());
6054
}
6155

6256
public function testHandleWithSecuredRequestAndHttpsChannel()
@@ -82,19 +76,12 @@ public function testHandleWithSecuredRequestAndHttpsChannel()
8276
->method('start')
8377
;
8478

85-
$event = $this->createMock(RequestEvent::class);
86-
$event
87-
->expects($this->any())
88-
->method('getRequest')
89-
->willReturn($request)
90-
;
91-
$event
92-
->expects($this->never())
93-
->method('setResponse')
94-
;
79+
$event = new RequestEvent($this->createMock(HttpKernelInterface::class), $request, HttpKernelInterface::MASTER_REQUEST);
9580

9681
$listener = new ChannelListener($accessMap, $entryPoint);
9782
$listener($event);
83+
84+
$this->assertNull($event->getResponse());
9885
}
9986

10087
public function testHandleWithNotSecuredRequestAndHttpsChannel()
@@ -124,20 +111,12 @@ public function testHandleWithNotSecuredRequestAndHttpsChannel()
124111
->willReturn($response)
125112
;
126113

127-
$event = $this->createMock(RequestEvent::class);
128-
$event
129-
->expects($this->any())
130-
->method('getRequest')
131-
->willReturn($request)
132-
;
133-
$event
134-
->expects($this->once())
135-
->method('setResponse')
136-
->with($this->equalTo($response))
137-
;
114+
$event = new RequestEvent($this->createMock(HttpKernelInterface::class), $request, HttpKernelInterface::MASTER_REQUEST);
138115

139116
$listener = new ChannelListener($accessMap, $entryPoint);
140117
$listener($event);
118+
119+
$this->assertSame($response, $event->getResponse());
141120
}
142121

143122
public function testHandleWithSecuredRequestAndHttpChannel()
@@ -167,19 +146,11 @@ public function testHandleWithSecuredRequestAndHttpChannel()
167146
->willReturn($response)
168147
;
169148

170-
$event = $this->createMock(RequestEvent::class);
171-
$event
172-
->expects($this->any())
173-
->method('getRequest')
174-
->willReturn($request)
175-
;
176-
$event
177-
->expects($this->once())
178-
->method('setResponse')
179-
->with($this->equalTo($response))
180-
;
149+
$event = new RequestEvent($this->createMock(HttpKernelInterface::class), $request, HttpKernelInterface::MASTER_REQUEST);
181150

182151
$listener = new ChannelListener($accessMap, $entryPoint);
183152
$listener($event);
153+
154+
$this->assertSame($response, $event->getResponse());
184155
}
185156
}

Tests/Firewall/ContextListenerTest.php

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,9 @@ public function testOnKernelResponseWithoutSessionNorToken()
146146
public function testInvalidTokenInSession($token)
147147
{
148148
$tokenStorage = $this->createMock(TokenStorageInterface::class);
149-
$event = $this->createMock(RequestEvent::class);
150149
$request = $this->createMock(Request::class);
151150
$session = $this->createMock(SessionInterface::class);
152151

153-
$event->expects($this->any())
154-
->method('getRequest')
155-
->willReturn($request);
156152
$request->expects($this->any())
157153
->method('hasPreviousSession')
158154
->willReturn(true);
@@ -168,7 +164,7 @@ public function testInvalidTokenInSession($token)
168164
->with(null);
169165

170166
$listener = new ContextListener($tokenStorage, [], 'key123');
171-
$listener($event);
167+
$listener(new RequestEvent($this->createMock(HttpKernelInterface::class), $request, HttpKernelInterface::MASTER_REQUEST));
172168
}
173169

174170
public function provideInvalidToken()
@@ -186,22 +182,13 @@ public function testHandleAddsKernelResponseListener()
186182
{
187183
$tokenStorage = $this->createMock(TokenStorageInterface::class);
188184
$dispatcher = $this->createMock(EventDispatcherInterface::class);
189-
$event = $this->createMock(RequestEvent::class);
190-
191185
$listener = new ContextListener($tokenStorage, [], 'key123', null, $dispatcher);
192186

193-
$event->expects($this->any())
194-
->method('isMasterRequest')
195-
->willReturn(true);
196-
$event->expects($this->any())
197-
->method('getRequest')
198-
->willReturn($this->createMock(Request::class));
199-
200187
$dispatcher->expects($this->once())
201188
->method('addListener')
202189
->with(KernelEvents::RESPONSE, [$listener, 'onKernelResponse']);
203190

204-
$listener($event);
191+
$listener(new RequestEvent($this->createMock(HttpKernelInterface::class), new Request(), HttpKernelInterface::MASTER_REQUEST));
205192
}
206193

207194
public function testOnKernelResponseListenerRemovesItself()
@@ -234,14 +221,11 @@ public function testHandleRemovesTokenIfNoPreviousSessionWasFound()
234221
$request = $this->createMock(Request::class);
235222
$request->expects($this->any())->method('hasPreviousSession')->willReturn(false);
236223

237-
$event = $this->createMock(RequestEvent::class);
238-
$event->expects($this->any())->method('getRequest')->willReturn($request);
239-
240224
$tokenStorage = $this->createMock(TokenStorageInterface::class);
241225
$tokenStorage->expects($this->once())->method('setToken')->with(null);
242226

243227
$listener = new ContextListener($tokenStorage, [], 'key123');
244-
$listener($event);
228+
$listener(new RequestEvent($this->createMock(HttpKernelInterface::class), $request, HttpKernelInterface::MASTER_REQUEST));
245229
}
246230

247231
public function testIfTokenIsDeauthenticated()

0 commit comments

Comments
 (0)