From 5637aff4ae16d3176e44d7fe84b998e8d8b6315c Mon Sep 17 00:00:00 2001 From: Alex Pott <alex.a.pott@googlemail.com> Date: Wed, 17 Apr 2024 16:55:34 +0100 Subject: [PATCH] Issue #3432867 by catch, Satane, quietone: Removed deprecated code in core/tests/Drupal/KernelTests --- .../tests/src/Kernel/FileSaveUploadTest.php | 4 ++- .../Core/Entity/EntityDeprecationTest.php | 25 -------------- .../Core/Entity/EntityKernelTestBase.php | 21 ------------ .../Core/Test/TestSetupTraitTest.php | 34 ------------------- .../Drupal/KernelTests/KernelTestBase.php | 25 +++----------- .../Drupal/KernelTests/KernelTestBaseTest.php | 27 --------------- 6 files changed, 7 insertions(+), 129 deletions(-) delete mode 100644 core/tests/Drupal/KernelTests/Core/Entity/EntityDeprecationTest.php delete mode 100644 core/tests/Drupal/KernelTests/Core/Test/TestSetupTraitTest.php diff --git a/core/modules/file/tests/src/Kernel/FileSaveUploadTest.php b/core/modules/file/tests/src/Kernel/FileSaveUploadTest.php index cffbdfbcb909..4cb54f8ed710 100644 --- a/core/modules/file/tests/src/Kernel/FileSaveUploadTest.php +++ b/core/modules/file/tests/src/Kernel/FileSaveUploadTest.php @@ -9,6 +9,8 @@ use Symfony\Component\HttpFoundation\File\UploadedFile; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; +use Symfony\Component\HttpFoundation\Session\Session; +use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; /** * Tests file_save_upload(). @@ -45,7 +47,7 @@ protected function setUp(): void { test: TRUE ), ]); - + $request->setSession(new Session(new MockArraySessionStorage())); $requestStack = new RequestStack(); $requestStack->push($request); diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityDeprecationTest.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityDeprecationTest.php deleted file mode 100644 index 521cc352bb58..000000000000 --- a/core/tests/Drupal/KernelTests/Core/Entity/EntityDeprecationTest.php +++ /dev/null @@ -1,25 +0,0 @@ -<?php - -declare(strict_types=1); - -namespace Drupal\KernelTests\Core\Entity; - -/** - * Tests the deprecations for the \Drupal\KernelTests\Core\Entity namespace. - * - * @group Entity - * @group legacy - */ -class EntityDeprecationTest extends EntityKernelTestBase { - - /** - * Tests deprecation of \Drupal\KernelTests\Core\Entity\EntityKernelTestBase::createUser(). - */ - public function testCreateUserDeprecation(): void { - $this->expectDeprecation('Calling createUser() with $values as the first parameter is deprecated in drupal:10.1.0 and will be removed from drupal:11.0.0. Use createUser(array $permissions = [], $name = NULL, $admin = FALSE, array $values = []) instead. See https://www.drupal.org/node/3330762'); - $this->createUser(['uid' => 2]); - $this->expectDeprecation('Calling createUser() with $permissions as the second parameter is deprecated in drupal:10.1.0 and will be removed from drupal:11.0.0. Use createUser(array $permissions = [], $name = NULL, $admin = FALSE, array $values = []) instead. See https://www.drupal.org/node/3330762'); - $this->createUser([], ['administer entity_test content']); - } - -} diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityKernelTestBase.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityKernelTestBase.php index ab3df7c6c899..a283140ef64e 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/EntityKernelTestBase.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityKernelTestBase.php @@ -109,27 +109,6 @@ protected function setUp(): void { * The created user entity. */ protected function createUser(array $permissions = [], $name = NULL, bool $admin = FALSE, array $values = []) { - // Allow for the old signature of this method: - // createUser($values = [], $permissions = []) - if (!array_is_list($permissions)) { - // An array with keys is assumed to be entity values rather than - // permissions, since there is no point in an array of permissions having - // keys. - @trigger_error('Calling createUser() with $values as the first parameter is deprecated in drupal:10.1.0 and will be removed from drupal:11.0.0. Use createUser(array $permissions = [], $name = NULL, $admin = FALSE, array $values = []) instead. See https://www.drupal.org/node/3330762', E_USER_DEPRECATED); - - $values = $permissions; - $permissions = []; - } - - if (is_array($name)) { - // If $name is an array rather than a string, then the caller is intending - // to pass in $permissions. - @trigger_error('Calling createUser() with $permissions as the second parameter is deprecated in drupal:10.1.0 and will be removed from drupal:11.0.0. Use createUser(array $permissions = [], $name = NULL, $admin = FALSE, array $values = []) instead. See https://www.drupal.org/node/3330762', E_USER_DEPRECATED); - - $permissions = $name; - $name = NULL; - } - return $this->drupalCreateUser($permissions, $name, $admin, $values); } diff --git a/core/tests/Drupal/KernelTests/Core/Test/TestSetupTraitTest.php b/core/tests/Drupal/KernelTests/Core/Test/TestSetupTraitTest.php deleted file mode 100644 index a7e5b589c948..000000000000 --- a/core/tests/Drupal/KernelTests/Core/Test/TestSetupTraitTest.php +++ /dev/null @@ -1,34 +0,0 @@ -<?php - -declare(strict_types=1); - -namespace Drupal\KernelTests\Core\Test; - -use Drupal\Core\Test\TestSetupTrait; -use Drupal\KernelTests\KernelTestBase; - -/** - * Tests the TestSetupTrait trait. - * - * @coversDefaultClass \Drupal\Core\Test\TestSetupTrait - * @group Testing - * - * Run in a separate process as this test involves Database statics and - * environment variables. - * @runTestsInSeparateProcesses - * @preserveGlobalState disabled - */ -class TestSetupTraitTest extends KernelTestBase { - - use TestSetupTrait; - - /** - * @covers ::getDatabaseConnection - * @group legacy - */ - public function testGetDatabaseConnection(): void { - $this->expectDeprecation('Drupal\Core\Test\TestSetupTrait::getDatabaseConnection is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. There is no replacement. See https://www.drupal.org/node/3176816'); - $this->assertNotNull($this->getDatabaseConnection()); - } - -} diff --git a/core/tests/Drupal/KernelTests/KernelTestBase.php b/core/tests/Drupal/KernelTests/KernelTestBase.php index 6d9d416bd0b7..56b913432bdc 100644 --- a/core/tests/Drupal/KernelTests/KernelTestBase.php +++ b/core/tests/Drupal/KernelTests/KernelTestBase.php @@ -39,7 +39,6 @@ use Symfony\Component\Routing\Route; use Symfony\Component\VarDumper\VarDumper; use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; -use Symfony\Component\HttpFoundation\Exception\SessionNotFoundException; /** * Base class for functional integration tests. @@ -270,17 +269,6 @@ protected function setUp(): void { $this->bootKernel(); } - /** - * {@inheritdoc} - */ - public function __get(string $name) { - if ($name === 'randomGenerator') { - @trigger_error('Accessing the randomGenerator property is deprecated in drupal:10.2.0 and is removed from drupal:11.0.0. Use getRandomGenerator() instead. See https://www.drupal.org/node/3358445', E_USER_DEPRECATED); - - return $this->getRandomGenerator(); - } - } - /** * Bootstraps a basic test environment. * @@ -687,15 +675,10 @@ protected function assertPostConditions(): void { protected function tearDown(): void { if ($this->container) { // Clean up mock session started in DrupalKernel::preHandle(). - try { - /** @var \Symfony\Component\HttpFoundation\Session\Session $session */ - $session = $this->container->get('request_stack')->getSession(); - $session->clear(); - $session->save(); - } - catch (SessionNotFoundException) { - @trigger_error('Pushing requests without a session onto the request_stack is deprecated in drupal:10.3.0 and an error will be thrown from drupal:11.0.0. See https://www.drupal.org/node/3337193', E_USER_DEPRECATED); - } + /** @var \Symfony\Component\HttpFoundation\Session\Session $session */ + $session = $this->container->get('request_stack')->getSession(); + $session->clear(); + $session->save(); } // Destroy the testing kernel. diff --git a/core/tests/Drupal/KernelTests/KernelTestBaseTest.php b/core/tests/Drupal/KernelTests/KernelTestBaseTest.php index d13ebd9ddccb..fe71a5b2d1d5 100644 --- a/core/tests/Drupal/KernelTests/KernelTestBaseTest.php +++ b/core/tests/Drupal/KernelTests/KernelTestBaseTest.php @@ -5,14 +5,12 @@ namespace Drupal\KernelTests; use Drupal\Component\FileCache\FileCacheFactory; -use Drupal\Component\Utility\Random; use Drupal\Core\Database\Database; use Drupal\Tests\StreamCapturer; use Drupal\user\Entity\Role; use org\bovigo\vfs\vfsStream; use org\bovigo\vfs\visitor\vfsStreamStructureVisitor; use Psr\Http\Client\ClientExceptionInterface; -use Symfony\Component\HttpFoundation\Request; /** * @coversDefaultClass \Drupal\KernelTests\KernelTestBase @@ -254,18 +252,6 @@ public function testSessionOnRequest(): void { $this->assertEquals('do-cleanup', $session->remove('some-other-val')); } - /** - * Tests deprecation of modified request stack lacking a session. - * - * @covers ::tearDown - * - * @group legacy - */ - public function testDeprecatedSessionMissing(): void { - $this->expectDeprecation('Pushing requests without a session onto the request_stack is deprecated in drupal:10.3.0 and an error will be thrown from drupal:11.0.0. See https://www.drupal.org/node/3337193'); - $this->container->get('request_stack')->push(Request::create('/')); - } - /** * Tests the assumption that local time is in 'Australia/Sydney'. */ @@ -341,17 +327,4 @@ public function testDatabaseDriverModuleEnabled() { $this->assertSame(1, \Drupal::service('extension.list.module')->get($module)->status); } - /** - * Tests the deprecation of accessing the randomGenerator property directly. - * - * @group legacy - */ - public function testGetRandomGeneratorPropertyDeprecation() { - $this->expectDeprecation('Accessing the randomGenerator property is deprecated in drupal:10.2.0 and is removed from drupal:11.0.0. Use getRandomGenerator() instead. See https://www.drupal.org/node/3358445'); - // We purposely test accessing an undefined property here. We need to tell - // PHPStan to ignore that. - // @phpstan-ignore-next-line - $this->assertInstanceOf(Random::class, $this->randomGenerator); - } - } -- GitLab