PHP code example of lipemat / wp-unit

1. Go to this page and download the library: Download lipemat/wp-unit 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/ */

    

lipemat / wp-unit example snippets



re __DIR__ . '/vendor/autoload.php';


define( 'DB_NAME', 'tests' );
define( 'DB_USER', 'user' );
define( 'DB_PASSWORD', 'password' );
define( 'DB_HOST', 'localhost' );

define( 'ABSPATH', WP_TESTS_DIR . '/' );
define( 'DOMAIN_CURRENT_SITE', 'wp-libs.loc' );
define( 'WP_TESTS_CONFIG_FILE_PATH',  __FILE__ );
define( 'WP_PHP_BINARY', 'php' );
// Root of your site/
define( 'WP_TESTS_DIR', dirname( __DIR__ ) );
define( 'WP_TESTS_DOMAIN', 'tests.loc' );
define( 'WP_TESTS_DOMAIN', 'wp-libs.loc' );
define( 'WP_TESTS_EMAIL', '[email protected]' );
define( 'WP_TESTS_TITLE', 'WordPress Unit Tests' );
define( 'WP_UNIT_DIR', __DIR__ . '/vendor/lipemat/wp-unit' );

// If using snapshot testing.
define( 'WP_TESTS_SNAPSHOTS_BASE', 'Lipe\Project' );
define( 'WP_TESTS_SNAPSHOTS_DIR', __DIR__ . '/__snapshots__' );

// If your not bootstrapping an exiting database.
define( 'WP_TESTS_TABLE_PREFIX', 'tests_' );

// If your tests must use `https` URL.
define( 'WP_TESTS_SSL', true );


class ExampleTest extends WP_UnitTestCase {
	public function test_examples() : void {
		$this->assertTrue( true );
		$this->assertFalse( false );
	}
}


$GLOBALS['wp_tests_options'][ 'site_name' ] = 'Example Site Name';

wp_cron_run_all()




re __DIR__ . '/vendor/lipemat/wp-unit/


$GLOBALS[ 'wp_tests_filters' ][ 'the_title' ] = function ( $title ) {
	return 'Example Title';
};


define( 'WP_TESTS_SEND_MAIL', true );


define( 'WP_MEMORY_LIMIT', '128M' );


define( 'WP_LANG_DIR', __DIR__ . '/languages' );


$post = self::factory()->post->create_and_get();
$attachment = self::factory()->attachment->create_and_get();
set_post_thumbnail( $post->ID, $attachment->ID );
// Will return something like `https:///wp-content/uploads//tmp/canola.jpg`
get_the_post_thumbnail_url( $post->ID );


$categories = \get_categories( [
			'orderby' => 'term_id',
			'order'   => 'ASC',
		] );
$per_page = 20;
$this->assertEqualSetsValues(
			wp_list_pluck( array_slice( $categories, $per_page * 4, $per_page ), 'term_id' ),
			wp_list_pluck( $this->get_results( 5 )->categories, 'id' )
		)


DG\BypassFinals::enable();

class WP_UnitTestCase extends WP_UnitTestCase_Base {
    // Normally live somewhere in your project.
    static SQLite3 $sqlite_db;
    
	protected function setUp(): void {
		parent::setUp();
	    self::sqlite_db = new SQLite3( ':memory:' );
		self::sqlite_db->exec( 'BEGIN TRANSACTION' );
	}


	protected function tearDown(): void {
		self::sqlite_db->exec( 'ROLLBACK' );
		parent::tearDown();
	}
}

const WP_UNIT_TESTCASE_BASE = __DIR__ . '/WP_UnitTestCase.php';