1. Go to this page and download the library: Download inpsyde/wp-tests-starter 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/ */
inpsyde / wp-tests-starter example snippets
public function testPersistBook(): void {
$book = new Book('The Da Vinci Code', 'Dan Brown', '2003');
$testee = new BookRepository($GLOBALS['wpdb']);
$testee->persist($book); // maps book to WP_Post object and post meta
self::assertGreaterThan(0, $book->id());
$wpPost = get_post($book->id());
self::assertSame('The Da Vinci Code', $wpPost->post_title);
self::assertSame('2003', get_post_meta($book->id(), '_publishing_year', true));
self::assertSame('Dan Brown', get_post_meta($book->id(), '_author', true));
}
declare(strict_types=1);
namespace MyProject\Tests;
use Inpsyde\WpTestsStarter\WpTestsStarter;
$projectDir = dirname(__DIR__);
') // Databse credentials in URL format, set in phpunit.xml.dist
);
// Some configuration:
$starter
// Install WP core as multisite
->testAsMultisite()
// boostrap your plugin or module code
->addActivePlugin(static function() {
(new MyModule())->init();
})
// add filters early
->addFilter('my_app.modules', static function(array $modules): array {
// whatever, it's just an example
return $modules;
})
//finally load WordPress
->bootstrap();
//either
$starter = new WpTestsStarter($baseDir, $dbUrl);
// or
$starter->useDbUrl($dbUrl);