concise
concise copied to clipboard
array equals diff
$this->assert([
['attach', ['event3', [1, 'method5']]],
['attach', ['event1', [1, 'method1']]],
['attach', ['event2', [1, 'method2']]],
['attach', ['event3', [1, 'method4']]],
['attach', ['event3', [1, 'method3']]],
])->equals([
['attach', ['event3', [1, 'method5']]],
['attach', ['event1', [1, 'method1']]],
['attach', ['event3', [1, 'method2']]],
['attach', ['event3', [1, 'method4']]],
['attach', ['event3', [1, 'method3']]],
]);
produces
[
[
"attach",
[
"event3",
[
1,
"method5"
]
]
],
[
"attach",
[
"event1",
[
1,
"method1"
]
]
],
[
"attach",
[
"event2",
[
1,
"method2"
]
]
],
[
"attach",
[
"event3",
[
1,
"method4"
]
]
],
[
"attach",
[
"event3",
[
1,
"method3"
]
]
]
] equals [
[
"attach",
[
"event3",
[
1,
"method5"
]
]
],
[
"attach",
[
"event1",
[
1,
"method1"
]
]
],
[
"attach",
[
"event3",
[
1,
"method2"
]
]
],
[
"attach",
[
"event3",
[
1,
"method4"
]
]
],
[
"attach",
[
"event3",
[
1,
"method3"
]
]
]
]
vs phpunit's
$this->assertEquals([
['attach', ['event3', [1, 'method5']]],
['attach', ['event1', [1, 'method1']]],
['attach', ['event2', [1, 'method2']]],
['attach', ['event3', [1, 'method4']]],
['attach', ['event3', [1, 'method3']]],
], [
['attach', ['event3', [1, 'method5']]],
['attach', ['event1', [1, 'method1']]],
['attach', ['event3', [1, 'method2']]],
['attach', ['event3', [1, 'method4']]],
['attach', ['event3', [1, 'method3']]],
]);
which produces
--- Expected
+++ Actual
@@ @@
1 => Array (
- 0 => 'event2'
+ 0 => 'event3'
1 => Array (...)
)
)
3 => Array (...)
4 => Array (...)
)
Yes, you're right. When you are comparing complex structures the differences become harder to read.
It could very well be redesigned, here are some ideas:
-
Use the background colour of the terminal to highlight lines that are different. This makes the differences stand out immediately but it useless when the colours are disabled (like on a CI).
-
We could produce a patch like PHPUnit. This focuses on the differences but doesn't always give a context that can make the output confusing.
-
We could put them side by side with a diff algorithm, like:
actual expected
[ [
5, 5,
2 3, // This line would be purple
2 // This line would be green
] ]
I'm keen to hear your ideas?
Best would be a combination of all 3:
- show side by side
- highlight change like github does in pull requests
- show +/- like phpunit does
If I had to do it simple though, I would just show +/- to current output
But I think important is also limiting amount of data shown. Phpunit is in this too restrictive and shows too little, but yours shows too much and it would be a problem when comparison data is large
Thats true, perhaps a CLI argument --context-lines
which defaults to a sensible number like 5. This would allow people to configure how many lines above and below the changes they would see?