Unverified Commit 7769a956 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3517614 by alexpott, longwave, cmlara, catch, quietone, mstrelan:...

Issue #3517614 by alexpott, longwave, cmlara, catch, quietone, mstrelan: Possible Non GPLv2 compatible code in ExpectDeprecationTrait

(cherry picked from commit 405ac9da)
parent bb1a18b7
Loading
Loading
Loading
Loading
Loading
+1 −41
Original line number Diff line number Diff line
@@ -63,10 +63,7 @@ public function tearDownErrorHandler(): void {
    // restored during ::tearDown().
    $handler = Error::currentErrorHandler();
    if (!$handler instanceof TestErrorHandler) {
      throw new \RuntimeException(sprintf('%s registered its own error handler (%s) without restoring the previous one before or during tear down. This can cause unpredictable test results. Ensure the test cleans up after itself.',
        $this->name(),
        self::getCallableName($handler),
      ));
      throw new \RuntimeException(sprintf('%s registered its own error handler without restoring the previous one before or during tear down. This can cause unpredictable test results. Ensure the test cleans up after itself.', $this->name()));
    }
    restore_error_handler();

@@ -97,41 +94,4 @@ public function expectDeprecation(string $message): void {
    DeprecationHandler::expectDeprecation($message);
  }

  /**
   * Returns a callable as a string suitable for inclusion in a message.
   *
   * @param callable $callable
   *   The callable.
   *
   * @return string
   *   The string suitable for inclusion in a message.
   *
   * @see https://stackoverflow.com/questions/34324576/print-name-or-definition-of-callable-in-php
   */
  private static function getCallableName(callable $callable): string {
    switch (TRUE) {
      case is_string($callable) && strpos($callable, '::'):
        return '[static] ' . $callable;

      case is_string($callable):
        return '[function] ' . $callable;

      case is_array($callable) && is_object($callable[0]):
        return '[method] ' . get_class($callable[0]) . '->' . $callable[1];

      case is_array($callable):
        return '[static] ' . $callable[0] . '::' . $callable[1];

      case $callable instanceof \Closure:
        return '[closure]';

      case is_object($callable):
        return '[invokable] ' . get_class($callable);

      default:
        return '[unknown]';

    }
  }

}