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

ExecutableFinderTest.php

Zuletzt modifiziert: 02.04.2025, 15:03 - Dateigröße: 4.61 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\ExecutableFinder;
016   
017  /**
018   * @author Chris Smith <chris@cs278.org>
019   */
020  class ExecutableFinderTest extends TestCase
021  {
022      private $path;
023   
024      protected function tearDown()
025      {
026          if ($this->path) {
027              // Restore path if it was changed.
028              putenv('PATH='.$this->path);
029          }
030      }
031   
032      private function setPath($path)
033      {
034          $this->path = getenv('PATH');
035          putenv('PATH='.$path);
036      }
037   
038      public function testFind()
039      {
040          if (ini_get('open_basedir')) {
041              $this->markTestSkipped('Cannot test when open_basedir is set');
042          }
043   
044          $this->setPath(\dirname(\PHP_BINARY));
045   
046          $finder = new ExecutableFinder();
047          $result = $finder->find($this->getPhpBinaryName());
048   
049          $this->assertSamePath(\PHP_BINARY, $result);
050      }
051   
052      public function testFindWithDefault()
053      {
054          if (ini_get('open_basedir')) {
055              $this->markTestSkipped('Cannot test when open_basedir is set');
056          }
057   
058          $expected = 'defaultValue';
059   
060          $this->setPath('');
061   
062          $finder = new ExecutableFinder();
063          $result = $finder->find('foo', $expected);
064   
065          $this->assertEquals($expected, $result);
066      }
067   
068      public function testFindWithNullAsDefault()
069      {
070          if (ini_get('open_basedir')) {
071              $this->markTestSkipped('Cannot test when open_basedir is set');
072          }
073   
074          $this->setPath('');
075   
076          $finder = new ExecutableFinder();
077   
078          $result = $finder->find('foo');
079   
080          $this->assertNull($result);
081      }
082   
083      public function testFindWithExtraDirs()
084      {
085          if (ini_get('open_basedir')) {
086              $this->markTestSkipped('Cannot test when open_basedir is set');
087          }
088   
089          $this->setPath('');
090   
091          $extraDirs = [\dirname(\PHP_BINARY)];
092   
093          $finder = new ExecutableFinder();
094          $result = $finder->find($this->getPhpBinaryName(), null, $extraDirs);
095   
096          $this->assertSamePath(\PHP_BINARY, $result);
097      }
098   
099      public function testFindWithOpenBaseDir()
100      {
101          if ('\\' === \DIRECTORY_SEPARATOR) {
102              $this->markTestSkipped('Cannot run test on windows');
103          }
104   
105          if (ini_get('open_basedir')) {
106              $this->markTestSkipped('Cannot test when open_basedir is set');
107          }
108   
109          $this->iniSet('open_basedir', \dirname(\PHP_BINARY).(!\defined('HHVM_VERSION') || HHVM_VERSION_ID >= 30800 ? \PATH_SEPARATOR.'/' : ''));
110   
111          $finder = new ExecutableFinder();
112          $result = $finder->find($this->getPhpBinaryName());
113   
114          $this->assertSamePath(\PHP_BINARY, $result);
115      }
116   
117      public function testFindProcessInOpenBasedir()
118      {
119          if (ini_get('open_basedir')) {
120              $this->markTestSkipped('Cannot test when open_basedir is set');
121          }
122          if ('\\' === \DIRECTORY_SEPARATOR) {
123              $this->markTestSkipped('Cannot run test on windows');
124          }
125   
126          $this->setPath('');
127          $this->iniSet('open_basedir', \PHP_BINARY.(!\defined('HHVM_VERSION') || HHVM_VERSION_ID >= 30800 ? \PATH_SEPARATOR.'/' : ''));
128   
129          $finder = new ExecutableFinder();
130          $result = $finder->find($this->getPhpBinaryName(), false);
131   
132          $this->assertSamePath(\PHP_BINARY, $result);
133      }
134   
135      public function testFindBatchExecutableOnWindows()
136      {
137          if (ini_get('open_basedir')) {
138              $this->markTestSkipped('Cannot test when open_basedir is set');
139          }
140          if ('\\' !== \DIRECTORY_SEPARATOR) {
141              $this->markTestSkipped('Can be only tested on windows');
142          }
143   
144          $target = tempnam(sys_get_temp_dir(), 'example-windows-executable');
145   
146          touch($target);
147          touch($target.'.BAT');
148   
149          $this->assertFalse(is_executable($target));
150   
151          $this->setPath(sys_get_temp_dir());
152   
153          $finder = new ExecutableFinder();
154          $result = $finder->find(basename($target), false);
155   
156          unlink($target);
157          unlink($target.'.BAT');
158   
159          $this->assertSamePath($target.'.BAT', $result);
160      }
161   
162      private function assertSamePath($expected, $tested)
163      {
164          if ('\\' === \DIRECTORY_SEPARATOR) {
165              $this->assertEquals(strtolower($expected), strtolower($tested));
166          } else {
167              $this->assertEquals($expected, $tested);
168          }
169      }
170   
171      private function getPhpBinaryName()
172      {
173          return basename(\PHP_BINARY, '\\' === \DIRECTORY_SEPARATOR ? '.exe' : '');
174      }
175  }
176