File tree Expand file tree Collapse file tree 2 files changed +35
-6
lines changed
examples/php/php-user_modelling-01_base Expand file tree Collapse file tree 2 files changed +35
-6
lines changed Original file line number Diff line number Diff line change 66
77final class User
88{
9+ private const SPANISH_LANGUAGE = "es " ;
10+ private const UNDERAGE_UNTIL_AGE = 18 ;
11+
912 private string $ locale ;
1013 private int $ age ;
1114
@@ -15,13 +18,15 @@ public function __construct(string $locale, int $age)
1518 $ this ->age = $ age ;
1619 }
1720
18- public function locale (): string
21+ public function understandSpanish (): bool
1922 {
20- return $ this ->locale ;
23+ $ language = substr ($ this ->locale , 0 , 2 );
24+
25+ return $ language === self ::SPANISH_LANGUAGE ;
2126 }
2227
23- public function age (): int
28+ public function isUnderage (): bool
2429 {
25- return $ this ->age ;
30+ return $ this ->age < self :: UNDERAGE_UNTIL_AGE ;
2631 }
2732}
Original file line number Diff line number Diff line change 1010final class UserTest extends TestCase
1111{
1212 /** @test */
13- public function shouldSayHelloWhenGreeting ()
13+ public function should_detect_spanish_from_spain_as_spanish_language (): void
1414 {
1515 $ user = new User ("es_ES " , 20 );
1616
17- self ::assertEquals ("es_ES " , $ user ->locale ());
17+ self ::assertTrue ($ user ->understandSpanish ());
18+ }
19+
20+ /** @test */
21+ public function should_not_detect_english_from_great_britain_as_spanish_language (): void
22+ {
23+ $ user = new User ("en_GB " , 20 );
24+
25+ self ::assertFalse ($ user ->understandSpanish ());
26+ }
27+
28+ /** @test */
29+ public function should_detect_underage_users_until_18_years_old (): void
30+ {
31+ $ user = new User ("en_GB " , 17 );
32+
33+ self ::assertTrue ($ user ->isUnderage ());
34+ }
35+
36+ /** @test */
37+ public function should_not_detect_underage_users_starting_from_18_years_old (): void
38+ {
39+ $ user = new User ("en_GB " , 18 );
40+
41+ self ::assertFalse ($ user ->isUnderage ());
1842 }
1943}
You can’t perform that action at this time.
0 commit comments