File tree Expand file tree Collapse file tree 3 files changed +31
-1
lines changed Expand file tree Collapse file tree 3 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -8,4 +8,12 @@ public function writeBadCode(): string
8
8
{
9
9
return 'Some junior developer generated code... ' ;
10
10
}
11
+
12
+ /**
13
+ * Junior is authorized to call method on TeamLead (real delegation)
14
+ */
15
+ public function writeReallyBadCode (TeamLead $ teamLead ): string
16
+ {
17
+ return $ teamLead ->writeReallyBadCode ();
18
+ }
11
19
}
Original file line number Diff line number Diff line change @@ -21,4 +21,18 @@ public function writeCode(): string
21
21
{
22
22
return $ this ->junior ->writeBadCode ();
23
23
}
24
+
25
+ public function writeBadCode (): string
26
+ {
27
+ //note that we are passing $this from teamLead context
28
+ return $ this ->junior ->writeReallyBadCode ($ this );
29
+ }
30
+
31
+ /**
32
+ * Junior can call this method
33
+ */
34
+ public function writeReallyBadCode (): string
35
+ {
36
+ return 'Even team lead can write bad code... ' ;
37
+ }
24
38
}
Original file line number Diff line number Diff line change 7
7
8
8
class DelegationTest extends TestCase
9
9
{
10
- public function testHowTeamLeadWriteCode ()
10
+ public function testTeamLeadCanBlameJuniorForBadCode ()
11
11
{
12
12
$ junior = new Delegation \JuniorDeveloper ();
13
13
$ teamLead = new Delegation \TeamLead ($ junior );
14
14
15
15
$ this ->assertEquals ($ junior ->writeBadCode (), $ teamLead ->writeCode ());
16
16
}
17
+
18
+ public function testTeamLeadCanWriteBadCode ()
19
+ {
20
+ $ junior = new Delegation \JuniorDeveloper ();
21
+ $ teamLead = new Delegation \TeamLead ($ junior );
22
+
23
+ $ this ->assertEquals ($ junior ->writeReallyBadCode ($ teamLead ), $ teamLead ->writeBadCode ());
24
+ }
17
25
}
You can’t perform that action at this time.
0 commit comments