-
Notifications
You must be signed in to change notification settings - Fork 149
Description
interface Renderable {
public function getArrayRepresentation(): array;
}Add it to the interface and add stub implementations to the implementing classes.
Discussed in #1439
Originally posted by oliverklee December 21, 2025
One big hurdle for adding more tests and for refactoring the existing tests is that we currently cannot check easily what the result of parsing some CSS is. I've thought about how we could improve this.
At the moment, we either check what render() returns (which also tests the rendering code and is dependent on the passed output format), or we do a big salad of multiple assertions, including multiple assertInstanceOf calls for the subject's children..
I'd like to make this easier. For this, I suggest we add an @internal method debugForTesting() (suggestions for a better name are welcome) and add it to the CSSElement (or Renderable) interface.
This method returns an object's class, its relevant data and recursively its children.
The return value is an array as this avoids the problem of multiline strings and long lines that strings have. Also, PHPUnit is quite good at displaying differences in arrays in a readable manner.
For example, the multi-assertion test then could work on an array like this instead (manually written, not tested):
[
'class' => `CSSFunction` // not the full class in order to improve readability
'name' => 'max',
'arguments' => [
0 => [
'class' => 'Size',
'size' => 300.0,
'unit' => 'px',
'isColorComponent' => false,
],
],
];Unlike var_export, this returned representation can hide some irrelevant internal details and shorten the output.
WDYT, @sabberworm, @JakeQZ?