Skip to content

Commit b4d9456

Browse files
committed
coding style: reformatted Assert::exception
1 parent 4a2aab5 commit b4d9456

18 files changed

+133
-88
lines changed

tests/Security.Http/CookieStorage.authentication.phpt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ require __DIR__ . '/../bootstrap.php';
1212
$request = new Nette\Http\Request(new Nette\Http\UrlScript);
1313
$response = Mockery::mock(Nette\Http\IResponse::class);
1414
$storage = new CookieStorage($request, $response);
15-
Assert::exception(function () use ($storage) {
16-
$storage->saveAuthentication(new SimpleIdentity('short'));
17-
}, LogicException::class);
15+
Assert::exception(
16+
fn() => $storage->saveAuthentication(new SimpleIdentity('short')),
17+
LogicException::class,
18+
);
1819

1920
// correct id
2021
$id = '123456789123456';

tests/Security/Passwords.hash().phpt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,13 @@ Assert::truthy(
2424
$hash = (new Passwords(PASSWORD_BCRYPT))->hash('dg');
2525
Assert::same($hash, crypt('dg', $hash));
2626

27-
Assert::exception(function () {
28-
(new Passwords(PASSWORD_BCRYPT, ['cost' => 3]))->hash('dg');
29-
}, PHP_VERSION_ID < 80000 ? Nette\InvalidStateException::class : ValueError::class);
27+
Assert::exception(
28+
fn() => (new Passwords(PASSWORD_BCRYPT, ['cost' => 3]))->hash('dg'),
29+
PHP_VERSION_ID < 80000 ? Nette\InvalidStateException::class : ValueError::class,
30+
);
3031

31-
Assert::exception(function () {
32-
(new Passwords)->hash('');
33-
}, Nette\InvalidArgumentException::class, 'Password can not be empty.');
32+
Assert::exception(
33+
fn() => (new Passwords)->hash(''),
34+
Nette\InvalidArgumentException::class,
35+
'Password can not be empty.',
36+
);

tests/Security/Permission.IsAllowedNonExistent.phpt

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,16 @@ use Tester\Assert;
1313
require __DIR__ . '/../bootstrap.php';
1414

1515

16-
Assert::exception(function () {
17-
$acl = new Permission;
18-
$acl->isAllowed('nonexistent');
19-
}, Nette\InvalidStateException::class, "Role 'nonexistent' does not exist.");
20-
21-
Assert::exception(function () {
22-
$acl = new Permission;
23-
$acl->isAllowed(null, 'nonexistent');
24-
}, Nette\InvalidStateException::class, "Resource 'nonexistent' does not exist.");
16+
$acl = new Permission;
17+
Assert::exception(
18+
fn() => $acl->isAllowed('nonexistent'),
19+
Nette\InvalidStateException::class,
20+
"Role 'nonexistent' does not exist.",
21+
);
22+
23+
$acl = new Permission;
24+
Assert::exception(
25+
fn() => $acl->isAllowed(null, 'nonexistent'),
26+
Nette\InvalidStateException::class,
27+
"Resource 'nonexistent' does not exist.",
28+
);

tests/Security/Permission.ResourceAddInheritsNonExistent.phpt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ require __DIR__ . '/../bootstrap.php';
1414

1515

1616
$acl = new Permission;
17-
Assert::exception(function () use ($acl) {
18-
$acl->addResource('area', 'nonexistent');
19-
}, Nette\InvalidStateException::class, "Resource 'nonexistent' does not exist.");
17+
Assert::exception(
18+
fn() => $acl->addResource('area', 'nonexistent'),
19+
Nette\InvalidStateException::class,
20+
"Resource 'nonexistent' does not exist.",
21+
);

tests/Security/Permission.ResourceDuplicate.phpt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ use Tester\Assert;
1313
require __DIR__ . '/../bootstrap.php';
1414

1515

16-
Assert::exception(function () {
17-
$acl = new Permission;
18-
$acl->addResource('area');
19-
$acl->addResource('area');
20-
}, Nette\InvalidStateException::class, "Resource 'area' already exists in the list.");
16+
$acl = new Permission;
17+
$acl->addResource('area');
18+
Assert::exception(
19+
fn() => $acl->addResource('area'),
20+
Nette\InvalidStateException::class,
21+
"Resource 'area' already exists in the list.",
22+
);

tests/Security/Permission.ResourceInheritsNonExistent.phpt

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,14 @@ require __DIR__ . '/../bootstrap.php';
1515

1616
$acl = new Permission;
1717
$acl->addResource('area');
18-
Assert::exception(function () use ($acl) {
19-
$acl->resourceInheritsFrom('nonexistent', 'area');
20-
}, Nette\InvalidStateException::class, "Resource 'nonexistent' does not exist.");
21-
22-
Assert::exception(function () use ($acl) {
23-
$acl->resourceInheritsFrom('area', 'nonexistent');
24-
}, Nette\InvalidStateException::class, "Resource 'nonexistent' does not exist.");
18+
Assert::exception(
19+
fn() => $acl->resourceInheritsFrom('nonexistent', 'area'),
20+
Nette\InvalidStateException::class,
21+
"Resource 'nonexistent' does not exist.",
22+
);
23+
24+
Assert::exception(
25+
fn() => $acl->resourceInheritsFrom('area', 'nonexistent'),
26+
Nette\InvalidStateException::class,
27+
"Resource 'nonexistent' does not exist.",
28+
);

tests/Security/Permission.ResourceRemoveOneNonExistent.phpt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ require __DIR__ . '/../bootstrap.php';
1414

1515

1616
$acl = new Permission;
17-
Assert::exception(function () use ($acl) {
18-
$acl->removeResource('nonexistent');
19-
}, Nette\InvalidStateException::class, "Resource 'nonexistent' does not exist.");
17+
Assert::exception(
18+
fn() => $acl->removeResource('nonexistent'),
19+
Nette\InvalidStateException::class,
20+
"Resource 'nonexistent' does not exist.",
21+
);

tests/Security/Permission.RoleRegistryAddInheritsNonExistent.phpt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ require __DIR__ . '/../bootstrap.php';
1414

1515

1616
$acl = new Permission;
17-
Assert::exception(function () use ($acl) {
18-
$acl->addRole('guest', 'nonexistent');
19-
}, Nette\InvalidStateException::class, "Role 'nonexistent' does not exist.");
17+
Assert::exception(
18+
fn() => $acl->addRole('guest', 'nonexistent'),
19+
Nette\InvalidStateException::class,
20+
"Role 'nonexistent' does not exist.",
21+
);

tests/Security/Permission.RoleRegistryDuplicate.phpt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ require __DIR__ . '/../bootstrap.php';
1414

1515

1616
$acl = new Permission;
17-
Assert::exception(function () use ($acl) {
18-
$acl->addRole('guest');
19-
$acl->addRole('guest');
20-
}, Nette\InvalidStateException::class, "Role 'guest' already exists in the list.");
17+
$acl->addRole('guest');
18+
Assert::exception(
19+
fn() => $acl->addRole('guest'),
20+
Nette\InvalidStateException::class,
21+
"Role 'guest' already exists in the list.",
22+
);

tests/Security/Permission.RoleRegistryInheritsNonExistent.phpt

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,14 @@ require __DIR__ . '/../bootstrap.php';
1515

1616
$acl = new Permission;
1717
$acl->addRole('guest');
18-
Assert::exception(function () use ($acl) {
19-
$acl->roleInheritsFrom('nonexistent', 'guest');
20-
}, Nette\InvalidStateException::class, "Role 'nonexistent' does not exist.");
21-
22-
Assert::exception(function () use ($acl) {
23-
$acl->roleInheritsFrom('guest', 'nonexistent');
24-
}, Nette\InvalidStateException::class, "Role 'nonexistent' does not exist.");
18+
Assert::exception(
19+
fn() => $acl->roleInheritsFrom('nonexistent', 'guest'),
20+
Nette\InvalidStateException::class,
21+
"Role 'nonexistent' does not exist.",
22+
);
23+
24+
Assert::exception(
25+
fn() => $acl->roleInheritsFrom('guest', 'nonexistent'),
26+
Nette\InvalidStateException::class,
27+
"Role 'nonexistent' does not exist.",
28+
);

0 commit comments

Comments
 (0)