@param bool $expectedState

@throws \RuntimeException
765444
private function assertCheckboxState(NodeElement $toggleableElement, $expectedState)
    {
        if ($toggleableElement->isChecked() !== $expectedState) {
            throw new \RuntimeException(sprintf(
                "Toggleable element state is '%s' but expected '%s'.",
                $toggleableElement->isChecked() ? 'true' : 'false',
                $expectedState ? 'true' : 'false'
            ));
        }
    }
1229013
protected function raiseMismatch($expectedType)
    {
        $value = $this->value;

        if (is_object($value)) {
            $value = get_class($value);
        } elseif (is_array($value)) {
            $value = implode(',', $value);
        }

        throw new CastingMismatchException(sprintf(self::MISMATCH_MESSAGE, $value, $expectedType));
    }
1253830
public function hasRole($expectedRole, $providedRoles = null) {
		if ($providedRoles !== null) {
			$roles = (array)$providedRoles;
		} else {
			$roles = $this->roles();
		}

		if (!$roles) {
			return false;
		}

		if (array_key_exists($expectedRole, $roles) || in_array($expectedRole, $roles)) {
			return true;
		}
		return false;
	}
348422
public function createMockConfig(MockConfig $expectation)
    {
        $uri = $this->createBaseUri()->withPath(self::API_EXPECTATIONS_URL);
        // TODO: Add converter from expectation to array
        $body = @json_encode($expectation);
        if (false === $body) {
            throw new \RuntimeException('Error generating json body for request: ' . json_last_error_msg());
        }
        $request = (new PsrRequest())
            ->withUri($uri)
            ->withMethod('post')
            ->withHeader('Content-Type', 'application/json')
            ->withBody(new StringStream($body));
        $this->ensureIsNotErrorResponse($this->connection->send($request));
    }
471785
private function checkStatus($expectedStatus)
    {
        $status = $this->response->getStatusCode();
        
        if ($status != $expectedStatus) {
            throw new EndpointException("Unexpected HTTP status {$status} " . $this->response->getReasonPhrase());
        }
    }
171760
public function assertHasHeader(string $expected)
    {
        $actual = $this->getHeaderText();
        if ($expected === $actual) {
            return;
        }

        throw new ExpectationException(
            sprintf(
                '[W402] Expected screen header "%1$s", found "%2$s".',
                $expected,
                $actual
            ),
            $this->getDriver()
        );
    }
685556
public synchronized void checkState(State requiredState) throws IllegalStateException {
        if (requiredState != currentState) {
            throw new IllegalStateException(String.format(Locale.US,
                    "Expected state %s, but in state %s", requiredState, currentState));
        }
    }
733118
public function verify()
    {
        if ($this->groupIndex < $this->sequenceIndex) {
            throw new PHPUnit_Framework_ExpectationFailedException(
              sprintf(
                "The expected invocation at method '%s' group-index %d was never reached.",

                $this->method,
                $this->sequenceIndex
              )
            );
        }
    }
242275
protected function verifyPage()
    {
        $url = $this->getSession()->getCurrentUrl();

        if (strrpos($url, $this->path) !== false) {
            return;
        }

        throw new ExpectationException(
            sprintf(
                '[W401] Expected screen is the wp-admin dashboard, instead on "%1$s".',
                $url
            ),
            $this->getDriver()
        );
    }
410682
protected function validateScenarioStateOrThrowException(
        Expectation $expectation,
        LoggerInterface $logger
    ) {
        if ($expectation->getNewScenarioState() && !$expectation->getScenarioStateIs()) {
            $logger->error('Scenario states misconfiguration');
            throw new \RuntimeException(
                'Trying to set scenario state without specifying scenario previous state'
            );
        }
    }
222651
public function seeInEmailTextBody($expected)
    {
        $email = $this->fetchLastMessage();
        $this->assertContains($expected, $email->text_body, 'Email body contains text');
    }
1259520
protected function _ensureReadable($bytePerByte = true)
    {
        if (!$this->valid()) {
            throw new RuntimeException('Cannot read from a closed stream.');
        }
        if (!$this->isReadable()) {
            $mode = $this->meta('mode');
            throw new RuntimeException("Cannot read on a non-readable stream (mode is `'{$mode}'`).");
        }
    }
298427
private function runRunnable($runnable)
    {
        if (!$runnable) return;

        $runnable->run();
        if ($runnable->getException()) {
            self::$console->setExitStatus(1);
            if (self::$console->options['stop']) {
                $this->reporter->afterRun();
                exit(1);
            }
        }
    }
962392
static function assertEqualIterable(iterable $expected, $actual, string $message = ''): void
    {
        static::assertThat($actual, static::equalIterable($expected), $message);
    }
825688
public static function InvalidTypeException($expectedType, $key, $value) {
        throw new InvalidTypeException($expectedType, $key, is_array($value) ? serialize($value) : $value);
    }
628514
public function assertRolesExist(TableNode $expected) {
    $role_info = [];
    /** @var \Drupal\user\Entity\Role[] $roles */
    $roles = $this->entityTypeManager()
      ->getStorage('user_role')
      ->loadMultiple();
    foreach ($roles as $id => $role) {
      $role_info[] = [$role->label(), $id];
    }
    $actual = new TableNode($role_info);

    (new TableEqualityAssertion($expected, $actual))
      ->expectHeader(['Name', 'Machine name'])
      ->ignoreRowOrder()
      ->setMissingRowsLabel(self::missingRowsLabelFor('roles'))
      ->setUnexpectedRowsLabel(self::unexpectedRowsLabelFor('roles'))
      ->assert();
  }
1339561
public function checkConnection( $checkResource = TRUE, $checkAuthentication = TRUE )
	{
		if( $checkResource && !$this->resource )
			throw new RuntimeException( "No Connection to FTP Server established" );
		if( $checkAuthentication && !$this->auth )
			throw new RuntimeException( "Not authenticated onto FTP Server" );
	}