PageRenderTime 54ms CodeModel.GetById 7ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/phpunit/phpunit/Tests/Util/ConfigurationTest.php

https://gitlab.com/karora/awl
PHP | 335 lines | 261 code | 15 blank | 59 comment | 0 complexity | 0fcac3cb25e2d1992b6b5e16b7e2c0b8 MD5 | raw file
  1. <?php
  2. /**
  3. * PHPUnit
  4. *
  5. * Copyright (c) 2001-2012, Sebastian Bergmann <sebastian@phpunit.de>.
  6. * All rights reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * * Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. *
  15. * * Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in
  17. * the documentation and/or other materials provided with the
  18. * distribution.
  19. *
  20. * * Neither the name of Sebastian Bergmann nor the names of his
  21. * contributors may be used to endorse or promote products derived
  22. * from this software without specific prior written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  25. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  26. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  27. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  28. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  29. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  30. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  31. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  32. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  33. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  34. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  35. * POSSIBILITY OF SUCH DAMAGE.
  36. *
  37. * @package PHPUnit
  38. * @author Sebastian Bergmann <sebastian@phpunit.de>
  39. * @copyright 2001-2012 Sebastian Bergmann <sebastian@phpunit.de>
  40. * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
  41. * @link http://www.phpunit.de/
  42. * @since File available since Release 3.3.0
  43. */
  44. /**
  45. *
  46. *
  47. * @package PHPUnit
  48. * @author Sebastian Bergmann <sebastian@phpunit.de>
  49. * @copyright 2001-2012 Sebastian Bergmann <sebastian@phpunit.de>
  50. * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
  51. * @version Release: @package_version@
  52. * @link http://www.phpunit.de/
  53. * @since Class available since Release 3.3.0
  54. */
  55. class Util_ConfigurationTest extends PHPUnit_Framework_TestCase
  56. {
  57. protected $configuration;
  58. protected function setUp()
  59. {
  60. $this->configuration = PHPUnit_Util_Configuration::getInstance(
  61. dirname(__DIR__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'configuration.xml'
  62. );
  63. }
  64. /**
  65. * @expectedException PHPUnit_Framework_Exception
  66. */
  67. public function testExceptionIsThrownForNotExistingConfigurationFile()
  68. {
  69. PHPUnit_Util_Configuration::getInstance('not_existing_file.xml');
  70. }
  71. public function testFilterConfigurationIsReadCorrectly()
  72. {
  73. $this->assertEquals(
  74. array(
  75. 'blacklist' =>
  76. array(
  77. 'include' =>
  78. array(
  79. 'directory' =>
  80. array(
  81. 0 =>
  82. array(
  83. 'path' => '/path/to/files',
  84. 'prefix' => '',
  85. 'suffix' => '.php',
  86. 'group' => 'DEFAULT'
  87. ),
  88. ),
  89. 'file' =>
  90. array(
  91. 0 => '/path/to/file',
  92. ),
  93. ),
  94. 'exclude' =>
  95. array(
  96. 'directory' =>
  97. array(
  98. 0 =>
  99. array(
  100. 'path' => '/path/to/files',
  101. 'prefix' => '',
  102. 'suffix' => '.php',
  103. 'group' => 'DEFAULT'
  104. ),
  105. ),
  106. 'file' =>
  107. array(
  108. 0 => '/path/to/file',
  109. ),
  110. ),
  111. ),
  112. 'whitelist' =>
  113. array(
  114. 'processUncoveredFilesFromWhitelist' => FALSE,
  115. 'include' =>
  116. array(
  117. 'directory' =>
  118. array(
  119. 0 =>
  120. array(
  121. 'path' => '/path/to/files',
  122. 'prefix' => '',
  123. 'suffix' => '.php',
  124. 'group' => 'DEFAULT'
  125. ),
  126. ),
  127. 'file' =>
  128. array(
  129. 0 => '/path/to/file',
  130. ),
  131. ),
  132. 'exclude' =>
  133. array(
  134. 'directory' =>
  135. array(
  136. 0 =>
  137. array(
  138. 'path' => '/path/to/files',
  139. 'prefix' => '',
  140. 'suffix' => '.php',
  141. 'group' => 'DEFAULT'
  142. ),
  143. ),
  144. 'file' =>
  145. array(
  146. 0 => '/path/to/file',
  147. ),
  148. ),
  149. ),
  150. ),
  151. $this->configuration->getFilterConfiguration()
  152. );
  153. }
  154. public function testGroupConfigurationIsReadCorrectly()
  155. {
  156. $this->assertEquals(
  157. array(
  158. 'include' =>
  159. array(
  160. 0 => 'name',
  161. ),
  162. 'exclude' =>
  163. array(
  164. 0 => 'name',
  165. ),
  166. ),
  167. $this->configuration->getGroupConfiguration()
  168. );
  169. }
  170. public function testListenerConfigurationIsReadCorrectly()
  171. {
  172. $dir = __DIR__;
  173. $includePath = ini_get('include_path');
  174. ini_set('include_path', $dir . PATH_SEPARATOR . $includePath);
  175. $this->assertEquals(
  176. array(
  177. 0 =>
  178. array(
  179. 'class' => 'MyListener',
  180. 'file' => '/optional/path/to/MyListener.php',
  181. 'arguments' =>
  182. array(
  183. 0 =>
  184. array(
  185. 0 => 'Sebastian',
  186. ),
  187. 1 => 22,
  188. 2 => 'April',
  189. 3 => 19.78,
  190. 4 => NULL,
  191. 5 => new stdClass,
  192. 6 => dirname(__DIR__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'MyTestFile.php',
  193. 7 => dirname(__DIR__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'MyRelativePath',
  194. ),
  195. ),
  196. array(
  197. 'class' => 'IncludePathListener',
  198. 'file' => __FILE__,
  199. 'arguments' => array()
  200. ),
  201. array(
  202. 'class' => 'CompactArgumentsListener',
  203. 'file' => '/CompactArgumentsListener.php',
  204. 'arguments' =>
  205. array(
  206. 0 => 42
  207. ),
  208. ),
  209. ),
  210. $this->configuration->getListenerConfiguration()
  211. );
  212. ini_set('include_path', $includePath);
  213. }
  214. public function testLoggingConfigurationIsReadCorrectly()
  215. {
  216. $this->assertEquals(
  217. array(
  218. 'charset' => 'UTF-8',
  219. 'lowUpperBound' => '35',
  220. 'highLowerBound' => '70',
  221. 'highlight' => FALSE,
  222. 'coverage-html' => '/tmp/report',
  223. 'coverage-clover' => '/tmp/clover.xml',
  224. 'json' => '/tmp/logfile.json',
  225. 'plain' => '/tmp/logfile.txt',
  226. 'tap' => '/tmp/logfile.tap',
  227. 'logIncompleteSkipped' => FALSE,
  228. 'junit' => '/tmp/logfile.xml',
  229. 'testdox-html' => '/tmp/testdox.html',
  230. 'testdox-text' => '/tmp/testdox.txt',
  231. ),
  232. $this->configuration->getLoggingConfiguration()
  233. );
  234. }
  235. public function testPHPConfigurationIsReadCorrectly()
  236. {
  237. $this->assertEquals(
  238. array(
  239. 'include_path' =>
  240. array(
  241. dirname(__DIR__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . '.',
  242. '/path/to/lib'
  243. ),
  244. 'ini'=> array('foo' => 'bar'),
  245. 'const'=> array('FOO' => FALSE, 'BAR' => TRUE),
  246. 'var'=> array('foo' => FALSE),
  247. 'env'=> array('foo' => TRUE),
  248. 'post'=> array('foo' => 'bar'),
  249. 'get'=> array('foo' => 'bar'),
  250. 'cookie'=> array('foo' => 'bar'),
  251. 'server'=> array('foo' => 'bar'),
  252. 'files'=> array('foo' => 'bar'),
  253. 'request'=> array('foo' => 'bar'),
  254. ),
  255. $this->configuration->getPHPConfiguration()
  256. );
  257. }
  258. /**
  259. * @backupGlobals enabled
  260. */
  261. public function testPHPConfigurationIsHandledCorrectly()
  262. {
  263. $this->configuration->handlePHPConfiguration();
  264. $path = dirname(__DIR__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . '.' . PATH_SEPARATOR . '/path/to/lib';
  265. $this->assertStringStartsWith($path, ini_get('include_path'));
  266. $this->assertEquals(FALSE, FOO);
  267. $this->assertEquals(TRUE, BAR);
  268. $this->assertEquals(FALSE, $GLOBALS['foo']);
  269. $this->assertEquals(TRUE, $_ENV['foo']);
  270. $this->assertEquals(TRUE, getenv('foo'));
  271. $this->assertEquals('bar', $_POST['foo']);
  272. $this->assertEquals('bar', $_GET['foo']);
  273. $this->assertEquals('bar', $_COOKIE['foo']);
  274. $this->assertEquals('bar', $_SERVER['foo']);
  275. $this->assertEquals('bar', $_FILES['foo']);
  276. $this->assertEquals('bar', $_REQUEST['foo']);
  277. }
  278. public function testPHPUnitConfigurationIsReadCorrectly()
  279. {
  280. $this->assertEquals(
  281. array(
  282. 'backupGlobals' => TRUE,
  283. 'backupStaticAttributes' => FALSE,
  284. 'bootstrap' => '/path/to/bootstrap.php',
  285. 'cacheTokens' => TRUE,
  286. 'colors' => FALSE,
  287. 'convertErrorsToExceptions' => TRUE,
  288. 'convertNoticesToExceptions' => TRUE,
  289. 'convertWarningsToExceptions' => TRUE,
  290. 'forceCoversAnnotation' => FALSE,
  291. 'mapTestClassNameToCoveredClassName' => FALSE,
  292. 'printerClass' => 'PHPUnit_TextUI_ResultPrinter',
  293. 'stopOnFailure' => FALSE,
  294. 'strict' => FALSE,
  295. 'testSuiteLoaderClass' => 'PHPUnit_Runner_StandardTestSuiteLoader',
  296. 'verbose' => FALSE,
  297. 'timeoutForSmallTests' => 1,
  298. 'timeoutForMediumTests' => 10,
  299. 'timeoutForLargeTests' => 60
  300. ),
  301. $this->configuration->getPHPUnitConfiguration()
  302. );
  303. }
  304. public function testSeleniumBrowserConfigurationIsReadCorrectly()
  305. {
  306. $this->assertEquals(
  307. array(
  308. 0 =>
  309. array(
  310. 'name' => 'Firefox on Linux',
  311. 'browser' => '*firefox /usr/lib/firefox/firefox-bin',
  312. 'host' => 'my.linux.box',
  313. 'port' => 4444,
  314. 'timeout' => 30000,
  315. ),
  316. ),
  317. $this->configuration->getSeleniumBrowserConfiguration()
  318. );
  319. }
  320. }