ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ProcessFailedExceptionTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11 
13 
15 
20 {
25  {
26  $process = $this->getMock(
27  'Symfony\Component\Process\Process',
28  array('isSuccessful'),
29  array('php')
30  );
31  $process->expects($this->once())
32  ->method('isSuccessful')
33  ->will($this->returnValue(true));
34 
35  $this->setExpectedException(
36  '\InvalidArgumentException',
37  'Expected a failed process, but the given process was successful.'
38  );
39 
40  new ProcessFailedException($process);
41  }
42 
48  {
49  $cmd = 'php';
50  $exitCode = 1;
51  $exitText = 'General error';
52  $output = 'Command output';
53  $errorOutput = 'FATAL: Unexpected error';
54  $workingDirectory = getcwd();
55 
56  $process = $this->getMock(
57  'Symfony\Component\Process\Process',
58  array('isSuccessful', 'getOutput', 'getErrorOutput', 'getExitCode', 'getExitCodeText', 'isOutputDisabled', 'getWorkingDirectory'),
59  array($cmd)
60  );
61  $process->expects($this->once())
62  ->method('isSuccessful')
63  ->will($this->returnValue(false));
64 
65  $process->expects($this->once())
66  ->method('getOutput')
67  ->will($this->returnValue($output));
68 
69  $process->expects($this->once())
70  ->method('getErrorOutput')
71  ->will($this->returnValue($errorOutput));
72 
73  $process->expects($this->once())
74  ->method('getExitCode')
75  ->will($this->returnValue($exitCode));
76 
77  $process->expects($this->once())
78  ->method('getExitCodeText')
79  ->will($this->returnValue($exitText));
80 
81  $process->expects($this->once())
82  ->method('isOutputDisabled')
83  ->will($this->returnValue(false));
84 
85  $process->expects($this->once())
86  ->method('getWorkingDirectory')
87  ->will($this->returnValue($workingDirectory));
88 
89  $exception = new ProcessFailedException($process);
90 
91  $this->assertEquals(
92  "The command \"$cmd\" failed.\n\nExit Code: $exitCode($exitText)\n\nWorking directory: {$workingDirectory}\n\nOutput:\n================\n{$output}\n\nError Output:\n================\n{$errorOutput}",
93  $exception->getMessage()
94  );
95  }
96 
102  {
103  $cmd = 'php';
104  $exitCode = 1;
105  $exitText = 'General error';
106  $workingDirectory = getcwd();
107 
108  $process = $this->getMock(
109  'Symfony\Component\Process\Process',
110  array('isSuccessful', 'isOutputDisabled', 'getExitCode', 'getExitCodeText', 'getOutput', 'getErrorOutput', 'getWorkingDirectory'),
111  array($cmd)
112  );
113  $process->expects($this->once())
114  ->method('isSuccessful')
115  ->will($this->returnValue(false));
116 
117  $process->expects($this->never())
118  ->method('getOutput');
119 
120  $process->expects($this->never())
121  ->method('getErrorOutput');
122 
123  $process->expects($this->once())
124  ->method('getExitCode')
125  ->will($this->returnValue($exitCode));
126 
127  $process->expects($this->once())
128  ->method('getExitCodeText')
129  ->will($this->returnValue($exitText));
130 
131  $process->expects($this->once())
132  ->method('isOutputDisabled')
133  ->will($this->returnValue(true));
134 
135  $process->expects($this->once())
136  ->method('getWorkingDirectory')
137  ->will($this->returnValue($workingDirectory));
138 
139  $exception = new ProcessFailedException($process);
140 
141  $this->assertEquals(
142  "The command \"$cmd\" failed.\n\nExit Code: $exitCode($exitText)\n\nWorking directory: {$workingDirectory}",
143  $exception->getMessage()
144  );
145  }
146 }
testProcessFailedExceptionPopulatesInformationFromProcessOutput()
tests ProcessFailedException uses information from process output to generate exception message...
testProcessFailedExceptionThrowsException()
tests ProcessFailedException throws exception if the process was successful.
$cmd
Definition: sahs_server.php:35
testDisabledOutputInFailedExceptionDoesNotPopulateOutput()
Tests that ProcessFailedException does not extract information from process output if it was previous...
if(!is_dir( $entity_dir)) exit("Fatal Error ([A-Za-z0-9]+)\+" &#(? foreach( $entity_files as $file) $output
Create styles array
The data for the language used.