Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
The FocalPoint class was not written with dependency injection in mind and this means that we cant write unit tests very well and that makes me sad. Fixing this would make me happy...
Comment | File | Size | Author |
---|---|---|---|
#18 | dependency_injection-2488292-18.patch | 12.51 KB | bleen |
Comments
Comment #1
bleen CreditAttribution: bleen at NBCUniversal commentedComment #2
bleen CreditAttribution: bleen at NBCUniversal commentedComment #3
bleen CreditAttribution: bleen at NBCUniversal commentedComment #4
bleen CreditAttribution: bleen at NBCUniversal commentedChasing HEAD
Comment #5
bleen CreditAttribution: bleen at NBCUniversal commentedThis patch is getting closer. The biggest change is that there is no more getFocalPoints() method. It doesnt actually make sense to have this in the FocalPoint class... perhaps I should reintroduce it in the .module itself?
Comment #6
bleen CreditAttribution: bleen at NBCUniversal commentedChasing HEAD
Comment #7
bleen CreditAttribution: bleen at NBCUniversal commentedComment #8
phenaproximaAt @balsama's request, I gave this a look. I'm unfamiliar with Focal Point so I didn't try to find deep issues or bugs, but I recommend the following changes:
Drupal doesn't use private; protected is greatly preferred.
@param File should be @param \Drupal\file\FileInterface.
Likewise, we prefer to type hint interfaces, not concrete classes, so that we can use mock objects in unit testing. So this should be FileInterface, not File.
This comment is strange -- is setFocalPoint() an abstract method or something? This line should probably just be iced.
These need more info :)
This line is kinda meaningless, since it's on a method called...FocalPoint::getFocalPoint() :) Should be removed.
Needs more info about the meaning of the return value.
Ideally, \Drupal::database() should not be used in a class. The database should be injected in the constructor -- \Drupal\Core\Database\Connection.
These need more info.
Should not use db_query(). The database should be injected in the constructor so you can do $this->database->select().
Generally, we prefer to mock interfaces over concrete classes. Also, if you mock FileInterface instead of File, you will not need to call disableOriginalConstructor().
Comment #9
balsamaThanks, @phenaproxima. @bleen18, we'll try to roll a new patch based on this unless you have objections or want to do it yourself. @chuchunaku can you take that on?
Comment #10
ChuChuNaKu CreditAttribution: ChuChuNaKu commented@balsama Yes, I'll work on that now.
Comment #11
bleen CreditAttribution: bleen at NBCUniversal commentedyes, please .. patches welcome
Comment #12
ChuChuNaKu CreditAttribution: ChuChuNaKu commented@bleen18 I'm working on putting an updated patch together based on @phenaproxima's comments. A few of the comments stated that more info is needed. I was wondering if you could help me complete the missing information @phenaproxima mentioned above?
Also, I attempted to apply the dependency_injection-2488292-6.patch but part of it failed. The errors I got when trying to apply the patch was
Comment #13
bleen CreditAttribution: bleen at NBCUniversal commentedThis is a straight re-roll of the patch from #6 with a few extra docblock comments based on #12...
I dont have a working local environment right now because my laptop is wonky and i have not had time to wipe it so this reroll has not been tested. (Incidentally, if anyone has an answer to this http://stackoverflow.com/questions/32878420/apache-wont-start-on-osx-htt... that'd be swell)
Comment #14
ericduran CreditAttribution: ericduran at NBCUniversal commentedThis call isn't needed anymore.
Comment #15
ericduran CreditAttribution: ericduran at NBCUniversal commentedIs it me or is the TestFocalPoint class missing?
It's not in the git repo
Comment #16
bleen CreditAttribution: bleen at NBCUniversal commentedI removed the line from #14
The TestFocalPoint class is in the repo: http://cgit.drupalcode.org/focal_point/tree/tests/src/Unit?h=8.x-1.xno its not ... adding back to the patch
Comment #17
bleen CreditAttribution: bleen at NBCUniversal commentedHere is a patch with the TestFocalPoint class too
Comment #18
bleen CreditAttribution: bleen at NBCUniversal commented... and finally, an actual patch with everything...
Comment #19
bleen CreditAttribution: bleen at NBCUniversal commented#2626950: Depend on Crop API for storage largely made this issue mute ... closing