sabberworm / PHP-CSS-Parser

A Parser for CSS Files written in PHP. Allows extraction of CSS files into a data structure, manipulation of said structure and output as (optimized) CSS

Home Page:http://www.sabberworm.com/blog/2010/6/10/php-css-parser

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add test mode setting

JakeQZ opened this issue · comments

It would be very useful if there was a way for exceptions caught internally to be propagated.

When unit-testing our own code we'd like to have any sign of an error fail the test in such a way that we can easily see why. Or, in certain scenarios, we might want to deliberately throw an exception for a consumer running their own tests.

This would probably involve adding a flag to Sabberworm\CSS\Settings and checking it whenever an exception is caught internally, to rethrow accordingly (like we do here).

For background, see MyIntervals/emogrifier#1129.

IMHO, using \Sabberworm\CSS\Settings::create()->beStrict() shouldn’t swallow any exceptions. Is this what you need?

Is this what you need?

Yes, sorry, I misunderstood how that setting was supposed to work, and believed it would work in somewhat the opposite way to how it does.

I thought lenient would mean allow rules with invalid selectors and provide them in the parsed data. Whereas in fact it means discard the rules nonetheless but carry on trying to parse the remainder.

Happy to close unless you think the documentation could be clarified (I think "choke" is a bit unclear and could be more clearly written as "throw an exception" - I actually thought it implied a Heimlich manoeuvre would be carried out so the parser could carry on, but that it would cough up rather than digest the specific rule that caused the error).

I actually thought it implied a Heimlich manoeuvre would be carried out so the parser could carry on, but that it would cough up rather than digest the specific rule that caused the error).

🤣

Thanks for the hint, I updated the readme as suggested.