vendi-advertising/vendi-sanity-tester

在安装过程中测试底层系统是否正常运行的工具。

v1.0.3 2018-07-24 16:16 UTC

This package is auto-updated.

Last update: 2024-09-20 04:18:48 UTC


README

示例

<?php

use Vendi\SanityTester\TestGroup;
use Vendi\SanityTester\TestRunner;
use Vendi\SanityTester\Tests\FileSystemTest;
use Vendi\SanityTester\Tests\PhpVersionTest;

define('VENDI_SANITY_ROOT', __DIR__ );

//The sanity checker is controlled via composer now
if(!file_exists(VENDI_SANITY_ROOT . '/vendor/autoload.php')){
    echo '<h1>Composer not loaded </h1>';
    exit;
}

//Load the plugin's autoloader
require_once VENDI_SANITY_ROOT . '/vendor/autoload.php';

//Make sure that the SanityTester actually exists
if(!class_exists('Vendi\SanityTester\TestRunner')){
    echo '<h1>Vendi SanityTester not found</h1>';
    exit;
}


//Now we can finally use the tester!!

          //The root runner
$runner = (new TestRunner('Sanity Tests'))

            //Add test group
            ->with_test_group(
                (new TestGroup('Composer'))

                    //Add individual tests
                    ->with_test(new FileSystemTest('Lock',          VENDI_SANITY_ROOT . '/composer.lock'))
                    ->with_test(new FileSystemTest('Vendor folder', VENDI_SANITY_ROOT . '/vendor/composer/'))
            )
            ->with_test_group(
                (new TestGroup('PHP'))
                    ->with_test(new PhpVersionTest(7, [1,2,3]))
            )
;

$runner->run();

WordPress

如果你需要测试WordPress功能,确保WordPress首先启动是你的责任。最简单的方法通常是加载wp-load.php。例如,如果你的测试文件位于一个插件根目录下,该URL是你手动调用的,你可能只需要使用

define( 'WP_USE_THEMES', false );
require '../../../wp-load.php' ;

define行本质上是一种告诉WordPress你想要轻量模式的方式。

然后你可以使用WordPressPlugin测试

$runner = (new TestRunner('Sanity Tests'))
            ->with_test_group(
                (new TestGroup('WordPress Plugins'))
                    ->with_test(new WordPressPlugin('ACF Pro', 'advanced-custom-fields-pro/acf.php'))
            )
;