Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions tests/Unit/Value/ValueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,42 @@ public function parsesArithmeticInFunctions(string $operator): void
self::DEFAULT_DELIMITERS
);

self::assertInstanceOf(CSSFunction::class, $subject);
self::assertSame('max(300px,50vh ' . $operator . ' 10px)', $subject->render(OutputFormat::createCompact()));
$result = $subject->getArrayRepresentation();
self::assertSame(
[
'class' => 'CSSFunction',
'components' => [
[
'class' => 'Size',
'number' => 300.0,
'unit' => 'px',
],
[
'class' => 'RuleValueList',
'components' => [
[
'class' => 'Size',
'number' => 50.0,
'unit' => 'vh',
],
[
'class' => 'string',
'value' => $operator,
],
[
'class' => 'Size',
'number' => 10.0,
'unit' => 'px',
],
],
'separator' => ' ',
],
],
'separator' => ',',
'name' => 'max',
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using assertSame() means the array keys must be in matching order, though it seems slightly illogical for name to be last.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can use assertEqualsCanonicalizing instead so we can have the array elements in a more readable order in the test.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I take taht back. We'd want something like assertSameCanonicalizing (as we want to do a strict comparison), which does not exist.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I take taht back. We'd want something like assertSameCanonicalizing (as we want to do a strict comparison), which does not exist.

That would be nice to have. Also, assertEqualsCanonicalizing sorts the array by value, whereas we want it sorted by key to be canonical. I've thought of a way to get CSSFunction to return the array in a more logical order without significant overhead or duplication, which I'll submit as a separate PR if it works...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That said, this particular test is somewhat convoluted. Other simpler tests may not need to worry about the order of the array keys.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've thought of a way to get CSSFunction to return the array in a more logical order without significant overhead or duplication, which I'll submit as a separate PR if it works...

#1461

],
$result
);
}

/**
Expand Down