2

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) {

  }

}
2
  • 1
    If you have a setUp method, does it call parent::setUp()? Also, please provide an entire minimal test class that exhibits this issue.
    – mona lisa
    Commented Jul 21, 2022 at 23:24
  • yes thats the very first thing i do in the setUp method.
    – Rick
    Commented Jul 22, 2022 at 12:53

1 Answer 1

2

It turns out I had to comment out the redis configuration settings in settings.php.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.