PHP code example of jimigrunge / invoke-private-methods
1. Go to this page and download the library: Download jimigrunge/invoke-private-methods library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
jimigrunge / invoke-private-methods example snippets
// Include class to call private methods
use Jimigrunge\InvokePrivateMethods\InvokePrivateMethod;
class testclass extends \PHPUnit_Framework_TestCase
{
/** @var InvokePrivateMethod */
private $invoker;
private $dummyObject;
public function setUp()
{
// Instantiate the class
$this->invoker = new InvokePrivateMethod();
$this->dummyObject = new DummyClass();
}
public function testMyMethod()
{
// Call invoke method on private function
$result = $this->invoker->invokeMethod($this->dummyObject, 'myPrivateFunction', ['param1']);
$this->assertEquals('Test Success', trim($result));
}
public function testMyMethodStatically()
{
// Can also be used statically
$result = InvokePrivateMethod::invoke($this->dummyObject, 'myPrivateFunction', ['param1']);
$this->assertEquals('Test Success', trim($result));
}
}
// Include trait to call private methods
use Jimigrunge\InvokePrivateMethods\Traits\InvokePrivateMethodTrait;
class testclass extends \PHPUnit_Framework_TestCase
{
use InvokePrivateMethodTrait;
private $dummyObject;
public function setUp()
{
$this->dummyObject = new DummyClass();
}
public function testMyMethod()
{
// Call invoke method on private function
$result = $this->invokeMethod($this->dummyObject, 'myPrivateFunction', ['param1']);
$this->assertEquals('Test Success', trim($result));
}
public function testMyMethodStatically()
{
// Can also be used statically
$result = self::invoke($this->dummyObject, 'myPrivateFunction', ['param1']);
$this->assertEquals('Test Success', trim($result));
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.