Skip to content

Instantly share code, notes, and snippets.

@benrowe
Created May 17, 2018 06:41
Show Gist options
  • Save benrowe/527c9f0b2800293e9b180a48cd926f85 to your computer and use it in GitHub Desktop.
Save benrowe/527c9f0b2800293e9b180a48cd926f85 to your computer and use it in GitHub Desktop.
PHPUnit Test Examples
public function testConstructorCallsMethod()
{
$callMethod = 'init'
$mock = $this
->getMockBuilder(ClassToTest::class)
->disableOriginalConstructor()
->getMock();
$mock
->expects($this->once())
->method($callMethod);
$reflectClass = new \ReflectionClass(ClassToTest::class);
$constructor = $reflectClass->getConstructor();
$constructor->invoke($mock, $args, $for, $constructor);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment