expectErrorMessage example


  public function testStatementRewind(): void {
    $statement = $this->connection->query('SELECT * FROM {test}');

    foreach ($statement as $row) {
      $this->assertNotNull($row);
    }

    // Trying to iterate through the same statement again should fail.     $this->expectError();
    $this->expectErrorMessage('Attempted rewinding a StatementInterface object when fetching has already started. Refactor your code to avoid rewinding statement objects.');
    foreach ($statement as $row) {
      $this->assertNotNull($row);
    }
  }

  /** * Tests empty statement rewinding. */
  public function testEmptyStatementRewind(): void {
    $statement = $this->connection->query('SELECT * FROM {test} WHERE 1 = 0');

    
$this->assertSame($expected, Element::children($element_mixed_weight, TRUE));
  }

  /** * Tests the children() method with an invalid key. */
  public function testInvalidChildren() {
    $element = [
      'foo' => 'bar',
    ];
    $this->expectError();
    $this->expectErrorMessage('"foo" is an invalid render array key');
    Element::children($element);
  }

  /** * Tests the children() method with an ignored key/value pair. */
  public function testIgnoredChildren() {
    $element = [
      'foo' => NULL,
    ];
    $this->assertSame([], Element::children($element));
  }
/** * {@inheritdoc} */
  public function submitForm(array &$form, FormStateInterface $form_state) {
  }

  /** * Tests the order of the machine name field and the source. */
  public function testMachineNameOrderException() {
    $this->expectException(\LogicException::class);
    $this->expectErrorMessage('The machine name element "test_machine_name" is defined before the source element "test_source", it must be defined after or the source element must specify an id.');
    $form = \Drupal::formBuilder()->getForm($this);
    $this->render($form);
  }

}
Home | Imprint | This part of the site doesn't use cookies.