@@ -19,6 +19,13 @@ public function setAssignments()
19
19
}
20
20
}
21
21
22
+ /**
23
+ * Check the $userId has exactly $allowedPermissions and no more.
24
+ *
25
+ * @param string $userId
26
+ * @param string[] $allowedPermissions
27
+ * @return void
28
+ */
22
29
public function assertAccesses ($ userId , array $ allowedPermissions )
23
30
{
24
31
$ deniedPermissions = array_diff ($ this ->getAllPermissions (), $ allowedPermissions );
@@ -27,15 +34,29 @@ public function assertAccesses($userId, array $allowedPermissions)
27
34
$ this ->assertAccess ($ userId , false , $ deniedPermissions );
28
35
}
29
36
30
- public function assertAccess ($ userId , $ isAllowed , array $ permissions )
37
+ /**
38
+ * @param string $userId
39
+ * @param bool $isAllowed whether the passed permissions should be allowed or denied
40
+ * @param string[] $permissions
41
+ */
42
+ public function assertAccess ($ userId , $ isAllowed , array $ permissions ): void
31
43
{
44
+ $ wrongPermissions = [];
32
45
foreach ($ permissions as $ permission ) {
33
46
$ checked = $ this ->auth ->checkAccess ($ userId , $ permission );
34
47
if ($ checked !== $ isAllowed ) {
35
- var_dump ( compact ( ' userId ' , ' isAllowed ' , ' permission ' )) ;
48
+ $ wrongPermissions [] = $ permission ;
36
49
}
37
- $ this ->assertSame ($ isAllowed , $ checked );
38
50
}
51
+
52
+ $ message = sprintf (
53
+ "The following permissions for user '%s' should be %s, but they are %s instead: \n\n %s " ,
54
+ $ userId ,
55
+ $ isAllowed ? 'allowed ' : 'denied ' ,
56
+ $ isAllowed ? 'denied ' : 'allowed ' ,
57
+ var_export ($ wrongPermissions , true )
58
+ );
59
+ $ this ->assertEmpty ($ wrongPermissions , $ message );
39
60
}
40
61
41
62
protected $ allPermissions ;
0 commit comments