You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add helper debugging/rendering function stub for (unit) tests #1440
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.
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.
It can always be moved to a separate interface if we later decide that would be cleaner/better.
Although thinking about it, there is little difference between a Renderable and a Representable. It's just a different type of rendering (as a string, or as an array of data).
I'm quite keen on this idea, so will have a crack at it now and see how it floats (proof-of-concept-wise). If you've already done some work on it (I didn't see any branches) then we may have the best of both worlds.
Activity
JakeQZ commentedon Dec 22, 2025
It can always be moved to a separate interface if we later decide that would be cleaner/better.
JakeQZ commentedon Dec 22, 2025
Although thinking about it, there is little difference between a
Renderableand aRepresentable. It's just a different type of rendering (as a string, or as an array of data).I'm quite keen on this idea, so will have a crack at it now and see how it floats (proof-of-concept-wise). If you've already done some work on it (I didn't see any branches) then we may have the best of both worlds.
[TASK] Add `getArrayRepresentation` method for testing
JakeQZ commentedon Dec 23, 2025
#1441 to see how this might work out...
[TASK] Add `getArrayRepresentation()` to `Renderable`
[TASK] Add `getArrayRepresentation()` to `Renderable` (#1447)
[TASK] Add more stub tests for `getArrayRepresentation()`
[CLEANUP] Reorder some PHPDoc annotations
[TASK] Add more stub tests for `getArrayRepresentation()` (#1448)
[CLEANUP] Reorder some PHPDoc annotations (#1449)
[TASK] Implement `getArrayRepresentation()` in `Value` and `ValueList`
61 remaining items
[TASK] Add tests for `RuleValueList::getArrayRepresentation()`
[TASK] Add tests for `RuleValueList::getArrayRepresentation()` (#1577)
[TASK] Implement `(At)RuleSet::getArrayRepresentation()`
[TASK] Implement `(At)RuleSet::getArrayRepresentation()`
[TASK] Implement `(At)RuleSet::getArrayRepresentation()` (#1580)
[TASK] Test `LineName::getArrayRepresentation()`
[TASK] Test `LineName::getArrayRepresentation()`
[TASK] Test `LineName::getArrayRepresentation()`
[TASK] Test `LineName::getArrayRepresentation()`
[TASK] Add tests for `Color::getArrayRepresentation()`
[TASK] Add tests for `Color::getArrayRepresentation()` (#1606)