Commit e434d61d authored by catch's avatar catch
Browse files

Issue #3081646 by Spokje, mallezie, richardbporter, VladimirAus, RoSk0: Follow...

Issue #3081646 by Spokje, mallezie, richardbporter, VladimirAus, RoSk0: Follow up for "Adding Assertions to Drupal - Test Tools"
parent de20700e
Loading
Loading
Loading
Loading
+1 −4
Original line number Diff line number Diff line
@@ -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();

+3 −7
Original line number Diff line number Diff line
@@ -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 {
    assert(!$this->validationRequired || $this->validated, 'Entity validation was skipped.');

    $this->validated = FALSE;
    }

    parent::preSave($storage);
  }
+4 −12
Original line number Diff line number Diff line
@@ -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);
      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);
      }
      else {
        throw new \InvalidArgumentException('You must provide the context IDs in the @{service_id}:{unqualified_context_id} format.');
      }
      $context_ids_by_service[$service_id][] = $unqualified_context_id;
    }

+1 −4
Original line number Diff line number Diff line
@@ -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);
+1 −1
Original line number Diff line number Diff line
@@ -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;
Loading