traviscarden/behat-table-comparison

为 Behat TableNode 表格提供等价断言,用于比较。

v0.3.0 2021-06-11 18:20 UTC

This package is auto-updated.

Last update: 2024-08-23 19:26:44 UTC


README

Packagist Build Status Coverage Status

Behat Table Comparison 库提供了 Behat TableNode 表格的比较等价断言。

安装 & 使用

通过 Composer 安装库

composer require --dev traviscarden/behat-table-comparison

然后在您的 FeatureContext 类中使用 TableEqualityAssertion

<?php

use Behat\Behat\Context\Context;
use Behat\Gherkin\Node\TableNode;
use TravisCarden\BehatTableComparison\TableEqualityAssertion;

class FeatureContext implements Context
{

    /**
     * @Then I should include the following characters in the Company of the Ring
     */
    public function iShouldIncludeTheFollowingCharactersInTheCompanyOfTheRing(TableNode $expected)
    {
        // Get the data from the application and create a table from it.
        $application_data = [
            ['Frodo Baggins', 'Hobbit'],
            ['Samwise "Sam" Gamgee', 'Hobbit'],
            ['Saruman the White', 'Wizard'],
            ['Legolas', 'Elf'],
            ['Gimli', 'Dwarf'],
            ['Aragorn (Strider)', 'Man'],
            ['Boromir', 'Man'],
            ['Meriadoc "Merry" Brandybuck', 'Hobbit'],
            ['Peregrin "Pippin" Took', 'Hobbit'],
        ];
        $actual = new TableNode($application_data);

        // Build and execute assertion.
        (new TableEqualityAssertion($expected, $actual))
            ->expectHeader(['name', 'race'])
            ->ignoreRowOrder()
            ->setMissingRowsLabel('Missing characters')
            ->setUnexpectedRowsLabel('Unexpected characters')
            ->assert();
    }

}

输出类似于以下内容

Example Output

示例

有关更多示例,请参阅 features/bootstrap/FeatureContext.phpfeatures/examples.feature

限制 & 已知问题

目前某些不等式检测功能已启用,但尚未显示有用的错误消息,因为它尚未确定应该显示什么。请帮助我 指定复杂差异的错误消息

贡献

根据 标准开源实践 欢迎所有贡献。