You are here

private static function ClassWriter::flushAlteredCodeToFile in Drupal 9

Flushes altered class code to file when necessary.

Parameters

string $file_name: The file name.

string $altered_code: The altered code.

Return value

string The full path of the file to be included.

2 calls to ClassWriter::flushAlteredCodeToFile()
ClassWriter::alterAssert in core/tests/Drupal/TestTools/PhpUnitCompatibility/PhpUnit8/ClassWriter.php
Alters the Assert class.
ClassWriter::alterTestCase in core/tests/Drupal/TestTools/PhpUnitCompatibility/PhpUnit8/ClassWriter.php
Alters the TestCase class.

File

core/tests/Drupal/TestTools/PhpUnitCompatibility/PhpUnit8/ClassWriter.php, line 105

Class

ClassWriter
Helper class to rewrite PHPUnit's TestCase class.

Namespace

Drupal\TestTools\PhpUnitCompatibility\PhpUnit8

Code

private static function flushAlteredCodeToFile(string $file_name, string $altered_code) : string {
  $directory = __DIR__ . '/../../../../../../sites/simpletest';
  $full_path = $directory . '/' . $file_name;

  // Only write when necessary.
  if (!file_exists($full_path) || md5_file($full_path) !== md5($altered_code)) {

    // Create directory when necessary.
    if (!file_exists($directory)) {
      mkdir($directory, 0777, TRUE);
    }
    file_put_contents($full_path, $altered_code);
  }
  return $full_path;
}