1. Go to this page and download the library: Download gin0115/wpunit-helpers 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/ */
$post_meta = Meta_Data_Inspector::initialise()->find_post_meta('post', 'my_key');
$this->assertInstanceOf(Meta_Data_Entity::class, $post_meta);
$this->assertEquals('This is my meta field', $post_meta->description);
// Access protected & privates properties.
Objects::get_property($instnace, 'property');
// Set protected or private properties.
Objects::set_property($instnace, 'property', 'new value');
// Invoke private or protected method.
Objects::invoke_method($instance, 'method', ['the', 'args']);
// iterable_map_with allows array_map to be done with access to the key and as many other
// values you wish to pass.
$result = Utils::iterable_map_with(
function($key, $value, $spacer){
return $key . $spacer . $value;
},
['key1'=>'value1', 'key2' => 'value2'],
' -|- '
);
var_dump($result); // ['key1 -|- value1', 'key2 -|- value2']
$wpdb = new Logable_WPDB();
// Set a return value.
$wpdb->then_return = 1;
// Mock an insert
$result = $wpdb->insert('table_name', ['col1'=>'value1'], ['%s']);
// Get back the set return value
var_dump($result);
// Access the useage log
$log = $wpdb->usage_log;
var_dump($log);
/**
* ['insert' =>
* [0] => [
* 'table' => 'table_name',
* 'data' => ['col1'=>'value1'],
* 'format' => ['%s'],
* ]
* ]
*/
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.