Refactored UrlManagerTest to cover more use cases #13477
Merged
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.
UrlManager is a complex class with a large bunch of options that needs
to be tested
and we had a few regressions in the past even though there are already a
lot of tests
covering it. Test coverage measured by lines does not help us determine
how good it is tested,
we need test coverage for every major path through the code.
I have refactored the UrlManager tests to reflect the different options
and cases to
have a better overview of which cases are covered and which are not.
UrlManager has two main operation modes:
"default" url format, which is the simple case. These are covered by
methods in
UrlManagerTest
."pretty" url format. This is the complex case, which involves UrlRules
and url parsing.
I have created two separate classes for this case:
Url creation for "pretty" url format is covered by
UrlManagerCreateUrlTest
.Url parsing for "pretty" url format is covered by
UrlManagerParseUrlTest
.Each of the test classes have a
getUrlManager
method that creates aUrlManager instance
with a specific configuration and certain variations in options.
It is also tested that options that are not relevant in a certain
operation mode have no effect on the result.
To make sure to not remove tests that have existed before, here is a map
of where code has been moved.
The following test methods existed in the old test
class:
testCreateUrl()
split between UrlManagerTest andUrlManagerCreateUrlTest variations should all be covered by
variationsProvider()
.testCreateUrlWithNullParams()
covered by UrlManagerCreateUrlTest bytestWithNullParams()
testCreateUrlWithEmptyPattern()
testCreateAbsoluteUrl()
covered in UrlManagerCreateUrlTest by newtests via
variationsProvider()
.testCreateAbsoluteUrlWithSuffix()
covered in UrlManagerCreateUrlTestby
testAbsolutePatterns
.testParseRequest()
covered by UrlManagerParseUrlTest, UrlNormalizerrelated parts moved to UrlNormalizerTest.
testParseRESTRequest()
moved to UrlManagerParseUrlTesttestHash()
covered in different tests in UrlManagerCreateUrlTest.testMultipleHostsRules($host)
kept as is.Before:
After: