Kernel tests can't use path aliases on entities

Created on 13 October 2023, about 1 year ago
Updated 10 January 2024, 10 months ago

Problem/Motivation

In #2336597: Convert path aliases to full featured entities we added a BC layer to kernel tests that removes path_processor_inbound and path_processor_outbound tags from the path_alias.path_processor definition. This is a great source of confusion when writing kernel tests that rely on path aliases.

Steps to reproduce

Write a kernel test as per the MR that boils down to this:

EntityTest::create(['id' => 1])->save();
$this->createPathAlias('/entity_test/1', '/entity-alias');
$entity = EntityTest::load(1);
$this->assertSame('/entity-alias', $entity->toUrl()->toString());

Watch it fail.

Remove this from KernelTestBase::register

if ($container->hasDefinition('path_alias.path_processor')) {
  // The alias-based processor requires the path_alias entity schema to be
  // installed, so we prevent it from being registered to the path processor
  // manager. We do this by removing the tags that the compiler pass looks
  // for. This means that the URL generator can safely be used within tests.
  $container->getDefinition('path_alias.path_processor')
    ->clearTag('path_processor_inbound')
    ->clearTag('path_processor_outbound');
}

Watch it pass.

Proposed resolution

Remove code that disabled path processing, ensure tests that use path alias install its schema.

See #10 for the history.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

🐛 Bug report
Status

Fixed

Version

11.0 🔥

Component
PHPUnit 

Last updated 5 minutes ago

Created by

🇦🇺Australia mstrelan

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024