traviscarden/behat-table-comparison
Composer 安装命令:
composer require --dev traviscarden/behat-table-comparison
包简介
Provides an equality assertion for comparing Behat TableNode tables.
README 文档
README
The Behat Table Comparison library provides an equality assertion for comparing Behat TableNode tables.
Installation & Usage
Install the library via Composer:
composer require --dev traviscarden/behat-table-comparison
Then use the TableEqualityAssertion class in your FeatureContext class:
<?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 = [ ['name', 'race'], // Header row (required when using expectHeader(...) ['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') ->setDuplicateRowsLabel('Duplicate characters') ->assert(); } }
Output is like the following:
Understanding Headers and Terminology
When using expectHeader(...), it's important to understand the asymmetrical design:
- Specified header: The header you declare by calling
expectHeader(...). This is what the columns should be. - Expected table: The table you provide as the first argument to
TableEqualityAssertion(your test specification). Its first row must match the specified header and is stripped before comparison. - Actual table: The table you provide as the second argument to
TableEqualityAssertion(the application's real output). It is compared as-is with no header validation or stripping.
This design is intentional: test specifications typically include headers (e.g., from Gherkin), while application-generated output often does not.
Error Message Specification
When tables are unequal, the assertion throws UnequalTablesException with a detailed
diagnostic message. The integer error code, available via getCode(), identifies the
category of failure:
| Constant | When thrown |
|---|---|
UnequalTablesException::HEADER_MISMATCH |
The header row does not match the expected header. |
UnequalTablesException::CONTENT_MISMATCH |
Rows are missing, unexpected, or duplicated. |
UnequalTablesException::ROW_ORDER_MISMATCH |
The same rows are present but in a different order. |
UnequalTablesException::STRUCTURAL_ERROR |
A structural failure occurred processing a table; see getPrevious(). |
Consumers should use the named constants rather than bare integers. For example:
try { (new TableEqualityAssertion($expected, $actual))->assert(); } catch (UnequalTablesException $e) { match ($e->getCode()) { UnequalTablesException::HEADER_MISMATCH => /* handle header issue */, UnequalTablesException::ROW_ORDER_MISMATCH => /* handle order issue */, default => /* handle content issue */, }; }
For a complete list of stable/public guarantees, see Contract Surface.
Difference sections
--- Missing rows: Rows present in expected but not in actual.+++ Unexpected rows: Rows present in actual but not in expected.*** Duplicate rows: Rows present on both sides with different multiplicity, shown as(appears N time/times, expected M).
Row-order diagnostics
When row order is respected and rows are out of order:
*** Row order mismatchis shown.- Per-row diagnostics are listed as
... should be at position X, found at Y. - Full order context is appended under:
Expected orderActual order
When row content differs while respecting row order, semantic missing/unexpected/duplicate sections are shown first, then full expected/actual order tables.
Header mismatch diagnostics
When expectHeader(...) is used and the expected table's first row does not match the specified header:
--- Expected header: The header specification passed toexpectHeader(...)+++ Given header: The expected table's first row (the test specification header that was provided)
Label customization
All user-facing section labels are configurable via defaults plus getter/setter pairs:
- Missing rows
- Unexpected rows
- Duplicate rows
- Row order mismatch
- Expected header
- Given header
- Expected order subheading
- Actual order subheading
Examples
See examples/bootstrap/FeatureContext.php and examples/features/examples.feature for more examples.
Contribution
All contributions are welcome according to normal open source practice.
traviscarden/behat-table-comparison 适用场景与选型建议
traviscarden/behat-table-comparison 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.72M 次下载、GitHub Stars 达 8, 最近一次更新时间为 2017 年 01 月 31 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「testing」 「Behat」 「gherkin」 「dev」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 traviscarden/behat-table-comparison 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 traviscarden/behat-table-comparison 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 traviscarden/behat-table-comparison 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Behat Context for testing Symfony Api
A Behat Extension that allows custom bootstrapping
Codeception module for supporting parameter notation in Gherkin features
Environment processor and contexts autoloader
A small library to check and fix annoying gherkin code style
Provides access to magento2 object manager from behat and allows to change magento config settings temporarly
统计信息
- 总下载量: 2.72M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 9
- 点击次数: 30
- 依赖项目数: 4
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-01-31
