Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions More/Delegation/JuniorDeveloper.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,12 @@ public function writeBadCode(): string
{
return 'Some junior developer generated code...';
}

/**
* Junior is authorized to call method on TeamLead (real delegation)
*/
public function writeReallyBadCode(TeamLead $teamLead): string
{
return $teamLead->writeReallyBadCode();
}
}
14 changes: 14 additions & 0 deletions More/Delegation/TeamLead.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,18 @@ public function writeCode(): string
{
return $this->junior->writeBadCode();
}

public function writeBadCode(): string
{
//note that we are passing $this from teamLead context
return $this->junior->writeReallyBadCode($this);
}

/**
* Junior can call this method
*/
public function writeReallyBadCode(): string
{
return 'Even team lead can write bad code...';
}
}
10 changes: 9 additions & 1 deletion More/Delegation/Tests/DelegationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,19 @@

class DelegationTest extends TestCase
{
public function testHowTeamLeadWriteCode()
public function testTeamLeadCanBlameJuniorForBadCode()
{
$junior = new Delegation\JuniorDeveloper();
$teamLead = new Delegation\TeamLead($junior);

$this->assertEquals($junior->writeBadCode(), $teamLead->writeCode());
}

public function testTeamLeadCanWriteBadCode()
{
$junior = new Delegation\JuniorDeveloper();
$teamLead = new Delegation\TeamLead($junior);

$this->assertEquals($junior->writeReallyBadCode($teamLead), $teamLead->writeBadCode());
}
}