flushAlteredCodeToFile example

    // \Drupal\Core\Test\TestDiscovery::registerTestNamespaces() necessitates     // this protection.     if (class_exists('PHPUnit\Framework\Assert', FALSE)) {
      return;
    }
    // Mutate Assert code to make it forward compatible with different PhpUnit     // versions, by adding Symfony's PHPUnit-bridge PolyfillAssertTrait.     $alteredFile = $autoloader->findFile('PHPUnit\Framework\Assert');
    $phpunit_dir = dirname($alteredFile, 3);
    $alteredCode = file_get_contents($alteredFile);
    $alteredCode = preg_replace('/abstract class Assert[^\{]+\{/', '$0 ' . \PHP_EOL . " use \Symfony\Bridge\PhpUnit\Legacy\PolyfillAssertTrait;" . \PHP_EOL, $alteredCode, 1);
    include static::flushAlteredCodeToFile('Assert.php', $alteredCode);
  }

  /** * Alters the TestCase class. * * @param \Composer\Autoload\ClassLoader $autoloader * The autoloader. * * @throws \ReflectionException */
  private static function alterTestCase(ClassLoader $autoloader): void {
    
Home | Imprint | This part of the site doesn't use cookies.