setWorkingDirectory($this->root) ->setTimeout(300) ->setIdleTimeout(300); $process->run(); $this->assertEquals(0, $process->getExitCode(), 'COMMAND: ' . $process->getCommandLine() . "\n" . 'OUTPUT: ' . $process->getOutput() . "\n" . 'ERROR: ' . $process->getErrorOutput() . "\n"); $this->assertStringContainsString('HTML output was generated.', $process->getOutput()); $this->assertStringContainsString('Drupal_FunctionalTests_Test_FunctionalTestDebugHtmlOutputHelperTest', $process->getOutput()); // Test without verbose output, set in xml. $alteredConfigFile = $this->getAlteredPhpunitXmlConfigurationFile( '', '', ); $config = [ '--configuration', $alteredConfigFile, ]; $process = new Process(array_merge($command, $config)); $process->setWorkingDirectory($this->root) ->setTimeout(300) ->setIdleTimeout(300); $process->run(); $this->assertEquals(0, $process->getExitCode(), 'COMMAND: ' . $process->getCommandLine() . "\n" . 'OUTPUT: ' . $process->getOutput() . "\n" . 'ERROR: ' . $process->getErrorOutput() . "\n"); $this->assertMatchesRegularExpression('/HTML output was generated, \d+ page\(s\)\./m', $process->getOutput()); unlink($alteredConfigFile); // Test without verbose output, overridden by BROWSERTEST_OUTPUT_VERBOSE // environment variable. $config = [ '--configuration', 'core', ]; $process = new Process(array_merge($command, $config)); $process->setWorkingDirectory($this->root) ->setTimeout(300) ->setIdleTimeout(300); $process->run(NULL, [ 'BROWSERTEST_OUTPUT_VERBOSE' => 'false', ]); $this->assertEquals(0, $process->getExitCode(), 'COMMAND: ' . $process->getCommandLine() . "\n" . 'OUTPUT: ' . $process->getOutput() . "\n" . 'ERROR: ' . $process->getErrorOutput() . "\n"); $this->assertMatchesRegularExpression('/HTML output was generated, \d+ page\(s\)\./m', $process->getOutput()); // Test with a wrong output directory, set in xml. $alteredConfigFile = $this->getAlteredPhpunitXmlConfigurationFile( '', '', ); $config = [ '--configuration', $alteredConfigFile, ]; $process = new Process(array_merge($command, $config)); $process->setWorkingDirectory($this->root) ->setTimeout(300) ->setIdleTimeout(300); $process->run(NULL, [ 'BROWSERTEST_OUTPUT_DIRECTORY' => FALSE, ]); $this->assertEquals(0, $process->getExitCode(), 'COMMAND: ' . $process->getCommandLine() . "\n" . 'OUTPUT: ' . $process->getOutput() . "\n" . 'ERROR: ' . $process->getErrorOutput() . "\n"); $this->assertStringContainsString('HTML output directory can_we_assume_that_a_subdirectory_with_this_name_does_not_exist is not a writable directory.', $process->getOutput()); unlink($alteredConfigFile); // Test with a wrong output directory, overridden by // BROWSERTEST_OUTPUT_DIRECTORY environment variable. $config = [ '--configuration', 'core', ]; $process = new Process(array_merge($command, $config)); $process->setWorkingDirectory($this->root) ->setTimeout(300) ->setIdleTimeout(300); $process->run(NULL, [ 'BROWSERTEST_OUTPUT_DIRECTORY' => 'can_we_assume_that_a_subdirectory_with_this_name_does_not_exist', ]); $this->assertEquals(0, $process->getExitCode(), 'COMMAND: ' . $process->getCommandLine() . "\n" . 'OUTPUT: ' . $process->getOutput() . "\n" . 'ERROR: ' . $process->getErrorOutput() . "\n"); $this->assertStringContainsString('HTML output directory can_we_assume_that_a_subdirectory_with_this_name_does_not_exist is not a writable directory.', $process->getOutput()); // Test disabling by setting BROWSERTEST_OUTPUT_DIRECTORY = ''. $config = [ '--configuration', 'core', ]; $process = new Process(array_merge($command, $config)); $process->setWorkingDirectory($this->root) ->setTimeout(300) ->setIdleTimeout(300); $process->run(NULL, [ 'BROWSERTEST_OUTPUT_DIRECTORY' => '', ]); $this->assertEquals(0, $process->getExitCode(), 'COMMAND: ' . $process->getCommandLine() . "\n" . 'OUTPUT: ' . $process->getOutput() . "\n" . 'ERROR: ' . $process->getErrorOutput() . "\n"); $this->assertStringContainsString('HTML output disabled by BROWSERTEST_OUTPUT_DIRECTORY = \'\'.', $process->getOutput()); // Test missing 'outputDirectory' parameter. $alteredConfigFile = $this->getAlteredPhpunitXmlConfigurationFile( '', '', ); $config = [ '--configuration', $alteredConfigFile, ]; $process = new Process(array_merge($command, $config)); $process->setWorkingDirectory($this->root) ->setTimeout(300) ->setIdleTimeout(300); $process->run(NULL, [ 'BROWSERTEST_OUTPUT_DIRECTORY' => FALSE, ]); $this->assertEquals(0, $process->getExitCode(), 'COMMAND: ' . $process->getCommandLine() . "\n" . 'OUTPUT: ' . $process->getOutput() . "\n" . 'ERROR: ' . $process->getErrorOutput() . "\n"); $this->assertStringContainsString('HTML output directory not specified.', $process->getOutput()); unlink($alteredConfigFile); } private function getAlteredPhpunitXmlConfigurationFile(array|string $search, array|string $replace): string { $fileSystem = \Drupal::service('file_system'); $copiedConfigFile = $fileSystem->tempnam($this->root . \DIRECTORY_SEPARATOR . 'core', 'pux'); $fileSystem->copy($this->root . \DIRECTORY_SEPARATOR . 'core' . \DIRECTORY_SEPARATOR . 'phpunit.xml.dist', $copiedConfigFile, FileExists::Replace); $content = file_get_contents($copiedConfigFile); $content = str_replace($search, $replace, $content); file_put_contents($copiedConfigFile, $content); return $fileSystem->realpath($copiedConfigFile); } }