File tree Expand file tree Collapse file tree 2 files changed +13
-3
lines changed Expand file tree Collapse file tree 2 files changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -19,13 +19,18 @@ public function registerUser(string $email): bool {
19
19
return true ;
20
20
}
21
21
22
- private function getUserRole (): string
22
+ private function test (): string
23
+ {
24
+ return "guest " ;
25
+ }
26
+
27
+ public function getUserRole (): string
23
28
{
24
29
return "guest " ;
25
30
}
26
31
27
32
final public function getUserType (): string
28
33
{
29
- return $ this -> getUserRole () ;
34
+ return " guest " ;
30
35
}
31
36
}
Original file line number Diff line number Diff line change 17
17
18
18
$ config = TestConfig::make ()->withName ("unitary " );
19
19
20
-
21
20
$ unit ->group ($ config ->withSubject ("Can not mock final or private " ), function (TestCase $ case ) {
22
21
$ user = $ case ->mock (UserService::class, function (MethodRegistry $ method ) {
23
22
$ method ->method ("getUserRole " )->willReturn ("admin " );
24
23
$ method ->method ("getUserType " )->willReturn ("admin " );
25
24
});
26
25
26
+ // You cannot mock final with data (should return a warning)
27
27
$ case ->validate ($ user ->getUserType (), function (Expect $ expect ) {
28
28
$ expect ->isEqualTo ("guest " );
29
29
});
30
+
31
+ // You can of course mock regular methods with data
32
+ $ case ->validate ($ user ->getUserRole (), function (Expect $ expect ) {
33
+ $ expect ->isEqualTo ("admin " );
34
+ });
30
35
});
31
36
32
37
$ unit ->group ($ config ->withSubject ("Test mocker " ), function (TestCase $ case ) use ($ unit ) {
You can’t perform that action at this time.
0 commit comments