Problem/Motivation
In unit tests that mock the guzzle client interface, the SecurityAdvisoriesFetcher throws an error like
TypeError: Argument 3 passed to Drupal\system\SecurityAdvisories\SecurityAdvisoriesFetcher::__construct() must be an instance of GuzzleHttp\Client, instance of Mock_ClientInterface_f0228a1b given
Steps to reproduce
Create a Kernel test that sets the http_client service to a mocked object using a GuzzleHttp\ClientInterface::class. For example,
$guzzle = $this->createMock(ClientInterface::class);
$guzzle->method('request')->will($this->returnCallback([
$this,
'guzzleCallback',
]));
\Drupal::getContainer()->set('http_client', $guzzle);
Role::create(['label' => "Foo", 'id' => "foo"])->save();
Proposed resolution
Simply replace the constructor type hint to use ClientInterface instead of Client
Remaining tasks
Replace the Type Hint
User interface changes
None
API changes
None
Data model changes
None
Release notes snippet
Comments
Comment #3
pookmish commentedComment #4
longwaveWe always use interfaces where possible, this is just an oversight in the original patch.
Comment #5
alexpottI merged this as part of #3222168: Replace \GuzzleHttp\Client with \GuzzleHttp\ClientInterface. These shouldn't have been separate issues. It's the same problem - a constructor not using an available interface. I credited @pookmish on that issue.