PHP code example of makeweb / wordpress-test-environment

1. Go to this page and download the library: Download makeweb/wordpress-test-environment 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/ */

    

makeweb / wordpress-test-environment example snippets


use MakeWeb\WordpressTestEnvironment\Wordpress;
use PHPUnit\Framework\TestCase as BaseTestCase;

class TestCase extends BaseTestCase;
{
    public function setUp()
    {
        $this->wordpress = (new Wordpress)
            ->loadEnvFrom(__DIR__.'/..');
    } 
}

class MyPluginTest extends TestCase
{
    public function the_main_plugin_class_can_use_wordpress_global_functions()
    {
        $this->wordpress->boot();

        $this->assertEquals('http://example.test', (new MyPluginClass)->url());
    }
}

class MyPluginClass
{
    public function url()
    {
        return get_site_url();
    }
}

class MyPluginTest extends TestCase
{
    public function the_main_plugin_class_can_use_wordpress_global_functions()
    {
        // To boot the plugin which we are testing when booting wordpress, pass the relative path
        // to the main plugin file into the withPlugin() method. Installation and activation hooks
        // will not be called.
        $this->wordpress->withPlugin(__DIR__.'/../edd-sl-deployer.php');

        // Request the front page of the wordpress site and capture the result
        $response = $this->wordpress->get('/');

        // Assert that the response returned a 200 http status code
        $response->assertSuccessful();

        // Assert that our text was output in the html
        $response->assertSee('Hello World');
    }
}

/**
 * Plugin Name: Hello World Outputter
 * Plugin Description: An enterprise ready solution to output the text 'Hello World' on your website
 * Plugin URI: https://hello-world-outputter.com
 * Version: 1.0.0
 * Author: Andrew Feeney
**/

class MyPluginClass
{
    public function boot()
    {
        echo('Hello World');
    }
}

(new MyPluginClass)->boot();