Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TASK] Pass debug setting on to CSS parser #1142
[TASK] Pass debug setting on to CSS parser #1142
Changes from 2 commits
73a5987
4e389d5
32150df
3c97b5b
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this line ever be reached?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I replied at length but it's been lost because GitHub's UI/UX is rubbish and I accidentally clicked a link.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/MyIntervals/emogrifier/pull/1142/files#diff-2eda2d27b064a67021c7004fd070acb00ac6bf08695521484af6c087c6eec0baR1425
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the above-linked change it was possible to split test data up on logical grounds - one set of data syntactically invalid, the other merely with property names/values that don't conform to the spec.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case there doesn't appear to be any logical split between which test data causes an exception and for which the invalid rules are simply discarded.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually in PHPUnit we can use
logicalOr
to test for this.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But if one of the conditions is an exception being thrown, AFAIAA, this is not possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hence this construct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We (as the Emogrifier maintainers) have the secret knowledge of what actually happens ;-) - and I think it's fair that we decide on one possible behavior to be the desired one and test for that. Otherwise, this would make the tests really confusing to read (because the desired behavior then is not clear to the reader).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What actually happens here is down to the behaviour of
sabberworm/php-css-parser
. We only know what happens because we have looked into it. We can influence it and I note you have had a number of PRs accepted. But at the end of the day it is a 3rd party library.Ultimately we may be able to dispense with this intermediary class and use the Sabberworm classes directly, but we are a little way off that yet.
Some invalid CSS throws an excpetion (in debug mode). Some doesn't. If it throws an excpetion in debug mode, that's a bonus. If it doesn't, it's no big deal. But we don't control that. This relates back to #1135 - to what extent are we testing 3rd party libraries duplicitously?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please let's use
$this->expectException
,expectExceptionCode
andexpectExceptionMessage
instead.Ditto for other tests that check for exceptions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean below. (Now it's above again. I mean see other comment on this.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Though if there is a
doNotExpectException
method the test could be written without thetry
/catch
- i.e. we expect an exception but if we reach some later point we'll make an assertion instead, and cancel the expectation of the exception. Is that possible?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expectException(null)
would do the trick, except that the parameter is not documented as nullable and a Psalm error is generated. (Actually it's not nullable at all and aTypeError
is generated ifnull
is passed. There doesn't seem to be a way to 'undo'expectException
.)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To test that an exception is not thrown, we can do one of the following things:
a) state that not throwing the exception is the main statement of the test, and use a
@doesNotPerformAssertions
annotationb) state that the return value (or something similar) is the main statement of the test, and assert for that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But we can't, it seems, have a 'throws exception' OR 'satisfies assertion' test. Or, at least, not easily.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then please let's test for one of the two. (We can also add the other case as a test and mark it as
self::markAsSkipped()
(if I remember the method name correctly).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. I've change this (and the other similar test) to expect an exception, but if one isn't thrown mark the test as skipped - since in strict (debug) mode the CSS parser only throws an exception with some of the datasets, and we are already testing that the invalid rules from these datasets are dropped in lenient (non-debug) mode.