Closed TravisCarden closed 7 years ago
If you wanted to look at implementing that, it would probably be useful. It's not something we'll have time to do in the short-to-medium term.
I think it might be quite complex to compare rows in literally any order - allowing for the possibility that some might be missing, extra, or have different values in one or more columns - and especially if you still wanted to produce a meaningful diff. If there wasn't an exact match, I guess you'd need some sort of fuzzy confidence-based matching to establish which rows in the result were meant to be equivalent to the rows in the expectation. I'd be a little worried that the complexity of the comparison would risk false-positives...
A simpler alternative might be to pick one fairly-reliable column to sort by before making the comparison. You could add an option for that, or implement something that takes a TableNode, sorts it by one or more columns and then returns a new TableNode with predictable ordering?
Ooh! I like the idea of specifying a row to sort by. So what would the ideal interface look like? This?
$this->doAssert(
'Failed asserting that two tables were equivalent: ',
['sortByColumn' => 'id'],
$expected,
$actual,
$message
);
That looks good to me.
Possibly for most flexibility 'sortByColumn' => ['id']
to support sorting on multiple columns. Although that may be overcomplicating and could easily be added later if required.
A little further use has convinced me that there's too much variance between the assumptions of my application and those of your library, so I'm going to look for an alternative. Thanks for your time, and good luck on your own endeavors!
Hi @TravisCarden no worries - I'd be interested to hear what you end up doing : always useful to have other perspectives. Cheers.
You bet, @acoulton. I've come up with this for myself: https://github.com/TravisCarden/my_devel/commit/83998431b17f405ae6f5379b4abbe0231581f1fc.
Update: I created a Packagist package for it: traviscarden/behat-table-comparison. Example output:
@TravisCarden thanks for that - it looks good. I suspect it won't quite handle some of the ways we're using / asserting tables in our projects but I'll keep an eye on it.
I'm considering behat-tableassert for a project, but I need the ability to ignore the sort order of rows. What's the chance of getting an
ignoreRowSequence
option?