Skip to content

Commit e4f316c

Browse files
OskarStarknicolas-grekas
authored andcommitted
[Tests] Streamline
1 parent 0416e8e commit e4f316c

File tree

6 files changed

+18
-13
lines changed

6 files changed

+18
-13
lines changed

Tests/Authentication/RememberMe/InMemoryTokenProviderTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ public function testCreateNewToken()
3131
public function testLoadTokenBySeriesThrowsNotFoundException()
3232
{
3333
$this->expectException(TokenNotFoundException::class);
34-
$provider = new InMemoryTokenProvider();
35-
$provider->loadTokenBySeries('foo');
34+
(new InMemoryTokenProvider())->loadTokenBySeries('foo');
3635
}
3736

3837
public function testUpdateToken()
@@ -50,12 +49,14 @@ public function testUpdateToken()
5049

5150
public function testDeleteToken()
5251
{
53-
$this->expectException(TokenNotFoundException::class);
5452
$provider = new InMemoryTokenProvider();
5553

5654
$token = new PersistentToken('foo', 'foo', 'foo', 'foo', new \DateTimeImmutable());
5755
$provider->createNewToken($token);
5856
$provider->deleteTokenBySeries('foo');
57+
58+
$this->expectException(TokenNotFoundException::class);
59+
5960
$provider->loadTokenBySeries('foo');
6061
}
6162
}

Tests/Authorization/Voter/VoterTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ public function testVoteWithTypeError()
6767
{
6868
$this->expectException(\TypeError::class);
6969
$this->expectExceptionMessage('Should error');
70-
$voter = new TypeErrorVoterTest_Voter();
71-
$voter->vote($this->token, new \stdClass(), ['EDIT']);
70+
(new TypeErrorVoterTest_Voter())->vote($this->token, new \stdClass(), ['EDIT']);
7271
}
7372
}
7473

Tests/User/ChainUserProviderTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ public function testLoadUserByIdentifier()
4747

4848
public function testLoadUserByIdentifierThrowsUserNotFoundException()
4949
{
50-
$this->expectException(UserNotFoundException::class);
5150
$provider1 = $this->createMock(InMemoryUserProvider::class);
5251
$provider1
5352
->expects($this->once())
@@ -65,6 +64,9 @@ public function testLoadUserByIdentifierThrowsUserNotFoundException()
6564
;
6665

6766
$provider = new ChainUserProvider([$provider1, $provider2]);
67+
68+
$this->expectException(UserNotFoundException::class);
69+
6870
$provider->loadUserByIdentifier('foo');
6971
}
7072

@@ -141,7 +143,6 @@ public function testRefreshUserAgain()
141143

142144
public function testRefreshUserThrowsUnsupportedUserException()
143145
{
144-
$this->expectException(UnsupportedUserException::class);
145146
$provider1 = $this->createMock(InMemoryUserProvider::class);
146147
$provider1
147148
->expects($this->once())
@@ -169,6 +170,9 @@ public function testRefreshUserThrowsUnsupportedUserException()
169170
;
170171

171172
$provider = new ChainUserProvider([$provider1, $provider2]);
173+
174+
$this->expectException(UnsupportedUserException::class);
175+
172176
$provider->refreshUser($this->createMock(UserInterface::class));
173177
}
174178

Tests/User/InMemoryUserCheckerTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ public function testCheckPostAuthPass()
3535
public function testCheckPreAuthDisabled()
3636
{
3737
$this->expectException(DisabledException::class);
38-
$checker = new InMemoryUserChecker();
39-
$checker->checkPreAuth(new InMemoryUser('John', 'password', [], false));
38+
(new InMemoryUserChecker())->checkPreAuth(new InMemoryUser('John', 'password', [], false));
4039
}
4140
}

Tests/User/InMemoryUserProviderTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,17 @@ public function testCreateUser()
6262

6363
public function testCreateUserAlreadyExist()
6464
{
65-
$this->expectException(\LogicException::class);
6665
$provider = new InMemoryUserProvider();
6766
$provider->createUser(new InMemoryUser('fabien', 'foo'));
67+
68+
$this->expectException(\LogicException::class);
69+
6870
$provider->createUser(new InMemoryUser('fabien', 'foo'));
6971
}
7072

7173
public function testLoadUserByIdentifierDoesNotExist()
7274
{
7375
$this->expectException(UserNotFoundException::class);
74-
$provider = new InMemoryUserProvider();
75-
$provider->loadUserByIdentifier('fabien');
76+
(new InMemoryUserProvider())->loadUserByIdentifier('fabien');
7677
}
7778
}

Tests/Validator/Constraints/UserPasswordValidatorTestCase.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,14 @@ public static function emptyPasswordData()
113113

114114
public function testUserIsNotValid()
115115
{
116-
$this->expectException(ConstraintDefinitionException::class);
117116
$user = new \stdClass();
118117

119118
$this->tokenStorage = $this->createTokenStorage($user);
120119
$this->validator = $this->createValidator();
121120
$this->validator->initialize($this->context);
122121

122+
$this->expectException(ConstraintDefinitionException::class);
123+
123124
$this->validator->validate('secret', new UserPassword());
124125
}
125126

0 commit comments

Comments
 (0)