Skip to content

Commit b8386cb

Browse files
committed
Fix the test expectation for the user providers
1 parent 94d688e commit b8386cb

3 files changed

Lines changed: 28 additions & 5 deletions

File tree

Tests/Security/EmailProviderTest.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use PHPUnit\Framework\TestCase;
1616
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
1717
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
18+
use Symfony\Component\Security\Core\Exception\UserNotFoundException;
1819

1920
class EmailProviderTest extends TestCase
2021
{
@@ -47,7 +48,11 @@ public function testLoadUserByUsername()
4748

4849
public function testLoadUserByInvalidUsername()
4950
{
50-
$this->expectException(UsernameNotFoundException::class);
51+
if (class_exists(UserNotFoundException::class)) {
52+
$this->expectException(UserNotFoundException::class);
53+
} else {
54+
$this->expectException(UsernameNotFoundException::class);
55+
}
5156

5257
$this->userManager->expects($this->once())
5358
->method('findUserByEmail')
@@ -82,7 +87,11 @@ public function testRefreshUserBy()
8287

8388
public function testRefreshDeleted()
8489
{
85-
$this->expectException(UsernameNotFoundException::class);
90+
if (class_exists(UserNotFoundException::class)) {
91+
$this->expectException(UserNotFoundException::class);
92+
} else {
93+
$this->expectException(UsernameNotFoundException::class);
94+
}
8695

8796
$user = $this->getMockForAbstractClass('FOS\UserBundle\Model\User');
8897
$this->userManager->expects($this->once())

Tests/Security/EmailUserProviderTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use PHPUnit\Framework\TestCase;
1616
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
1717
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
18+
use Symfony\Component\Security\Core\Exception\UserNotFoundException;
1819

1920
class EmailUserProviderTest extends TestCase
2021
{
@@ -47,7 +48,11 @@ public function testLoadUserByUsername()
4748

4849
public function testLoadUserByInvalidUsername()
4950
{
50-
$this->expectException(UsernameNotFoundException::class);
51+
if (class_exists(UserNotFoundException::class)) {
52+
$this->expectException(UserNotFoundException::class);
53+
} else {
54+
$this->expectException(UsernameNotFoundException::class);
55+
}
5156

5257
$this->userManager->expects($this->once())
5358
->method('findUserByUsernameOrEmail')

Tests/Security/UserProviderTest.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use PHPUnit\Framework\TestCase;
1616
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
1717
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
18+
use Symfony\Component\Security\Core\Exception\UserNotFoundException;
1819

1920
class UserProviderTest extends TestCase
2021
{
@@ -47,7 +48,11 @@ public function testLoadUserByUsername()
4748

4849
public function testLoadUserByInvalidUsername()
4950
{
50-
$this->expectException(UsernameNotFoundException::class);
51+
if (class_exists(UserNotFoundException::class)) {
52+
$this->expectException(UserNotFoundException::class);
53+
} else {
54+
$this->expectException(UsernameNotFoundException::class);
55+
}
5156

5257
$this->userManager->expects($this->once())
5358
->method('findUserByUsername')
@@ -82,7 +87,11 @@ public function testRefreshUserBy()
8287

8388
public function testRefreshDeleted()
8489
{
85-
$this->expectException(UsernameNotFoundException::class);
90+
if (class_exists(UserNotFoundException::class)) {
91+
$this->expectException(UserNotFoundException::class);
92+
} else {
93+
$this->expectException(UsernameNotFoundException::class);
94+
}
8695

8796
$user = $this->getMockForAbstractClass('FOS\UserBundle\Model\User');
8897
$this->userManager->expects($this->once())

0 commit comments

Comments
 (0)