10000 minor #29672 [Tests] Change to willThrowException (gmponos) · symfony/symfony@e1b35b4 · GitHub
[go: up one dir, main page]

Skip to content

Commit e1b35b4

Browse files
committed
minor #29672 [Tests] Change to willThrowException (gmponos)
This PR was submitted for the master branch but it was squashed and merged into the 3.4 branch instead (closes #29672). Discussion ---------- [Tests] Change to willThrowException | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | License | MIT Trivial changes of `will($this->throwException());` to `willThrowException();` Do you think it's worth it ti create a PR to change `->will($this->returnValue());` Commits ------- 0695834 [Tests] Change to willThrowException
2 parents 2437d70 + 0695834 commit e1b35b4

25 files changed

+52
-52
lines changed

src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationDebugCommandTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public function testDebugInvalidDirectory()
103103
$kernel->expects($this->once())
104104
->method('getBundle')
105105
->with($this->equalTo('dir'))
106-
->will($this->throwException(new \InvalidArgumentException()));
106+
->willThrowException(new \InvalidArgumentException());
107107

108108
$tester = $this->createCommandTester(array(), array(), $kernel);
109109
$tester->execute(array('locale' => 'en', 'bundle' => 'dir'));

src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Loader/TemplateLocatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function testThrowsExceptionWhenTemplateNotFound()
6060
$fileLocator
6161
->expects($this->once())
6262
->method('locate')
63-
->will($this->throwException(new \InvalidArgumentException($errorMessage)))
63+
->willThrowException(new \InvalidArgumentException($errorMessage))
6464
;
6565

6666
$locator = new TemplateLocator($fileLocator);

src/Symfony/Bundle/TwigBundle/Tests/Loader/FilesystemLoaderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function testTwigErrorIfLocatorThrowsInvalid()
6868
$locator
6969
->expects($this->once())
7070
->method('locate')
71-
->will($this->throwException(new \InvalidArgumentException('Unable 10000 to find template "NonExistent".')))
71+
->willThrowException(new \InvalidArgumentException('Unable to find template "NonExistent".'))
7272
;
7373

7474
$loader = new FilesystemLoader($locator, $parser);

src/Symfony/Bundle/WebProfilerBundle/Tests/EventListener/WebDebugToolbarListenerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ public function testThrowingUrlGenerator()
252252
->expects($this->once())
253253
->method('generate')
254254
->with('_profiler', array('token' => 'xxxxxxxx'))
255-
->will($this->throwException(new \Exception('foo')))
255+
->willThrowException(new \Exception('foo'))
256256
;
257257

258258
$event = new FilterResponseEvent($this->getKernelMock(), $this->getRequestMock(), HttpKernelInterface::MASTER_REQUEST, $response);
@@ -273,7 +273,7 @@ public function testThrowingErrorCleanup()
273273
->expects($this->once())
274274
->method('generate')
275275
->with('_profiler', array('token' => 'xxxxxxxx'))
276-
->will($this->throwException(new \Exception("This\nmultiline\r\ntabbed text should\tcome out\r on\n \ta single plain\r\nline")))
276+
->willThrowException(new \Exception("This\nmultiline\r\ntabbed text should\tcome out\r on\n \ta single plain\r\nline"))
277277
;
278278

279279
$event = new FilterResponseEvent($this->getKernelMock(), $this->getRequestMock(), HttpKernelInterface::MASTER_REQUEST, $response);

src/Symfony/Component/Console/Tests/ApplicationTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -919,7 +919,7 @@ public function testRunReturnsIntegerExitCode()
919919
$application->setAutoExit(false);
920920
$application->expects($this->once())
921921
->method('doRun')
922-
->will($this->throwException($exception));
922+
->willThrowException($exception);
923923

924924
$exitCode = $application->run(new ArrayInput(array()), new NullOutput());
925925

@@ -958,7 +958,7 @@ public function testRunReturnsExitCodeOneForExceptionCodeZero()
958958
$application->setAutoExit(false);
959959
$application->expects($this->once())
960960
->method('doRun')
961-
->will($this->throwException($exception));
961+
->willThrowException($exception);
962962

963963
$exitCode = $application->run(new ArrayInput(array()), new NullOutput());
964964

src/Symfony/Component/Form/Tests/SimpleFormTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ public function testNotSynchronizedIfViewReverseTransformationFailed()
629629
$transformer = $this->getDataTransformer();
630630
$transformer->expects($this->once())
631631
->method('reverseTransform')
632-
->will($this->throwException(new TransformationFailedException()));
632+
->willThrowException(new TransformationFailedException());
633633

634634
$form = $this->getBuilder()
635635
->addViewTransformer($transformer)
@@ -645,7 +645,7 @@ public function testNotSynchronizedIfModelReverseTransformationFailed()
645645
$transformer = $this->getDataTransformer();
646646
$transformer->expects($this->once())
647647
->method('reverseTransform')
648-
->will($this->throwException(new TransformationFailedException()));
648+
->willThrowException(new TransformationFailedException());
649649

650650
$form = $this->getBuilder()
651651
->addModelTransformer($transformer)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function testDefaultLocaleIsUsedOnExceptionsInOnKernelRequest()
4747
$this->translator
4848
->expects($this->at(0))
4949
->method('setLocale')
50-
->will($this->throwException(new \InvalidArgumentException()));
50+
->willThrowException(new \InvalidArgumentException());
5151
$this->translator
5252
->expects($this->at(1))
5353
->method('setLocale')
@@ -84,7 +84,7 @@ public function testDefaultLocaleIsUsedOnExceptionsInOnKernelFinishRequest()
8484
$this->translator
8585
->expects($this->at(0))
8686
->method('setLocale')
87-
->will($this->throwException(new \InvalidArgumentException()));
87+
->willThrowException(new \InvalidArgumentException());
8888
$this->translator
8989
->expects($this->at(1))
9090
->method('setLocale')

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function testRenderWithDefaultText()
8080
$engine->expects($this->once())
8181
->method('exists')
8282
->with('default')
83-
->will($this->throwException(new \InvalidArgumentException()));
83+
->willThrowException(new \InvalidArgumentException());
8484

8585
// only default
8686
$strategy = new HIncludeFragmentRenderer($engine);
@@ -93,7 +93,7 @@ public function testRenderWithEngineAndDefaultText()
9393
$engine->expects($this->once())
9494
->method('exists')
9595
->with('loading...')
96-
->will($this->throwException(new \RuntimeException()));
96+
->willThrowException(new \RuntimeException());
9797

9898
// only default
9999
$strategy = new HIncludeFragmentRenderer($engine);

src/Symfony/Component/Intl/Tests/Data/Bundle/Reader/BundleEntryReaderTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public function testFallbackIfLocaleDoesNotExist()
148148
$this->readerImpl->expects($this->at(0))
149149
->method('read')
150150
->with(self::RES_DIR, 'en_GB')
151-
->will($this->throwException(new ResourceBundleNotFoundException()));
151+
->willThrowException(new ResourceBundleNotFoundException());
152152

153153
$this->readerImpl->expects($this->at(1))
154154
->method('read')
@@ -166,7 +166,7 @@ public function testDontFallbackIfLocaleDoesNotExistAndFallbackDisabled()
166166
$this->readerImpl->expects($this->once())
167167
->method('read')
168168
->with(self::RES_DIR, 'en_GB')
169-
->will($this->throwException(new ResourceBundleNotFoundException()));
169+
->willThrowException(new ResourceBundleNotFoundException());
170170

171171
$this->reader->readEntry(self::RES_DIR, 'en_GB', array('Entries', 'Bam'), false);
172172
}

src/Symfony/Component/Security/Core/Tests/Authentication/AuthenticationProviderManagerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ protected function getAuthenticationProvider($supports, $token = null, $exceptio
188188
} elseif (null !== $exception) {
189189
$provider->expects($this->once())
190190
->method('authenticate')
191-
->will($this->throwException($this->getMockBuilder($exception)->setMethods(null)->getMock()))
191+
->willThrowException($this->getMockBuilder($exception)->setMethods(null)->getMock())
192192
;
193193
}
194194

src/Symfony/Component/Security/Core/Tests/Authentication/Provider/DaoAuthenticationProviderTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function testRetrieveUserWhenUsernameIsNotFound()
3838
$userProvider = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\User\\UserProviderInterface')->getMock();
3939
$userProvider->expects($this->once())
4040
->method('loadUserByUsername')
41-
->will($this->throwException(new UsernameNotFoundException()))
41+
->willThrowException(new UsernameNotFoundException())
4242
;
4343

4444
$provider = new DaoAuthenticationProvider($userProvider, $this->getMockBuilder('Symfony\\Component\\Security\\Core\\User\\UserCheckerInterface')->getMock(), 'key', $this->getMockBuilder('Symfony\\Component\\Security\\Core\\Encoder\\EncoderFactoryInterface')->getMock());
@@ -56,7 +56,7 @@ public function testRetrieveUserWhenAnExceptionOccurs()
5656
$userProvider = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\User\\UserProviderInterface')->getMock();
5757
$userProvider->expects($this->once())
5858
->method('loadUserByUsername')
59-
->will($this->throwException(new \RuntimeException()))
59+
->willThrowException(new \RuntimeException())
6060
;
6161

6262
$provider = new DaoAuthenticationProvider($userProvider, $this->getMockBuilder('Symfony\\Component\\Security\\Core\\User\\UserCheckerInterface')->getMock(), 'key', $this->getMockBuilder('Symfony\\Component\\Security\\Core\\Encoder\\EncoderFactoryInterface')->getMock());

src/Symfony/Component/Security/Core/Tests/Authentication/Provider/LdapBindAuthenticationProviderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function testBindFailureShouldThrowAnException()
7373
$ldap
7474
->expects($this->once())
7575
->method('bind')
76-
->will($this->throwException(new ConnectionException()))
76+
->willThrowException(new ConnectionException())
7777
;
7878
$userChecker = $this->getMockBuilder(UserCheckerInterface::class)->getMock();
7979

src/Symfony/Component/Security/Core/Tests/Authentication/Provider/PreAuthenticatedAuthenticationProviderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public function testAuthenticateWhenUserCheckerThrowsException()
8585
$userChecker = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserCheckerInterface')->getMock();
8686
$userChecker->expects($this->once())
8787
->method('checkPostAuth')
88-
->will($this->throwException(new LockedException()))
88+
->willThrowException(new LockedException())
8989
;
9090

9191
$provider = $this->getProvider($user, $userChecker);

src/Symfony/Component/Security/Core/Tests/Authentication/Provider/RememberMeAuthenticationProviderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function testAuthenticateWhenPreChecksFails()
5757
$userChecker = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserCheckerInterface')->getMock();
5858
$userChecker->expects($this->once())
5959
->method('checkPreAuth')
< 10000 /code>
60-
->will($this->throwException(new DisabledException()));
60+
->willThrowException(new DisabledException());
6161

6262
$provider = $this->getProvider($userChecker);
6363

src/Symfony/Component/Security/Core/Tests/Authentication/Provider/SimpleAuthenticationProviderTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function testAuthenticateWhenPreChecksFails()
3434
$userChecker = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserCheckerInterface')->getMock();
3535
$userChecker->expects($this->once())
3636
->method('checkPreAuth')
37-
->will($this->throwException(new DisabledException()));
37+
->willThrowException(new DisabledException());
3838

3939
$authenticator = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\SimpleAuthenticatorInterface')->getMock();
4040
$authenticator->expects($this->once())
@@ -61,7 +61,7 @@ public function testAuthenticateWhenPostChecksFails()
6161
$userChecker = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserCheckerInterface')->getMock();
6262
$userChecker->expects($this->once())
6363
->method('checkPostAuth')
64-
->will($this->throwException(new LockedException()));
64+
->willThrowException(new LockedException());
6565

6666
$authenticator = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\SimpleAuthenticatorInterface')->getMock();
6767
$authenticator->expects($this->once())

src/Symfony/Component/Security/Core/Tests/Authentication/Provider/UserAuthenticationProviderTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function testAuthenticateWhenUsernameIsNotFound()
4848
$provider = $this->getProvider(false, false);
4949
$provider->expects($this->once())
5050
->method('retrieveUser')
51-
->will($this->throwException(new UsernameNotFoundException()))
51+
->willThrowException(new UsernameNotFoundException())
5252
;
5353

5454
$provider->authenticate($this->getSupportedToken());
@@ -62,7 +62,7 @@ public function testAuthenticateWhenUsernameIsNotFoundAndHideIsTrue()
6262
$provider = $this->getProvider(false, true);
6363
$provider->expects($this->once())
6464
->method('retrieveUser')
65-
->will($this->throwException(new UsernameNotFoundException()))
65+
->willThrowException(new UsernameNotFoundException())
6666
;
6767

6868
$provider->authenticate($this->getSupportedToken());
@@ -90,7 +90,7 @@ public function testAuthenticateWhenPreChecksFails()
9090
$userChecker = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserCheckerInterface')->getMock();
9191
$userChecker->expects($this->once())
9292
->method('checkPreAuth')
93-
->will($this->throwException(new CredentialsExpiredException()))
93+
->willThrowException(new CredentialsExpiredException())
9494
;
9595

9696
$provider = $this->getProvider($userChecker);
@@ -110,7 +110,7 @@ public function testAuthenticateWhenPostChecksFails()
110110
$userChecker = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserCheckerInterface')->getMock();
111111
$userChecker->expects($this->once())
112112
->method('checkPostAuth')
113-
->will($this->throwException(new AccountExpiredException()))
113+
->willThrowException(new AccountExpiredException())
114114
;
115115

116116
$provider = $this->getProvider($userChecker);
@@ -135,7 +135,7 @@ public function testAuthenticateWhenPostCheckAuthenticationFails()
135135
;
136136
$provider->expects($this->once())
137137
->method('checkAuthentication')
138-
->will($this->throwException(new BadCredentialsException()))
138+
->willThrowException(new BadCredentialsException())
139139
;
140140

141141
$provider->authenticate($this->getSupportedToken());
@@ -154,7 +154,7 @@ public function testAuthenticateWhenPostCheckAuthenticationFailsWithHideFalse()
154154
;
155155
$provider->expects($this->once())
156156
->method('checkAuthentication')
157-
->will($this->throwException(new BadCredentialsException('Foo')))
157+
->willThrowException(new BadCredentialsException('Foo'))
158158
;
159159

160160
$provider->authenticate($this->getSupportedToken());

src/Symfony/Component/Security/Core/Tests/User/ChainUserProviderTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function testLoadUserByUsername()
2525
->expects($this->once())
2626
->method('loadUserByUsername')
2727
->with($this->equalTo('foo'))
28-
->will($this->throwException(new UsernameNotFoundException('not found')))
28+
->willThrowException(new UsernameNotFoundException('not found'))
2929
;
3030

3131
$provider2 = $this->getProvider();
@@ -50,15 +50,15 @@ public function testLoadUserByUsernameThrowsUsernameNotFoundException()
5050
->expects($this->once())
5151
->method('loadUserByUsername')
5252
->with($this->equalTo('foo'))
53-
->will($this->throwException(new UsernameNotFoundException('not found')))
53+
->willThrowException(new UsernameNotFoundException('not found'))
5454
;
5555

5656
$provider2 = $this->getProvider();
5757
$provider2
5858
->expects($this->once())
5959
->method('loadUserByUsername')
6060
->with($this->equalTo('foo'))
61-
->will($this->throwException(new UsernameNotFoundException('not found')))
61+
->willThrowException(new UsernameNotFoundException('not found'))
6262
;
6363

6464
$provider = new ChainUserProvider(array($provider1, $provider2));
@@ -71,7 +71,7 @@ public function testRefreshUser()
7171
$provider1
7272
->expects($this->once())
7373
->method('refreshUser')
74-
->will($this->throwException(new UnsupportedUserException('unsupported')))
74+
->willThrowException(new UnsupportedUserException('unsupported'))
7575
;
7676

7777
$provider2 = $this->getProvider();
@@ -91,7 +91,7 @@ public function testRefreshUserAgain()
9191
$provider1
9292
->expects($this->once())
9393
->method('refreshUser')
94-
->will($this->throwException(new UsernameNotFoundException('not found')))
94+
->willThrowException(new UsernameNotFoundException('not found'))
9595
;
9696

9797
$provider2 = $this->getProvider();
@@ -114,14 +114,14 @@ public function testRefreshUserThrowsUnsupportedUserException()
114114
$provider1
115115
->expects($this->once())
116116
->method('refreshUser')
117-
->will($this->throwException(new UnsupportedUserException('unsupported')))
117+
->willThrowException(new UnsupportedUserException('unsupported'))
118118
;
119119

120120
$provider2 = $this->getProvider();
121121
$provider2
122122
->expects($this->once())
123123
->method('refreshUser')
124-
->will($this->throwException(new UnsupportedUserException('unsupported')))
124+
->willThrowException(new UnsupportedUserException('unsupported'))
125125
;
126126

127127
$provider = new ChainUserProvider(array($provider1, $provider2));
@@ -178,7 +178,7 @@ public function testAcceptsTraversable()
178178
$provider1
179179
->expects($this->once())
180180
->method('refreshUser')
181-
->will($this->throwException(new UnsupportedUserException('unsupported')))
181+
->willThrowException(new UnsupportedUserException('unsupported'))
182182
;
183183

184184
$provider2 = $this->getProvider();

src/Symfony/Component/Security/Core/Tests/User/LdapUserProviderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function testLoadUserByUsernameFailsIfCantConnectToLdap()
3333
$ldap
3434
->expects($this->once())
3535
->method('bind')
36-
->will($this->throwException(new ConnectionException()))
36+
->willThrowException(new ConnectionException())
3737
;
3838

3939
$provider = new LdapUserProvider($ldap, 'ou=MyBusiness,dc=symfony,dc=com');

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public function testHandleCatchesAuthenticationException()
185185
$authenticator
186186
->expects($this->once())
187187
->method('getCredentials')
188-
->will($this->throwException($authException));
188+
->willThrowException($authException);
189189

190190
// this is not called
191191
$this->authenticationManager

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function testHandleWhenAuthenticationFails()
9090
->expects($this->once())
9191
->method('authenticate')
9292
->with($this->isInstanceOf('Symfony\Component\Security\Core\Authentication\Token\PreAuthenticatedToken'))
93-
->will($this->throwException($exception))
93+
->willThrowException($exception)
9494
;
9595

9696
$listener = $this->getMockForAbstractClass('Symfony\Component\Security\Http\Firewall\AbstractPreAuthenticatedListener', array(
@@ -138,7 +138,7 @@ public function testHandleWhenAuthenticationFailsWithDifferentToken()
138138
->expects($this->once())
139139
->method('authenticate')
140140
->with($this->isInstanceOf('Symfony\Component\Security\Core\Authentication\Token\PreAuthenticatedToken'))
141-
->will($this->throwException($exception))
141+
->willThrowException($exception)
142142
;
143143

144144
$listener = $this->getMockForAbstractClass('Symfony\Component\Security\Http\Firewall\AbstractPreAuthenticatedListener', array(
@@ -228,7 +228,7 @@ public function testHandleWithAnInvalidSimilarToken()
228228
->expects($this->once())
229229
->method('authenticate')
230230
->with($this->isInstanceOf('Symfony\Component\Security\Core\Authentication\Token\PreAuthenticatedToken'))
231-
->will($this->throwException($exception))
231+
->willThrowException($exception)
232232
;
233233

234234
$listener = $this->getMockForAbstractClass('Symfony\Component\Security\Http\Firewall\AbstractPreAuthenticatedListener', array(

0 commit comments

Comments
 (0)
0