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. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
ProcessBuilderTest.php
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\ProcessBuilder;
016
017 /**
018 * @group legacy
019 */
020 class ProcessBuilderTest extends TestCase
021 {
022 public function testInheritEnvironmentVars()
023 {
024 $proc = ProcessBuilder::create()
025 ->add('foo')
026 ->getProcess();
027
028 $this->assertTrue($proc->areEnvironmentVariablesInherited());
029
030 $proc = ProcessBuilder::create()
031 ->add('foo')
032 ->inheritEnvironmentVariables(false)
033 ->getProcess();
034
035 $this->assertFalse($proc->areEnvironmentVariablesInherited());
036 }
037
038 public function testAddEnvironmentVariables()
039 {
040 $pb = new ProcessBuilder();
041 $env = [
042 'foo' => 'bar',
043 'foo2' => 'bar2',
044 ];
045 $proc = $pb
046 ->add('command')
047 ->setEnv('foo', 'bar2')
048 ->addEnvironmentVariables($env)
049 ->getProcess()
050 ;
051
052 $this->assertSame($env, $proc->getEnv());
053 }
054
055 public function testNegativeTimeoutFromSetter()
056 {
057 $this->expectException('Symfony\Component\Process\Exception\InvalidArgumentException');
058 $pb = new ProcessBuilder();
059 $pb->setTimeout(-1);
060 }
061
062 public function testNullTimeout()
063 {
064 $pb = new ProcessBuilder();
065 $pb->setTimeout(10);
066 $pb->setTimeout(null);
067
068 $r = new \ReflectionObject($pb);
069 $p = $r->getProperty('timeout');
070 $p->setAccessible(true);
071
072 $this->assertNull($p->getValue($pb));
073 }
074
075 public function testShouldSetArguments()
076 {
077 $pb = new ProcessBuilder(['initial']);
078 $pb->setArguments(['second']);
079
080 $proc = $pb->getProcess();
081
082 $this->assertStringContainsString('second', $proc->getCommandLine());
083 }
084
085 public function testPrefixIsPrependedToAllGeneratedProcess()
086 {
087 $pb = new ProcessBuilder();
088 $pb->setPrefix('/usr/bin/php');
089
090 $proc = $pb->setArguments(['-v'])->getProcess();
091 if ('\\' === \DIRECTORY_SEPARATOR) {
092 $this->assertEquals('"/usr/bin/php" -v', $proc->getCommandLine());
093 } else {
094 $this->assertEquals("'/usr/bin/php' '-v'", $proc->getCommandLine());
095 }
096
097 $proc = $pb->setArguments(['-i'])->getProcess();
098 if ('\\' === \DIRECTORY_SEPARATOR) {
099 $this->assertEquals('"/usr/bin/php" -i', $proc->getCommandLine());
100 } else {
101 $this->assertEquals("'/usr/bin/php' '-i'", $proc->getCommandLine());
102 }
103 }
104
105 public function testArrayPrefixesArePrependedToAllGeneratedProcess()
106 {
107 $pb = new ProcessBuilder();
108 $pb->setPrefix(['/usr/bin/php', 'composer.phar']);
109
110 $proc = $pb->setArguments(['-v'])->getProcess();
111 if ('\\' === \DIRECTORY_SEPARATOR) {
112 $this->assertEquals('"/usr/bin/php" composer.phar -v', $proc->getCommandLine());
113 } else {
114 $this->assertEquals("'/usr/bin/php' 'composer.phar' '-v'", $proc->getCommandLine());
115 }
116
117 $proc = $pb->setArguments(['-i'])->getProcess();
118 if ('\\' === \DIRECTORY_SEPARATOR) {
119 $this->assertEquals('"/usr/bin/php" composer.phar -i', $proc->getCommandLine());
120 } else {
121 $this->assertEquals("'/usr/bin/php' 'composer.phar' '-i'", $proc->getCommandLine());
122 }
123 }
124
125 public function testShouldEscapeArguments()
126 {
127 $pb = new ProcessBuilder(['%path%', 'foo " bar', '%baz%baz']);
128 $proc = $pb->getProcess();
129
130 if ('\\' === \DIRECTORY_SEPARATOR) {
131 $this->assertSame('""^%"path"^%"" "foo "" bar" ""^%"baz"^%"baz"', $proc->getCommandLine());
132 } else {
133 $this->assertSame("'%path%' 'foo \" bar' '%baz%baz'", $proc->getCommandLine());
134 }
135 }
136
137 public function testShouldEscapeArgumentsAndPrefix()
138 {
139 $pb = new ProcessBuilder(['arg']);
140 $pb->setPrefix('%prefix%');
141 $proc = $pb->getProcess();
142
143 if ('\\' === \DIRECTORY_SEPARATOR) {
144 $this->assertSame('""^%"prefix"^%"" arg', $proc->getCommandLine());
145 } else {
146 $this->assertSame("'%prefix%' 'arg'", $proc->getCommandLine());
147 }
148 }
149
150 public function testShouldThrowALogicExceptionIfNoPrefixAndNoArgument()
151 {
152 $this->expectException('Symfony\Component\Process\Exception\LogicException');
153 ProcessBuilder::create()->getProcess();
154 }
155
156 public function testShouldNotThrowALogicExceptionIfNoArgument()
157 {
158 $process = ProcessBuilder::create()
159 ->setPrefix('/usr/bin/php')
160 ->getProcess();
161
162 if ('\\' === \DIRECTORY_SEPARATOR) {
163 $this->assertEquals('"/usr/bin/php"', $process->getCommandLine());
164 } else {
165 $this->assertEquals("'/usr/bin/php'", $process->getCommandLine());
166 }
167 }
168
169 public function testShouldNotThrowALogicExceptionIfNoPrefix()
170 {
171 $process = ProcessBuilder::create(['/usr/bin/php'])
172 ->getProcess();
173
174 if ('\\' === \DIRECTORY_SEPARATOR) {
175 $this->assertEquals('"/usr/bin/php"', $process->getCommandLine());
176 } else {
177 $this->assertEquals("'/usr/bin/php'", $process->getCommandLine());
178 }
179 }
180
181 public function testShouldReturnProcessWithDisabledOutput()
182 {
183 $process = ProcessBuilder::create(['/usr/bin/php'])
184 ->disableOutput()
185 ->getProcess();
186
187 $this->assertTrue($process->isOutputDisabled());
188 }
189
190 public function testShouldReturnProcessWithEnabledOutput()
191 {
192 $process = ProcessBuilder::create(['/usr/bin/php'])
193 ->disableOutput()
194 ->enableOutput()
195 ->getProcess();
196
197 $this->assertFalse($process->isOutputDisabled());
198 }
199
200 public function testInvalidInput()
201 {
202 $this->expectException('Symfony\Component\Process\Exception\InvalidArgumentException');
203 $this->expectExceptionMessage('"Symfony\Component\Process\ProcessBuilder::setInput" only accepts strings, Traversable objects or stream resources.');
204 $builder = ProcessBuilder::create();
205 $builder->setInput([]);
206 }
207
208 public function testDoesNotPrefixExec()
209 {
210 if ('\\' === \DIRECTORY_SEPARATOR) {
211 $this->markTestSkipped('This test cannot run on Windows.');
212 }
213
214 $builder = ProcessBuilder::create(['command', '-v', 'ls']);
215 $process = $builder->getProcess();
216 $process->run();
217
218 $this->assertTrue($process->isSuccessful());
219 }
220 }
221