Skip to content

Instantly share code, notes, and snippets.

@SparK-Cruz
Last active January 31, 2019 15:28
Show Gist options
  • Save SparK-Cruz/237e6f01b37a5ce2d3cff7f39272fe55 to your computer and use it in GitHub Desktop.
Save SparK-Cruz/237e6f01b37a5ce2d3cff7f39272fe55 to your computer and use it in GitHub Desktop.
PHP Trait to be used for testing when invoking private methods is necessary
<?php
namespace Test;
trait Trespasser
{
protected function forceCall($subject, $methodName, ...$parameters)
{
$reflection = new \ReflectionMethod($subject, $methodName);
$reflection->setAccessible(true);
return $reflection->invokeArgs($subject, $parameters);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment