Created
August 26, 2017 22:04
-
-
Save luke10x/e3ad07f2f71c6c2035766ede50485e59 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace So\ProphecyTest; | |
use PHPUnit\Framework\TestCase; | |
class SimpleRecord { | |
private $value = 'default-one'; | |
} | |
class MagicRecord { | |
public function __get($prop) { | |
return 'default-two'; | |
} | |
} | |
class Report { | |
public function getResult(SimpleRecord $rec1, MagicRecord $rec2) { | |
$val1 = $rec1->value; | |
$val2 = $rec2->value; | |
print_r([$val1, $val2]); | |
return "REC1: $val1, REC2: $val2."; | |
} | |
} | |
class ReportTest extends TestCase { | |
public function testGetResult() { | |
// Arrange | |
$rec1Prophecy = $this->prophesize(SimpleRecord::class); | |
$rec1 = $rec1Prophecy->reveal(); | |
$rec1->value = 'override-one'; | |
$rec2Prophecy = $this->prophesize(MagicRecord::class); | |
$rec2 = $rec2Prophecy->reveal(); | |
$rec2->value = 'override-two'; | |
$report = new Report; | |
// Act | |
$result = $report->getResult($rec1, $rec2); | |
// Assert | |
$this->assertEquals("REC1: override-one, REC2: override-two.", $result); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment