traviscarden / behat-table-comparison
Provides an equality assertion for comparing Behat TableNode tables.
Installs: 2 383 738
Dependents: 4
Suggesters: 0
Security: 0
Stars: 8
Watchers: 3
Forks: 2
Open Issues: 1
Requires
- php: ^7.3 || ^8.0
- behat/gherkin: ^4.4.4
- sebastian/diff: >=1.4
Requires (Dev)
- behat/behat: ^3.3
- phpunit/phpunit: ^9.5
- squizlabs/php_codesniffer: ^3.6
This package is auto-updated.
Last update: 2024-11-23 19:59:08 UTC
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 = [ ['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(); } }
Output is like the following:
Examples
See features/bootstrap/FeatureContext.php
and features/examples.feature
for more examples.
Limitations & Known Issues
Some inequality detection currently works but does not yet display a helpful error message, because it has not been decided what it should show. Please help me specify error messages for complex differences.
Contribution
All contributions are welcome according to normal open source practice.