I'm running a functional test that extends the ResourceTestBase however it is throwing the following error:
ServiceNotFoundException: The service "cache_tags.invalidator.checksum" has a dependency on a non-existent service "redis.factory".
the module i'm testing has a dependency on redis and i have included the line:
protected static $modules = ['user', 'rest', 'redis'];
In my class but I still get this error.
my test class:
<?php
namespace Drupal\Tests\my_module\Functional\Rest;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Url;
use Drupal\Tests\rest\Functional\ResourceTestBase;
use GuzzleHttp\RequestOptions;
use Psr\Http\Message\ResponseInterface;
/**
* Tests creation of a user using REST.
*
* @group my_module
*/
class myUserCreateTest extends ResourceTestBase {
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
protected static $auth = 'basic_auth';
/**
* {@inheritdoc}
*/
protected static $modules = ['user', 'rest', 'redis'];
/**
* {@inheritdoc}
*/
public function setUp(): void {
parent::setUp();
$auth = isset(static::$auth) ? [static::$auth] : [];
$this->provisionResource([static::$format], $auth);
$this->setUpAuthorization('POST');
}
/**
* Tests user creation
*/
public function testCreateUser() {
$create_user_url = Url::fromUserInput('/my-api/my_module/create')
->setRouteParameter('_format', static::$format);
$request_body = [
"mail" => "[email protected]",
"custom_id" => "12345",
];
$request_options = $this->getAuthenticationRequestOptions('POST');
$request_options[RequestOptions::BODY] = $this->serialize->encode($request_body, static::$format);
$request_options[RequestOptions::HEADERS]['Content-Type'] = static::$mimeType;
$response = $this->request('POST', $create_user_url, $request_options);
print_r($response);
$this->assertResourceResponse(200, FALSE, $response);
}
/**
* {@inheritdoc}
*/
protected function setUpAuthorization($method) {
switch ($method) {
case 'POST':
$this->grantPermissionsToAuthenticatedRole(['restful post create']);
break;
default:
throw new \UnexpectedValueException();
}
}
/**
* {@inheritdoc}
*/
protected function getExpectedUnauthorizedAccessCacheability() {
return new CacheableMetadata();
}
/**
* {@inheritdoc}
*/
protected function assertAuthenticationEdgeCases($method, Url $url, array $request_options) {
}
/**
* {@inheritdoc}
*/
protected function assertNormalizationEdgeCases($method, Url $url, array $request_options) {
}
/**
* {@inheritdoc}
*/
protected function assertResponseWhenMissingAuthentication($method, ResponseInterface $response) {
}
}
setUp
method, does it callparent::setUp()
? Also, please provide an entire minimal test class that exhibits this issue.