Skip to content

Instantly share code, notes, and snippets.

@RickySu
Last active November 16, 2016 07:56
Show Gist options
  • Save RickySu/0b956dfc06153148cde6a0ca7affd8aa to your computer and use it in GitHub Desktop.
Save RickySu/0b956dfc06153148cde6a0ca7affd8aa to your computer and use it in GitHub Desktop.
<?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