PHP code example of wikimedia / testing-access-wrapper

1. Go to this page and download the library: Download wikimedia/testing-access-wrapper 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/ */

    

wikimedia / testing-access-wrapper example snippets


use Wikimedia\TestingAccessWrapper;

class NonPublic {
	protected $prop;
	protected const CONSTANT = 4;
	protected function func() {}
	protected static function staticFunc() {}
}

class NonPublicCtor {
	protected function __construct() {}
}

$object = new NonPublic();
// or:
// $object = TestingAccessWrapper::construct( NonPublicCtor::class );

$wrapper = TestingAccessWrapper::newFromObject( $object );
$classWrapper = TestingAccessWrapper::newFromClass( NonPublic::class );

$wrapper->prop = 'foo';
$wrapper->func();
$classWrapper->staticFunc();

$value = TestingAccessWrapper::constant( NonPublic::class, 'CONSTANT' );