Skip to content

Instantly share code, notes, and snippets.

@richlloydmiles
Last active January 6, 2019 11:49
Show Gist options
  • Save richlloydmiles/1ea6310f4b23b0ff0115795b204fdec8 to your computer and use it in GitHub Desktop.
Save richlloydmiles/1ea6310f4b23b0ff0115795b204fdec8 to your computer and use it in GitHub Desktop.
<?php
use PHPUnit\Framework\TestCase;
require('./Person.php');
class PersonTest extends TestCase {
public function testPersonClassConstructorIsCalledAsExpected() {
$mock = $this->getMockBuilder('Person')->disableOriginalConstructor()->getMock();
$mock->expects($this->once())->method('setName')->with($this->equalTo('richard'));
$reflectedClass = new ReflectionClass('Person');
$constructor = $reflectedClass->getConstructor();
$constructor->invoke($mock, 'richard', 'richard@example.com');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment