Skip to content

Instantly share code, notes, and snippets.

@muhamed-didovic
Forked from JeffreyWay/reflection.php
Last active August 29, 2015 14:11
Show Gist options
  • Save muhamed-didovic/9621551164ade8e1955d to your computer and use it in GitHub Desktop.
Save muhamed-didovic/9621551164ade8e1955d to your computer and use it in GitHub Desktop.
<?php
// ...
public function testProtected()
{
$dateFormatter = new DateFormatter;
$class = new \ReflectionClass('DateFormatter');
// Find the protected/private method and make it public
$getSentence = $class->getMethod('getSentence');
$getSentence->setAccessible(true);
// Trigger the method, and pass in any applicable args
$sentence = $getSentence->invokeArgs($dateFormatter, [1, 'month']);
// Do your test as usual
$this->assertEquals('1 month from now.', $sentence);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment