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
88    {
99        return  'Some junior developer generated code... ' ;
1010    }
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+     }
1119}
Original file line number Diff line number Diff line change @@ -21,4 +21,18 @@ public function writeCode(): string
2121    {
2222        return  $ this  ->junior ->writeBadCode ();
2323    }
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+     }
2438}
Original file line number Diff line number Diff line change 77
88class  DelegationTest extends  TestCase
99{
10-     public  function  testHowTeamLeadWriteCode ()
10+     public  function  testTeamLeadCanBlameJuniorForBadCode ()
1111    {
1212        $ junior  = new  Delegation \JuniorDeveloper ();
1313        $ teamLead  = new  Delegation \TeamLead ($ junior );
1414
1515        $ this  ->assertEquals ($ junior ->writeBadCode (), $ teamLead ->writeCode ());
1616    }
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+     }
1725}
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments