themeplate/tester

适用于所有包的通用信息

v2.2.1 2024-08-02 13:06 UTC

This package is auto-updated.

Last update: 2024-09-05 05:10:57 UTC


README

可用命令

使用方法

composer.json

{
	"name": "my/package",
	"require": {
		"php": "^7.4|^8.2"
	},
	"require-dev": {
		"themeplate/tester": "*"
	},
	"autoload-dev": {
		"psr-4": {
			"Tests\\": "tests"
		}
	}
}

SampleTest.php

namespace Tests;

use ThemePlate\Tester\Utils;

class SampleTest extends WP_UnitTestCase {
	public function test_sample() {
		$instance = new Class();

		Utils::invoke_inaccessible_method( $instance, 'method_name', array( 'arg1', 'arg2' ) );

		$value = Utils::get_inaccessible_property( $instance, 'property_name' );

		Utils::set_inaccessible_property( $instance, 'wanted_property', $value );

		// Do actual assertions
	}
}

执行 composer install 后,运行 ./vendor/bin/themeplate setup

  • 分析 ./vendor/bin/themeplate analyse
  • 代码检查 ./vendor/bin/themeplate lint
  • 修复 ./vendor/bin/themeplate fix
  • 测试 ./vendor/bin/themeplate test

导出配置进行自定义 ./vendor/bin/themeplate dump

示例 composer 脚本

...
    "scripts": {
        "analyse": "themeplate analyse",
        "lint": "themeplate lint",
        "fix": "themeplate fix",
        "test": "themeplate test",
        "test:unit": "themeplate test --type unit",
        "test:integration": "themeplate test --type integration"
    }
...