Skip to content

Commit 364bc20

Browse files
committed
Adjust test
1 parent 66a2003 commit 364bc20

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

tests/TestLib/UserService.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,18 @@ public function registerUser(string $email): bool {
1919
return true;
2020
}
2121

22-
private function getUserRole(): string
22+
private function test(): string
23+
{
24+
return "guest";
25+
}
26+
27+
public function getUserRole(): string
2328
{
2429
return "guest";
2530
}
2631

2732
final public function getUserType(): string
2833
{
29-
return $this->getUserRole();
34+
return "guest";
3035
}
3136
}

tests/unitary-unitary.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,21 @@
1717

1818
$config = TestConfig::make()->withName("unitary");
1919

20-
2120
$unit->group($config->withSubject("Can not mock final or private"), function(TestCase $case) {
2221
$user = $case->mock(UserService::class, function(MethodRegistry $method) {
2322
$method->method("getUserRole")->willReturn("admin");
2423
$method->method("getUserType")->willReturn("admin");
2524
});
2625

26+
// You cannot mock final with data (should return a warning)
2727
$case->validate($user->getUserType(), function(Expect $expect) {
2828
$expect->isEqualTo("guest");
2929
});
30+
31+
// You can of course mock regular methods with data
32+
$case->validate($user->getUserRole(), function(Expect $expect) {
33+
$expect->isEqualTo("admin");
34+
});
3035
});
3136

3237
$unit->group($config->withSubject("Test mocker"), function (TestCase $case) use($unit) {

0 commit comments

Comments
 (0)