Last active
November 16, 2016 07:56
-
-
Save RickySu/0b956dfc06153148cde6a0ca7affd8aa to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
abstract class Foo | |
{ | |
protected $records; | |
public function __construct() | |
{ | |
$this->records = $this->setRecords(); | |
} | |
abstract public function setRecords(); | |
public function getMaxRecord() | |
{ | |
return max($this->records); | |
} | |
} | |
//tests | |
class FooTest extends PHPUnit_Framework_TestCase | |
{ | |
public function test___construct() | |
{ | |
//arrange | |
$vale = 'test_value'; | |
$foo = $this | |
->getMockBuilder(Foo::class) | |
->setMethods(array('setRecords')) | |
->disableOriginalConstructor() | |
->getMockForAbstractClass(); | |
$foo | |
->expects($this->once()) | |
->method('setRecords') | |
->willReturn($value); | |
$class = new ReflectionClass(Foo::class); | |
$constructor = $class->getConstructor(); | |
//act | |
$constructor->invoke($foo); | |
//assert | |
$this->assertEquals($value, $this->getObjectAttribute($foo, 'records')); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment