Chapters
18 Chapters
|
1:54:58
|
Login to bookmark this video
-
Course Code
Subscribe to download the code!
Subscribe to download the code!
-
This Video
Subscribe to download the video!
Subscribe to download the video!
-
Subtitles
Subscribe to download the subtitles!
Subscribe to download the subtitles!
-
Course Script
Subscribe to download the script!
Subscribe to download the script!
05.
SRP: Takeaways
Scroll down to the script below, click on any sentence (including terminal blocks) to jump to that spot in the video!
Subscribe to jump to this part in the video!
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"php": ">=8.2",
"ext-ctype": "*",
"ext-iconv": "*",
"composer/package-versions-deprecated": "^1.11", // 1.11.99.1
"doctrine/annotations": "^1.0", // 1.12.1
"doctrine/doctrine-bundle": "^2", // 2.3.1
"doctrine/doctrine-migrations-bundle": "^3", // 3.1.1
"doctrine/orm": "^2", // 2.8.4
"knplabs/knp-time-bundle": "^1.15", // v1.16.0
"phpdocumentor/reflection-docblock": "^5.2", // 5.2.2
"sensio/framework-extra-bundle": "^6.0", // v6.1.2
"symfony/console": "5.2.*", // v5.2.6
"symfony/dotenv": "5.2.*", // v5.2.4
"symfony/flex": "^1.9", // v1.21.6
"symfony/form": "5.2.*", // v5.2.6
"symfony/framework-bundle": "5.2.*", // v5.2.6
"symfony/http-client": "5.2.*", // v5.2.6
"symfony/mailer": "5.2.*", // v5.2.6
"symfony/property-access": "5.2.*", // v5.2.4
"symfony/property-info": "5.2.*", // v5.2.4
"symfony/security-bundle": "5.2.*", // v5.2.6
"symfony/serializer": "5.2.*", // v5.2.4
"symfony/twig-bundle": "5.2.*", // v5.2.4
"symfony/validator": "5.2.*", // v5.2.6
"symfony/webpack-encore-bundle": "^1.6", // v1.11.1
"symfony/yaml": "5.2.*", // v5.2.5
"twig/cssinliner-extra": "^3.3", // v3.3.0
"twig/extra-bundle": "^2.12|^3.0", // v3.3.0
"twig/twig": "^2.12|^3.0" // v3.3.0
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.2", // 3.4.0
"fakerphp/faker": "^1.13", // v1.14.1
"symfony/debug-bundle": "^5.2", // v5.2.4
"symfony/maker-bundle": "^1.13", // v1.30.2
"symfony/monolog-bundle": "^3.0", // v3.7.0
"symfony/stopwatch": "^5.2", // v5.2.4
"symfony/var-dumper": "^5.2", // v5.2.6
"symfony/web-profiler-bundle": "^5.2" // v5.2.6
}
}
5 Comments
There is also important to remember about the tests. With this implementation we can only test public methods of `UserManager` (for instance, the Boston way input-output). In such case we cannot unit test token generation in separation. So I would slightly argue about some concepts presented here ;)
Cheers
Along with what Ryan said, I'd say there are other ways to test private methods.
1) Use reflection to be able to access to the private method
2) Test it indirectly. In this case, you can test what
$user->getConfirmationToken()returns3) Add an integration test for checking the whole process works (create a new user, follow confirmation, link, etc)
I wouldn't test private methods because it means that you test the implementation and not the interface with a black box testing approach. This might lead to fragile tests and bad composition thus encapsulation.
There is only one case that I would test private methods. When I have got a legacy codebase and method is crucial to be tested before the refactor.
So with this manner I would only check exposed, public interface. I encourage you to check https://github.com/sarven/u... there are some nice tips out there
Cheers
Thanks for the link Sargath, it seems useful. One last thing I have to say about testing private methods. I'd rather use reflection or making the method public (and tag it as internal method "do not call this directly") than not testing it at all. Validating your logic works as expected brings much more value than achieving encapsulation
Hey Sargath!
That's a very valid point - thanks for sharing it! We do mention this point later in the OCP section... actually talking about SRP :p - it's at the very end of the chapter - https://symfonycasts.com/sc...
But you're absolutely right. I'm not sure if SRP specifically "concerns itself" about testability. But, in the real world, if I have complex logic, I WILL split it into its own class / public method *just* to be able to unit test it. That, in itself, is another reason for "splitting".
Cheers!
"Houston: no signs of life"
Start the conversation!