Problem/Motivation

I'm getting the following error when running ExistingSite tests using the weitzman/drupal-test-traits project. It's phpunit stuff but using a real database.

RuntimeException: Case mismatch between loaded and declared class names: "Drupal\viewsreference\ViewsreferenceServiceProvider" vs "Drupal\viewsreference\ViewsReferenceServiceProvider".

There does not appear to be any problems with the functionality on the site, so this may really be a bug with drupal-test-traits or maybe with something else. But I found the following reference as I was digging:

Note that if you want this service alteration to be recognized automatically, the name of this class is required to be a CamelCase version of your module's machine name followed by ServiceProvider

(see https://www.drupal.org/docs/drupal-apis/services-and-dependency-injectio...)

Steps to reproduce

TBD

Proposed resolution

Modify name of service file and class to follow naming conventions outlined in the provided link. Make that R lowercase:

ViewsReferenceServiceProvider.php => ViewsreferenceServiceProvider.php
ViewsReferenceServiceProvider => ViewsreferenceServiceProvider

Remaining tasks

Determine whether this is a bug in viewsreference or in a different project (drupal-test-traits or my custom code, etc.).

User interface changes

None.

API changes

TBD

Data model changes

None.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

danflanagan8 created an issue. See original summary.

sam152’s picture

Status: Active » Reviewed & tested by the community

I believe this is a bug in the viewsreference module. Here is a snippet of code from DrupalKernel:

    // Load each module's serviceProvider class.
    foreach ($module_filenames as $module => $filename) {
      $camelized = ContainerBuilder::camelize($module);
      $name = "{$camelized}ServiceProvider";
      $class = "Drupal\\{$module}\\{$name}";
      if (class_exists($class)) {
        $this->serviceProviderClasses['app'][$module] = $class;
      }
      $filename = dirname($filename) . "/$module.services.yml";
      if (file_exists($filename)) {
        $this->serviceYamls['app'][$module] = $filename;
      }
    }

You can see it expects a camelized version of the module name, which in this case, since there is no underscore in the module name would be "Viewsreference".

It just so happens the DebugClassLoader used by symfony and Drupal to check deprecations during testing has additional checks for when class capitalisation is incorrect:

            if ($name !== $class && 0 === strcasecmp($name, $class)) {
                throw new \RuntimeException(sprintf('Case mismatch between loaded and declared class names: "%s" vs "%s".', $class, $name));
            }

Fix looks good to me.

seanB made their first commit to this issue’s fork.

seanb’s picture

Status: Reviewed & tested by the community » Fixed

Merged! Thanks for the extra explanation @Sam152.

seanb’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

johan_vm’s picture

Currently I have the same issue in the latest release branch (8.x-2.x-beta2). Since beta3 is not (yet) released we have to make due with a patch.

johan_vm’s picture

StatusFileSize
new496 bytes
johan_vm’s picture

johan_vm’s picture

StatusFileSize
new494 bytes