Normally with Drupal 8 I can use dependency injection like this:
<?php
class ExampleController extends ControllerBase {
private $http_client;
public function __construct(HttpClient $http_client) {
$this->http_client = $http_client;
}
public function create(ContainerInterface $container) {
$http_client = $container->get('http_client');
}
public function getResource() {
$response = $this->http_client->get('http://biebertunes.com?q=selena');
return $response->getBody();
}
}
I can then use the $http_client property's methods.
Now in my testing class I'm already extending the UnitTestCase class, so I don't have access to the create method for dependency injection.
<?php
class ExampleTest extends UnitTestCase {
public function testGetResource() {
$mock = $this->getMock('\Drupal\Example\ExampleController');
}
}
Now when I run my unit tests it complains that I don't have the $http_client parameter. So how can I inject $http_client into the unit test without the create method?