After upgrading to Drupal 10 getting Error on Kernel test running: You have requested a non-existent service "path_alias.repository"

Created on 31 October 2023, over 1 year ago

I recently upgraded my site to Drupal 10.1 locally, I have managed to fix all other issues but getting the below error on one Kernel test case:

Drupal\Tests\custom_module\Kernel\CustomTest::testNormalizer Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException: You have requested a non-existent service "path_alias.repository".

🐛 Bug report
Status

Active

Version

10.1

Component
PHPUnit 

Last updated 1 day ago

Created by

🇮🇳India Ankita31

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

Comments & Activities

  • Issue created by @Ankita31
  • Issue was unassigned.
  • Status changed to Postponed: needs info over 1 year ago
  • 🇮🇳India Ankita31

    namespace Drupal\Tests\drupal_product_comparison\Kernel;

    use Drupal\file\Entity\File;
    use Drupal\image\Entity\ImageStyle;
    use Drupal\media\Entity\Media;
    use Drupal\drupal_products\Entity\Product;
    use Drupal\taxonomy\Entity\Term;
    use Drupal\Tests\drupal_products\Kernel\drupalProductTestBase;

    /**
    * Test product normalization.
    *
    * @group drupal_product_comparison
    */
    class ProductNormalizerTest extends drupalProductTestBase {

    /**
    * {@inheritdoc}
    */
    public static $modules = [
    'drupal_product_comparison',
    'drupal_new_content',
    'serialization',
    ];

    /**
    * {@inheritdoc}
    */
    protected function setUp(): void {
    parent::setUp();

    $this->installEntitySchema('drupal_product');
    $this->installEntitySchema('taxonomy_term');
    $this->installEntitySchema('file');
    $this->installEntitySchema('media');

    $this->installSchema('file', ['file_usage']);

    ImageStyle::create([
    'name' => 'comparison_panel_thumb',
    'label' => 'Compare thumb',
    ])->save();
    }

    /**
    * Test the product normalizer.
    */
    public function testNormalizer() {
    $brand = Term::create([
    'vid' => 'brand',
    'name' => 'Test Brand',
    ]);
    $file = File::create([
    'uri' => 'public://test.jpg',
    ]);
    $file->save();
    $media = Media::create([
    'bundle' => 'image',
    'field_media_image' => [
    'entity' => $file,
    ],
    ]);
    $media->save();

    ImageStyle::create([
    'name' => 'compare_thumb',
    'label' => 'Compare thumb',
    ])->save();

    $product = Product::create([
    'product_type' => 'test_type',
    'product_name' => 'Product 5',
    'brand' => ['entity' => $brand],
    'product_images' => ['entity' => $media],
    ]);
    $product->save();

    $url = ImageStyle::load('comparison_panel_thumb')->buildUrl($product->product_images[0]->entity->field_media_image->entity->getFileUri());
    $this->assertStringContainsString('files/styles/comparison_panel_thumb', $url);
    $this->assertStringContainsString('test.jpg', $url);

    $json = \json_encode([
    'id' => 1,
    'category' => 'Test Type',
    'title' => 'Product 5',
    'type' => 'Test Brand',
    'image' => $url,
    'new' => FALSE,
    ]);
    $this->assertEquals($json, $this->container->get('serializer')->serialize($product, 'json'));
    }

    }
    this is the code I pasted above and the path_alias module also enabled. This exaxtly same test passed on Drupal 9 but it throws the memtioned error on D10

  • Status changed to Active over 1 year ago
  • Status changed to Postponed: needs info over 1 year ago
  • That is one function. Show the entire test class for support.

  • Status changed to Closed: outdated 6 months ago
Production build 0.71.5 2024