-
Notifications
You must be signed in to change notification settings - Fork 180
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
[2.0] Reduce size of WebTestCase? #392
Comments
I agree that traits are the less elegant solution. Essentially they are a quick fix band aid. So to me the choice boils down to how much time we want to invest. The service route is the cleaner route but more work. |
It may not be so long, but the main issue is that we cannot do |
Could we deprecate runCommand or create additional method which will return related to #219 |
I agree, using the |
Most of the code has been moved in several classes, thanks to #398 🎉 |
Problem
As suggested by @soullivaneuh, we can discuss here about the size problem of
WebTestCase
.The last version of
WebTestCase
contains 888 lines, including 28use
declarations: https://github.com/liip/LiipFunctionalTestBundle/blob/3bca1f2349c694f16670d6de63020c28c55df9fa/src/Test/WebTestCase.phpThis class has accumulated features since 7 years, this is nice but it looks more and more like a Big Ball Of Mud. We have the opportunity to clean it up.
I identified some groups of related methods (methods marked with ¹ were moved in the
HttpAssertions
one year ago):getKernelClass()
,getServiceMockBuilder()
,getContainer()
loadFixtures()
,loadFixtureFiles()
,setExcludedDoctrineTables()
and all the private methods that are needed by these methodsrunCommand()
,setVerbosityLevel()
createUserToken()
,loginAs()
makeClient()
,isSuccessful()
¹,fetchContent()
,fetchCrawler()
,assertStatusCode()
¹,assertValidationErrors()
¹We're very far from Single responsibility principle. 😅
Interestingly, about one half of the class code is used to load fixtures. So I think that it should be the first thing to move.
Solution
@lsmith77 has suggested several possibilities:
Traits
I was in favour of traits but @Jean85 added a strong argument againt it:
With traits, complexity would persist since
WebTestCase
and its traits would still be linked together.Services
With services, we could add something like the
liip.functional_test.fixtures_loader
(or the class name) and call$this->getContainer('liip.functional_test.fixtures_loader')->loadFixtures(…);
$this->getContainer()->get('liip.functional_test.fixtures_loader')->loadFixtures(…); instead of
$this->loadFixtures(…);`. This is longer to type but it will be easier to maintain a service with its own class than a long class.We may also inject this
liip.functional_test.fixtures_loader
service inWebTestCase
in order to provide a shortcut to this service.[Your solution here]
Please share your thoughts on this subject!
The text was updated successfully, but these errors were encountered: