ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ExecutableFinderTest.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{
21 private $path;
22
23 protected function tearDown()
24 {
25 if ($this->path) {
26 // Restore path if it was changed.
27 putenv('PATH='.$this->path);
28 }
29 }
30
31 private function setPath($path)
32 {
33 $this->path = getenv('PATH');
34 putenv('PATH='.$path);
35 }
36
37 public function testFind()
38 {
39 if (ini_get('open_basedir')) {
40 $this->markTestSkipped('Cannot test when open_basedir is set');
41 }
42
43 $this->setPath(dirname(PHP_BINARY));
44
45 $finder = new ExecutableFinder();
46 $result = $finder->find($this->getPhpBinaryName());
47
48 $this->assertSamePath(PHP_BINARY, $result);
49 }
50
51 public function testFindWithDefault()
52 {
53 if (ini_get('open_basedir')) {
54 $this->markTestSkipped('Cannot test when open_basedir is set');
55 }
56
57 $expected = 'defaultValue';
58
59 $this->setPath('');
60
61 $finder = new ExecutableFinder();
62 $result = $finder->find('foo', $expected);
63
64 $this->assertEquals($expected, $result);
65 }
66
67 public function testFindWithExtraDirs()
68 {
69 if (ini_get('open_basedir')) {
70 $this->markTestSkipped('Cannot test when open_basedir is set');
71 }
72
73 $this->setPath('');
74
75 $extraDirs = array(dirname(PHP_BINARY));
76
77 $finder = new ExecutableFinder();
78 $result = $finder->find($this->getPhpBinaryName(), null, $extraDirs);
79
80 $this->assertSamePath(PHP_BINARY, $result);
81 }
82
83 public function testFindWithOpenBaseDir()
84 {
85 if ('\\' === DIRECTORY_SEPARATOR) {
86 $this->markTestSkipped('Cannot run test on windows');
87 }
88
89 if (ini_get('open_basedir')) {
90 $this->markTestSkipped('Cannot test when open_basedir is set');
91 }
92
93 $this->iniSet('open_basedir', dirname(PHP_BINARY).(!defined('HHVM_VERSION') || HHVM_VERSION_ID >= 30800 ? PATH_SEPARATOR.'/' : ''));
94
95 $finder = new ExecutableFinder();
96 $result = $finder->find($this->getPhpBinaryName());
97
98 $this->assertSamePath(PHP_BINARY, $result);
99 }
100
102 {
103 if (ini_get('open_basedir')) {
104 $this->markTestSkipped('Cannot test when open_basedir is set');
105 }
106 if ('\\' === DIRECTORY_SEPARATOR) {
107 $this->markTestSkipped('Cannot run test on windows');
108 }
109
110 $this->setPath('');
111 $this->iniSet('open_basedir', PHP_BINARY.(!defined('HHVM_VERSION') || HHVM_VERSION_ID >= 30800 ? PATH_SEPARATOR.'/' : ''));
112
113 $finder = new ExecutableFinder();
114 $result = $finder->find($this->getPhpBinaryName(), false);
115
116 $this->assertSamePath(PHP_BINARY, $result);
117 }
118
119 private function assertSamePath($expected, $tested)
120 {
121 if ('\\' === DIRECTORY_SEPARATOR) {
122 $this->assertEquals(strtolower($expected), strtolower($tested));
123 } else {
124 $this->assertEquals($expected, $tested);
125 }
126 }
127
128 private function getPhpBinaryName()
129 {
130 return basename(PHP_BINARY, '\\' === DIRECTORY_SEPARATOR ? '.exe' : '');
131 }
132}
$result
An exception for terminatinating execution or to throw for unit testing.
defined( 'APPLICATION_ENV')||define( 'APPLICATION_ENV'
Definition: bootstrap.php:27