Closed (fixed)
Project:
Drupal core
Version:
9.3.x-dev
Component:
media system
Priority:
Minor
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
26 Jan 2019 at 17:34 UTC
Updated:
30 Aug 2021 at 13:44 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
phenaproximaThanks for looking into this!
Comment #3
averagejoe3000Comment #4
nathandentzau+1 RTBC
Comment #5
phenaproximaLooks great! Nice, straightforward test coverage. My feedback is all minor stuff, mostly style things. Thanks for writing this!
I'm not a huge fan of the whole "getter that is actually a setter" pattern. Let's reduce all this down to one line:
return $this->logger ?: \Drupal::service('logger.channel.media');There's only one test method, so we don't really need to implement setUp() on this class. Therefore, we also don't really need to have the mocked objects as properties of the class. Let's just make them local variables of the test method.
Let's use Prophecy to mock the classes that need it; it's a lot more readable. This will become something like:
Using Prophecy, this will be something like:
$logger->error(Argument::type('string'))->shouldBeCalled()This should be something like
$this->assertInternalType('array', $provider_repository->getAll());Comment #7
averagejoe3000Patch is rerolled against 8.8.x.
I updated the getLogger method with the single line return, and updated the test to use prophesize. I left the set up method as an entry point into the test to instantiate my mocked services.
Comment #8
phenaproximaThanks! Let's see if this passes tests. Looking forward to getting this committed!
Comment #9
nathandentzauRemoved the unused
use GuzzleHttp\Psr7\Response;use statement.Comment #10
phenaproximaThanks for this! Looking super good.
Should be "Gets".
Can all these be moved into local variables of testGetAllWhenProviderUrlIsInvalid()? :)
This should be returning the mocked double, so
->willReturn($config->reveal()).I didn't know this until very recently, but responses don't really need to be prophesized :) Something like
new Response(200, [], Json::encode(...))Should be using \Drupal\Component\Serialization\Json::encode().
Comment #11
averagejoe3000I updated the typo, removed the setUp method and make all the variables local, no longer prophesize the response, and use the \Drupal\Component\Serialization\Json::encode() method.
The
add-logging-service-3028664_11.broken.patchfile is just the test fileComment #12
averagejoe3000Updated code for style.
Comment #13
phenaproximaPerfect.
Comment #14
phenaproximaComment #16
alexpottThis is not really used in core.
Also why are we logging here? I'm not sure that this is the correct approach. We are throwing ProviderException above so why not make this the responsibility of the callers?
Maybe we should be injecting the logger here.
Comment #18
averagejoe3000Updated ProviderRepository to not use logger aware trait and added to constructor with E_USER_DEPRECATED error. Added comment as to the error should be logged.
Comment #19
averagejoe3000Corrected newly added comment to 80 character line length
Comment #20
phenaproximaGlorious! All of @alexpott's feedback is addressed; back to RTBC.
Comment #21
alexpottThe problem with adding $logger to the end of the arguments is that $cache_backend is optional. Really we need to move it to before $cache_backend.
This shuffle is kinda complex though... so something like this...
We need not to the type hinting manually.
Comment #22
averagejoe3000I had trouble generating the interdiff for this patch and the last patch.
Comment #23
phenaproximaNo worries. Let's see how the testbot likes this.
Comment #24
alexpottWe're missing an else to handle $cache_backend when in is a CacheBackendInterface
Comment #25
averagejoe3000Thank you for catching that alexpott. I added another if statement to check if cache_backend is a CacheBackendInterface and set it there.
Comment #26
alexpottDiscussed more with @averagejoe3000...
I think we beed the else thrown exception here too...
Maybe we can change direction above to have the first bit sort out the arguments to conform to the new expectations and then do the pseudo-typehinting here.
Comment #27
averagejoe3000I updated the constructor with your suggestions.
Comment #28
alexpottThanks @averagejoe3000. Sorry that this change is proving tricky. Maintaining deprecated constructors were arguments are moving is not an easy task!
Because this is complex we should introduce a legacy test that tests our assumptions about how this logic works and how the deprecation is triggered.
must be an instance of CacheBackendInterface - according to the docs it is optional.
Comment #29
phenaproximaComment #34
phenaproximaAs of #3186184: Make oEmbed provider repository more fault-tolerant if provider database is unavailable (9.3.x and up), the provider repository is much more docile about throwing exceptions. It will now throw only if it really doesn't have any data to work with, even in its permanent non-volatile cache, which is truly a show-stopping error condition that warrants a throw.
Therefore, I think we can reduce the scope of this issue and patch, to simply add a log line warning about providers which are skipped. I can see such a thing being helpful for debugging purposes. The referenced issue also injected the logger factory and handled the backwards compatibility implications of that, so this patch can be really, really simple. Just a log line and a unit test. I'm downgrading it to minor priority for that reason.
Comment #36
phenaproximaHiding patches in favor of the merge request. Which has tests, so removing that tag as well.
Comment #37
phenaproximaComment #38
chris burge commentedMR looks good and has test coverage. +1 for commit
Comment #40
catchCommitted/pushed to 9.3.x, thanks!