Verzeichnisstruktur phpBB-3.3.15


Veröffentlicht
28.08.2024

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

ProcessFailedExceptionTest.php

Zuletzt modifiziert: 02.04.2025, 15:03 - Dateigröße: 4.52 KiB


001  <?php
002   
003  /*
004   * This file is part of the Symfony package.
005   *
006   * (c) Fabien Potencier <fabien@symfony.com>
007   *
008   * For the full copyright and license information, please view the LICENSE
009   * file that was distributed with this source code.
010   */
011   
012  namespace Symfony\Component\Process\Tests;
013   
014  use PHPUnit\Framework\TestCase;
015  use Symfony\Component\Process\Exception\ProcessFailedException;
016   
017  /**
018   * @author Sebastian Marek <proofek@gmail.com>
019   */
020  class ProcessFailedExceptionTest extends TestCase
021  {
022      /**
023       * tests ProcessFailedException throws exception if the process was successful.
024       */
025      public function testProcessFailedExceptionThrowsException()
026      {
027          $process = $this->getMockBuilder('Symfony\Component\Process\Process')->setMethods(['isSuccessful'])->setConstructorArgs(['php'])->getMock();
028          $process->expects($this->once())
029              ->method('isSuccessful')
030              ->willReturn(true);
031   
032          $this->expectException(\InvalidArgumentException::class);
033          $this->expectExceptionMessage('Expected a failed process, but the given process was successful.');
034   
035          new ProcessFailedException($process);
036      }
037   
038      /**
039       * tests ProcessFailedException uses information from process output
040       * to generate exception message.
041       */
042      public function testProcessFailedExceptionPopulatesInformationFromProcessOutput()
043      {
044          $cmd = 'php';
045          $exitCode = 1;
046          $exitText = 'General error';
047          $output = 'Command output';
048          $errorOutput = 'FATAL: Unexpected error';
049          $workingDirectory = getcwd();
050   
051          $process = $this->getMockBuilder('Symfony\Component\Process\Process')->setMethods(['isSuccessful', 'getOutput', 'getErrorOutput', 'getExitCode', 'getExitCodeText', 'isOutputDisabled', 'getWorkingDirectory'])->setConstructorArgs([$cmd])->getMock();
052          $process->expects($this->once())
053              ->method('isSuccessful')
054              ->willReturn(false);
055   
056          $process->expects($this->once())
057              ->method('getOutput')
058              ->willReturn($output);
059   
060          $process->expects($this->once())
061              ->method('getErrorOutput')
062              ->willReturn($errorOutput);
063   
064          $process->expects($this->once())
065              ->method('getExitCode')
066              ->willReturn($exitCode);
067   
068          $process->expects($this->once())
069              ->method('getExitCodeText')
070              ->willReturn($exitText);
071   
072          $process->expects($this->once())
073              ->method('isOutputDisabled')
074              ->willReturn(false);
075   
076          $process->expects($this->once())
077              ->method('getWorkingDirectory')
078              ->willReturn($workingDirectory);
079   
080          $exception = new ProcessFailedException($process);
081   
082          $this->assertEquals(
083              "The command \"$cmd\" failed.\n\nExit Code: $exitCode($exitText)\n\nWorking directory: {$workingDirectory}\n\nOutput:\n================\n{$output}\n\nError Output:\n================\n{$errorOutput}",
084              $exception->getMessage()
085          );
086      }
087   
088      /**
089       * Tests that ProcessFailedException does not extract information from
090       * process output if it was previously disabled.
091       */
092      public function testDisabledOutputInFailedExceptionDoesNotPopulateOutput()
093      {
094          $cmd = 'php';
095          $exitCode = 1;
096          $exitText = 'General error';
097          $workingDirectory = getcwd();
098   
099          $process = $this->getMockBuilder('Symfony\Component\Process\Process')->setMethods(['isSuccessful', 'isOutputDisabled', 'getExitCode', 'getExitCodeText', 'getOutput', 'getErrorOutput', 'getWorkingDirectory'])->setConstructorArgs([$cmd])->getMock();
100          $process->expects($this->once())
101              ->method('isSuccessful')
102              ->willReturn(false);
103   
104          $process->expects($this->never())
105              ->method('getOutput');
106   
107          $process->expects($this->never())
108              ->method('getErrorOutput');
109   
110          $process->expects($this->once())
111              ->method('getExitCode')
112              ->willReturn($exitCode);
113   
114          $process->expects($this->once())
115              ->method('getExitCodeText')
116              ->willReturn($exitText);
117   
118          $process->expects($this->once())
119              ->method('isOutputDisabled')
120              ->willReturn(true);
121   
122          $process->expects($this->once())
123              ->method('getWorkingDirectory')
124              ->willReturn($workingDirectory);
125   
126          $exception = new ProcessFailedException($process);
127   
128          $this->assertEquals(
129              "The command \"$cmd\" failed.\n\nExit Code: $exitCode($exitText)\n\nWorking directory: {$workingDirectory}",
130              $exception->getMessage()
131          );
132      }
133  }
134