Skip to content

Commit 745e811

Browse files
claudef3l1x
authored andcommitted
Tests: use Contributte\Tester
1 parent 27e550e commit 745e811

File tree

5 files changed

+20
-35
lines changed

5 files changed

+20
-35
lines changed

tests/.coveralls.yml

Lines changed: 0 additions & 4 deletions
This file was deleted.

tests/.gitignore

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,19 @@
77
require_once __DIR__ . '/../../bootstrap.php';
88

99
use Contributte\Security\Auth\DebugAuthenticator;
10+
use Contributte\Tester\Toolkit;
1011
use Nette\Security\AuthenticationException;
1112
use Nette\Security\IIdentity;
1213
use Tester\Assert;
1314

14-
// Optimistic
15-
test(function (): void {
15+
// Authenticate with pass=true returns identity
16+
Toolkit::test(function (): void {
1617
$auth = new DebugAuthenticator(true);
1718
Assert::type(IIdentity::class, $auth->authenticate('foo', 'bar'));
1819
});
1920

20-
// Pessimistic
21-
test(function (): void {
21+
// Authenticate with pass=false throws exception
22+
Toolkit::test(function (): void {
2223
Assert::exception(function (): void {
2324
$auth = new DebugAuthenticator(false);
2425
$auth->authenticate('', '');
Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,57 +7,58 @@
77
require_once __DIR__ . '/../../bootstrap.php';
88

99
use Contributte\Security\Auth\StaticAuthenticator;
10+
use Contributte\Tester\Toolkit;
1011
use Nette\Security\AuthenticationException;
1112
use Nette\Security\IIdentity;
1213
use Nette\Security\Passwords;
1314
use Tester\Assert;
1415

15-
// Success - hashed password
16-
test(function (): void {
16+
// Authenticate with hashed password
17+
Toolkit::test(function (): void {
1718
$hash = (new Passwords(PASSWORD_BCRYPT))->hash('foobar');
1819
$auth = new StaticAuthenticator([
1920
2021
'password' => $hash,
2122
],
22-
], (new Passwords(PASSWORD_BCRYPT)));
23+
], new Passwords(PASSWORD_BCRYPT));
2324

2425
Assert::type(IIdentity::class, $auth->authenticate('[email protected]', 'foobar'));
2526
});
2627

27-
// Success - plain password
28-
test(function (): void {
28+
// Authenticate with plain password (unsecured)
29+
Toolkit::test(function (): void {
2930
$auth = new StaticAuthenticator([
3031
3132
'password' => 'foobar',
3233
'unsecured' => true,
3334
],
34-
], (new Passwords(PASSWORD_BCRYPT)));
35+
], new Passwords(PASSWORD_BCRYPT));
3536

3637
Assert::type(IIdentity::class, $auth->authenticate('[email protected]', 'foobar'));
3738
});
3839

39-
// User not found
40-
test(function (): void {
40+
// Authenticate throws exception when user not found
41+
Toolkit::test(function (): void {
4142
$hash = (new Passwords(PASSWORD_BCRYPT))->hash('foobar');
4243
$auth = new StaticAuthenticator([
4344
4445
'password' => $hash,
4546
],
46-
], (new Passwords(PASSWORD_BCRYPT)));
47+
], new Passwords(PASSWORD_BCRYPT));
4748

4849
Assert::exception(function () use ($auth): void {
4950
$auth->authenticate('foo', 'bar');
5051
}, AuthenticationException::class, 'User `foo` not found');
5152
});
5253

53-
// Invalid password
54-
test(function (): void {
54+
// Authenticate throws exception on invalid password
55+
Toolkit::test(function (): void {
5556
$hash = (new Passwords(PASSWORD_BCRYPT))->hash('foobar');
5657
$auth = new StaticAuthenticator([
5758
5859
'password' => $hash,
5960
],
60-
], (new Passwords(PASSWORD_BCRYPT)));
61+
], new Passwords(PASSWORD_BCRYPT));
6162

6263
Assert::exception(function () use ($auth): void {
6364
$auth->authenticate('[email protected]', 'bar');

tests/bootstrap.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
<?php declare(strict_types = 1);
22

3-
use Ninjify\Nunjuck\Environment;
3+
use Contributte\Tester\Environment;
44

55
if (@!include __DIR__ . '/../vendor/autoload.php') {
66
echo 'Install Nette Tester using `composer update --dev`';
77
exit(1);
88
}
99

10-
// Configure environment
11-
Environment::setupTester();
12-
Environment::setupTimezone();
13-
Environment::setupVariables(__DIR__);
10+
Environment::setup(__DIR__);

0 commit comments

Comments
 (0)