diff --git a/core/lib/Drupal/Core/Ajax/AjaxResponseAttachmentsProcessor.php b/core/lib/Drupal/Core/Ajax/AjaxResponseAttachmentsProcessor.php index b1b04bfe92d04d305facd63cdbc825d8bf4891a0..3936ce8fe0db7f55ec5ccf61b0386bd3ee4312fe 100644 --- a/core/lib/Drupal/Core/Ajax/AjaxResponseAttachmentsProcessor.php +++ b/core/lib/Drupal/Core/Ajax/AjaxResponseAttachmentsProcessor.php @@ -109,10 +109,7 @@ public function __construct(AssetResolverInterface $asset_resolver, ConfigFactor * {@inheritdoc} */ public function processAttachments(AttachmentsInterface $response) { - // @todo Convert to assertion once https://www.drupal.org/node/2408013 lands - if (!$response instanceof AjaxResponse) { - throw new \InvalidArgumentException('\Drupal\Core\Ajax\AjaxResponse instance expected.'); - } + assert($response instanceof AjaxResponse, '\Drupal\Core\Ajax\AjaxResponse instance expected.'); $request = $this->requestStack->getCurrentRequest(); diff --git a/core/lib/Drupal/Core/Entity/ContentEntityBase.php b/core/lib/Drupal/Core/Entity/ContentEntityBase.php index 75dd42564b2b8edd7f57fd3d8d4f7f92c0481a30..7521601cd58a4c85587940cc12c9947d75f8acc7 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityBase.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityBase.php @@ -439,13 +439,9 @@ public function isTranslatable() { public function preSave(EntityStorageInterface $storage) { // An entity requiring validation should not be saved if it has not been // actually validated. - if ($this->validationRequired && !$this->validated) { - // @todo Make this an assertion in https://www.drupal.org/node/2408013. - throw new \LogicException('Entity validation was skipped.'); - } - else { - $this->validated = FALSE; - } + assert(!$this->validationRequired || $this->validated, 'Entity validation was skipped.'); + + $this->validated = FALSE; parent::preSave($storage); } diff --git a/core/lib/Drupal/Core/Plugin/Context/LazyContextRepository.php b/core/lib/Drupal/Core/Plugin/Context/LazyContextRepository.php index 68c7d6ffaa9ededc8aae18f6f5990b043a18aabb..21d3adc6e6108852501a3d8039f3a42b6125e218 100644 --- a/core/lib/Drupal/Core/Plugin/Context/LazyContextRepository.php +++ b/core/lib/Drupal/Core/Plugin/Context/LazyContextRepository.php @@ -58,18 +58,10 @@ public function getRuntimeContexts(array $context_ids) { $contexts[$id] = $this->contexts[$id]; continue; } - // The IDs have been passed in @{service_id}:{unqualified_context_id} - // format. - // @todo Convert to an assert once https://www.drupal.org/node/2408013 is - // in. - if ($id[0] === '@' && strpos($id, ':') !== FALSE) { - [$service_id, $unqualified_context_id] = explode(':', $id, 2); - // Remove the leading '@'. - $service_id = substr($service_id, 1); - } - else { - throw new \InvalidArgumentException('You must provide the context IDs in the @{service_id}:{unqualified_context_id} format.'); - } + assert($id[0] === '@' && strpos($id, ':'), 'You must provide the context IDs in the @{service_id}:{unqualified_context_id} format.'); + list($service_id, $unqualified_context_id) = explode(':', $id, 2); + // Remove the leading '@'. + $service_id = substr($service_id, 1); $context_ids_by_service[$service_id][] = $unqualified_context_id; } diff --git a/core/lib/Drupal/Core/Render/Renderer.php b/core/lib/Drupal/Core/Render/Renderer.php index b6ff24a41e06c3932b19d54e4864908c63f927df..019a2c133fdb8ca05a894e6d03b7ac75488f9af4 100644 --- a/core/lib/Drupal/Core/Render/Renderer.php +++ b/core/lib/Drupal/Core/Render/Renderer.php @@ -580,10 +580,7 @@ public function executeInRenderContext(RenderContext $context, callable $callabl // Set the provided context and call the callable, it will use that context. $this->setCurrentRenderContext($context); $result = $callable(); - // @todo Convert to an assertion in https://www.drupal.org/node/2408013 - if ($context->count() > 1) { - throw new \LogicException('Bubbling failed.'); - } + assert($context->count() <= 1, 'Bubbling failed.'); // Restore the original render context. $this->setCurrentRenderContext($previous_context); diff --git a/core/modules/system/tests/modules/entity_test/src/EntityTestForm.php b/core/modules/system/tests/modules/entity_test/src/EntityTestForm.php index 3ea354d54993f929c25c1b625660fdd96896582f..4ec687aacd96c055e3a809535c20f98e62302e60 100644 --- a/core/modules/system/tests/modules/entity_test/src/EntityTestForm.php +++ b/core/modules/system/tests/modules/entity_test/src/EntityTestForm.php @@ -80,7 +80,7 @@ public function save(array $form, FormStateInterface $form_state) { $form_state->setRebuild(); } } - catch (\Exception $e) { + catch (\AssertionError $e) { \Drupal::state()->set('entity_test.form.save.exception', get_class($e) . ': ' . $e->getMessage()); } return $status ?? FALSE; diff --git a/core/modules/system/tests/src/Functional/Entity/EntityFormTest.php b/core/modules/system/tests/src/Functional/Entity/EntityFormTest.php index 7b1b0995ed5f21acaa2ee2c758967292612e659d..5cdb38fc18a9af7111d17d4d19f7813e9b0235d8 100644 --- a/core/modules/system/tests/src/Functional/Entity/EntityFormTest.php +++ b/core/modules/system/tests/src/Functional/Entity/EntityFormTest.php @@ -225,7 +225,7 @@ public function testValidationHandlers() { $state->set('entity_test.form.validate.test', 'button-level'); $this->drupalGet('entity_test/add'); $this->submitForm([], 'Save'); - $this->assertEquals('Drupal\\Core\\Entity\\EntityStorageException: Entity validation was skipped.', $state->get('entity_test.form.save.exception'), 'Button-level validation handlers behave correctly.'); + $this->assertEquals('AssertionError: Entity validation was skipped.', $state->get('entity_test.form.save.exception'), 'Button-level validation handlers behave correctly.'); } /** diff --git a/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php b/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php index f3060f6c38da4d86df365f7dd34325b7ac1a77bd..6ac67ace217ad40d21f58ecb768e1773b92e8073 100644 --- a/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php @@ -487,7 +487,7 @@ public function testRequiredValidation() { // that trying to save a non-validated entity when validation is required // results in an exception. $this->assertTrue($this->entity->isValidationRequired()); - $this->expectException(\LogicException::class); + $this->expectException(\AssertionError::class); $this->expectExceptionMessage('Entity validation was skipped.'); $this->entity->save(); } diff --git a/core/tests/Drupal/Tests/Core/Plugin/Context/LazyContextRepositoryTest.php b/core/tests/Drupal/Tests/Core/Plugin/Context/LazyContextRepositoryTest.php index 82bb5e192154efb44b8216f011e4f2c9e8f79589..a1b9c8012b1202deef48c6ef6776a770085115de 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/Context/LazyContextRepositoryTest.php +++ b/core/tests/Drupal/Tests/Core/Plugin/Context/LazyContextRepositoryTest.php @@ -69,7 +69,7 @@ public function testGetRuntimeMultipleContextProviders() { */ public function testInvalidContextId() { $lazy_context_repository = new LazyContextRepository($this->container, ['test_provider']); - $this->expectException(\InvalidArgumentException::class); + $this->expectException(\AssertionError::class); $this->expectExceptionMessage('You must provide the context IDs in the @{service_id}:{unqualified_context_id} format.'); $lazy_context_repository->getRuntimeContexts(['test_context', '@test_provider:test_context1']); }