calderawp/caldera-interop-fixture

0.1.0 2018-05-08 21:48 UTC

This package is auto-updated.

Last update: 2024-09-08 06:47:28 UTC


README

Build Status

caldera-interop 兼容服务 自动化测试

为什么?

  • 每个兼容集必须始终在数组/实体/模型/集合/HTTP 消息/等之间转换。
  • 我们只能在测试了实体属性所有可能值组合的合理近似后,才能相信这个声明。
  • 编写所有这些测试需要很长时间。

安装

composer require calderawp/caldera-interop-fixture --dev

需求

  • PHP 7.1

状态

BETA

用法

此测试组件旨在与使用 InteropProvider 提供给容器的兼容集一起使用。此组件由两部分组成。

固定设备和属性描述

InteropFixture 类接受一组类似数组的 PropData 数据,用于描述实体的属性和可能值。 PropData 是此过程中最不自动化的部分。

PropData

对于每个属性,我们提供该属性名称和值数组。例如,要添加 xpLevel 属性

$propData = new PropData();
$propData->testProps = [
   'xpLevel' => [
       'values' => []
   ]
];

values 索引收集提供输入值和预期输出值的数组。例如,要测试我们的属性绝对值始终返回

[
    'value' => -10,
    'expect' => 10
],

完整示例

$propData = new PropData();
$propData->testProps = [
   'xpLevel' => [
       'values' => [
           [
               'value' => -10,
               'expect' => 10
           ],
           [
               'value' => 10,
               'expect' => 10
           ],
       ]
   ],
   'otherLevel' => [
           'values' => [
               [
                   'value' => 10,
                   'expect' => 10
               ],
               [
                   'value' => 10,
                   'expect' => 10
               ],
           ]
       ]
];

InteropFixture

use calderawp\InteropFixture\Entities\PropData;
use calderawp\InteropFixture\InteropFixture;
$fixture = new InteropFixture($propData);

在测试中使用

use calderawp\HelloExtension\HelloInteropService;
use calderawp\interop\CalderaForms;
use calderawp\interop\Interfaces\CalderaFormsApp;
use calderawp\InteropFixture\Entities\PropData;
/**
 * Class HelloInteropTest
 *
 * Test the example Hello interop binding
 */
class MyInteropTest extends UnitTestCase
{
	//Make fixture tests available
	use TestsInterops;


	public function testInterop()
	{
		//This provides 64 assertions for a set with two properties :)
		$this->checkFixture(
			new InteropFixture(PropData::fromArray([
				//array like examples above
			])),
			//The interoperable service provider for this set
			new SomeService(),
			//main app
			CalderaForms::factory()
		);
	}


}

完整示例

在 tests/Unit/HelloInteropTest 中的测试中测试了 tests/example 中的示例兼容集。此示例有两个属性。两者都有自定义验证逻辑。为此集生成了 64 个断言。

开发

安装

需要 git 和 Composer

  • git clone git@github.com:calderawp/caldera-interop-fixture.git
  • cd caldera-interop-fixture
  • composer install

编码标准:Caldera (psr2 with tabs)。强制使用 phpcs。

测试

测试分为单元测试和其他类型的测试。

安装

所有测试依赖项都通过 composer 安装。

使用

从插件的根目录运行以下命令。

  • 运行所有测试和代码格式化
    • composer tests
    • 包括以下内容:lints、单元测试和以下文档中记录的修复
  • 运行单元测试
    • composer unit-tests
    • 单元测试位于 /Tests/Unit
  • 修复所有代码格式
    • composer formatting
    • 运行代码嗅探和代码修复以及 lint。

其他。

版权所有 2018 CalderaWP LLC。许可证:GPL v2 或更高版本。