Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8de7c8f

Browse files
committed
Use createMock
1 parent 5f7e436 commit 8de7c8f

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/Symfony/Component/Security/Http/Tests/EventListener/IsGrantedAttributeListenerTest.php

+12-12
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function testAttribute()
4444
$listener = new IsGrantedAttributeListener($authChecker);
4545
$listener->onKernelControllerArguments($event);
4646

47-
$authChecker = $this->getMockBuilder(AuthorizationCheckerInterface::class)->getMock();
47+
$authChecker = $this->createMock(AuthorizationCheckerInterface::class);
4848
$authChecker->expects($this->once())
4949
->method('isGranted')
5050
->willReturn(true);
@@ -63,7 +63,7 @@ public function testAttribute()
6363

6464
public function testNothingHappensWithNoConfig()
6565
{
66-
$authChecker = $this->getMockBuilder(AuthorizationCheckerInterface::class)->getMock();
66+
$authChecker = $this->createMock(AuthorizationCheckerInterface::class);
6767
$authChecker->expects($this->never())
6868
->method('isGranted');
6969

@@ -81,7 +81,7 @@ public function testNothingHappensWithNoConfig()
8181

8282
public function testIsGrantedCalledCorrectly()
8383
{
84-
$authChecker = $this->getMockBuilder(AuthorizationCheckerInterface::class)->getMock();
84+
$authChecker = $this->createMock(AuthorizationCheckerInterface::class);
8585
$authChecker->expects($this->once())
8686
->method('isGranted')
8787
->with('ROLE_ADMIN')
@@ -101,7 +101,7 @@ public function testIsGrantedCalledCorrectly()
101101

102102
public function testIsGrantedSubjectFromArguments()
103103
{
104-
$authChecker = $this->getMockBuilder(AuthorizationCheckerInterface::class)->getMock();
104+
$authChecker = $this->createMock(AuthorizationCheckerInterface::class);
105105
$authChecker->expects($this->once())
106106
->method('isGranted')
107107
// the subject => arg2name will eventually resolve to the 2nd argument, which has this value
@@ -148,7 +148,7 @@ public function testIsGrantedSubjectFromArgumentsWithArray()
148148

149149
public function testIsGrantedNullSubjectFromArguments()
150150
{
151-
$authChecker = $this->getMockBuilder(AuthorizationCheckerInterface::class)->getMock();
151+
$authChecker = $this->createMock(AuthorizationCheckerInterface::class);
152152
$authChecker->expects($this->once())
153153
->method('isGranted')
154154
->with('ROLE_ADMIN', null)
@@ -168,7 +168,7 @@ public function testIsGrantedNullSubjectFromArguments()
168168

169169
public function testIsGrantedArrayWithNullValueSubjectFromArguments()
170170
{
171-
$authChecker = $this->getMockBuilder(AuthorizationCheckerInterface::class)->getMock();
171+
$authChecker = $this->createMock(AuthorizationCheckerInterface::class);
172172
$authChecker->expects($this->once())
173173
->method('isGranted')
174174
->with('ROLE_ADMIN', [
@@ -193,7 +193,7 @@ public function testExceptionWhenMissingSubjectAttribute()
193193
{
194194
$this->expectException(\RuntimeException::class);
195195

196-
$authChecker = $this->getMockBuilder(AuthorizationCheckerInterface::class)->getMock();
196+
$authChecker = $this->createMock(AuthorizationCheckerInterface::class);
197197

198198
$event = new ControllerArgumentsEvent(
199199
$this->createMock(HttpKernelInterface::class),
@@ -212,12 +212,12 @@ public function testExceptionWhenMissingSubjectAttribute()
212212
*/
213213
public function testAccessDeniedMessages(array $attributes, ?string $subject, string $method, string $expectedMessage)
214214
{
215-
$authChecker = $this->getMockBuilder(AuthorizationCheckerInterface::class)->getMock();
215+
$authChecker = $this->createMock(AuthorizationCheckerInterface::class);
216216
$authChecker->expects($this->any())
217217
->method('isGranted')
218218
->willReturn(false);
219219

220-
$expressionLanguage = $this->getMockBuilder(ExpressionLanguage::class)->getMock();
220+
$expressionLanguage = $this->createMock(ExpressionLanguage::class);
221221
$expressionLanguage->expects($this->any())
222222
->method('evaluate')
223223
->willReturn('bar');
@@ -285,7 +285,7 @@ public function testNotFoundHttpException()
285285

286286
public function testIsGrantedwithExpressionInAttribute()
287287
{
288-
$authChecker = $this->getMockBuilder(AuthorizationCheckerInterface::class)->getMock();
288+
$authChecker = $this->createMock(AuthorizationCheckerInterface::class);
289289
$authChecker->expects($this->once())
290290
->method('isGranted')
291291
->with(new Expression('"ROLE_ADMIN" in role_names or is_granted("POST_VIEW", subject)'), 'post')
@@ -305,13 +305,13 @@ public function testIsGrantedwithExpressionInAttribute()
305305

306306
public function testIsGrantedwithExpressionInSubject()
307307
{
308-
$authChecker = $this->getMockBuilder(AuthorizationCheckerInterface::class)->getMock();
308+
$authChecker = $this->createMock(AuthorizationCheckerInterface::class);
309309
$authChecker->expects($this->once())
310310
->method('isGranted')
311311
->with(new Expression('user === subject'), 'author')
312312
->willReturn(true);
313313

314-
$expressionLanguage = $this->getMockBuilder(ExpressionLanguage::class)->getMock();
314+
$expressionLanguage = $this->createMock(ExpressionLanguage::class);
315315
$expressionLanguage->expects($this->once())
316316
->method('evaluate')
317317
->with(new Expression('args["post"].getAuthor()'), [

0 commit comments

Comments
 (0)