PageRenderTime 46ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/phprojekt/tests/UnitTests/AllTests.php

https://github.com/aponto/PHProjekt
PHP | 230 lines | 130 code | 36 blank | 64 comment | 14 complexity | 48e7ab2c2cd043852e6d9ad09c26c31b MD5 | raw file
Possible License(s): LGPL-3.0, BSD-3-Clause, LGPL-2.0, MIT
  1. <?php
  2. /**
  3. * AllTests merges all test from the modules and provides
  4. * several switches to control unit testing
  5. *
  6. * AllTests merges defined test suites for each
  7. * module, while each module itself has its own AllTests
  8. *
  9. * This software is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License version 3 as published by the Free Software Foundation
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * @category PHProjekt
  19. * @package UnitTests
  20. * @copyright Copyright (c) 2010 Mayflower GmbH (http://www.mayflower.de)
  21. * @license LGPL v3 (See LICENSE file)
  22. * @link http://www.phprojekt.com
  23. * @since File available since Release 6.0
  24. * @author David Soria Parra <soria_parra@mayflower.de>
  25. */
  26. // Force quotes off to run in cruisecontrol
  27. ini_set("magic_quotes_gpc", 0);
  28. ini_set("magic_quotes_runtime", 0);
  29. ini_set("magic_quotes_sybase", 0);
  30. /* use command line switches to overwrite this */
  31. define("DEFAULT_CONFIG_FILE", "configuration.php");
  32. define("PHPR_CONFIG_FILE", "configuration.php");
  33. define("DEFAULT_CONFIG_SECTION", "testing-mysql");
  34. define("PHPR_CONFIG_SECTION", "testing-mysql");
  35. define('PHPR_ROOT_PATH', realpath(dirname(__FILE__) . '/../../'));
  36. require_once PHPR_ROOT_PATH . DIRECTORY_SEPARATOR . 'library' . DIRECTORY_SEPARATOR . 'Phprojekt.php';
  37. Phprojekt::getInstance();
  38. Zend_Db_Table_Abstract::getDefaultMetadataCache()->clean();
  39. if (!defined('PHPUnit_MAIN_METHOD')) {
  40. define('PHPUnit_MAIN_METHOD', 'AllTests::main');
  41. }
  42. require_once 'PHPUnit/Framework.php';
  43. require_once 'PHPUnit/TextUI/TestRunner.php';
  44. require_once 'PHPUnit/Util/Filter.php';
  45. require_once 'Default/AllTests.php';
  46. require_once 'Phprojekt/AllTests.php';
  47. require_once 'Timecard/AllTests.php';
  48. require_once 'History/AllTests.php';
  49. require_once 'User/AllTests.php';
  50. require_once 'Calendar/AllTests.php';
  51. require_once 'Note/AllTests.php';
  52. require_once 'Role/AllTests.php';
  53. require_once 'Todo/AllTests.php';
  54. require_once 'Tab/AllTests.php';
  55. require_once 'Module/AllTests.php';
  56. require_once 'Project/AllTests.php';
  57. require_once 'Minutes/AllTests.php';
  58. require_once 'Helpdesk/AllTests.php';
  59. require_once 'Contact/AllTests.php';
  60. require_once 'Filemanager/AllTests.php';
  61. require_once 'Gantt/AllTests.php';
  62. require_once 'Statistic/AllTests.php';
  63. // require_once 'Selenium/AllTests.php';
  64. /**
  65. * AllTests merges all test from the modules
  66. *
  67. * @category PHProjekt
  68. * @package UnitTests
  69. * @copyright Copyright (c) 2010 Mayflower GmbH (http://www.mayflower.de)
  70. * @license LGPL v3 (See LICENSE file)
  71. * @link http://www.phprojekt.com
  72. * @since File available since Release 6.0
  73. * @author David Soria Parra <soria_parra@mayflower.de>
  74. */
  75. class AllTests extends PHPUnit_Framework_TestSuite
  76. {
  77. /**
  78. * Initialize the TestRunner
  79. */
  80. public static function main()
  81. {
  82. // for compability with phpunit offer suite() without any parameter.
  83. // in that case use defaults
  84. PHPUnit_TextUI_TestRunner::run(self::suite());
  85. }
  86. /**
  87. * Merges the test suites
  88. *
  89. * @return PHPUnit_Framework_TestSuite
  90. */
  91. public static function suite()
  92. {
  93. // These directories are covered for the code coverage even they are not part of unit testing
  94. PHPUnit_Util_Filter::addDirectoryToWhitelist(dirname(dirname(dirname(__FILE__))) . '/application');
  95. PHPUnit_Util_Filter::addDirectoryToWhitelist(dirname(dirname(dirname(__FILE__))) . '/library/Phprojekt');
  96. // Avoid Selenium checks
  97. PHPUnit_Util_Filter::addDirectoryToFilter(dirname(__FILE__) . '/Selenium');
  98. $authNamespace = new Zend_Session_Namespace('Phprojekt_Auth-login');
  99. $authNamespace->userId = 1;
  100. $authNamespace->admin = 1;
  101. $suite = new PHPUnit_Framework_TestSuite('PHPUnit');
  102. $suite->sharedFixture = Phprojekt::getInstance()->getDb();
  103. $suite->addTest(Timecard_AllTests::suite());
  104. $suite->addTest(Statistic_AllTests::suite());
  105. $suite->addTest(User_AllTests::suite());
  106. $suite->addTest(Calendar_AllTests::suite());
  107. $suite->addTest(Note_AllTests::suite());
  108. $suite->addTest(Todo_AllTests::suite());
  109. $suite->addTest(Helpdesk_AllTests::suite());
  110. $suite->addTest(Phprojekt_AllTests::suite());
  111. $suite->addTest(History_AllTests::suite());
  112. $suite->addTest(Role_AllTests::suite());
  113. $suite->addTest(Tab_AllTests::suite());
  114. $suite->addTest(Project_AllTests::suite());
  115. $suite->addTest(Module_AllTests::suite());
  116. $suite->addTest(Contact_AllTests::suite());
  117. $suite->addTest(Filemanager_AllTests::suite());
  118. $suite->addTest(Gantt_AllTests::suite());
  119. $suite->addTest(Minutes_AllTests::suite());
  120. // Add here additional test suites
  121. $suite->addTest(Default_AllTests::suite());
  122. //$suite->addTestSuite(Selenium_AllTests::suite());
  123. return $suite;
  124. }
  125. }
  126. /**
  127. * This is actually our entry point. If we run from the commandline
  128. * we support several switches to the AllTest file.
  129. *
  130. * To see the switches try
  131. * php AllTests.php -h
  132. */
  133. if (PHPUnit_MAIN_METHOD == 'AllTests::main') {
  134. /* default settings */
  135. $whiteListing = true;
  136. $configFile = DEFAULT_CONFIG_FILE;
  137. $configSect = DEFAULT_CONFIG_SECTION;
  138. if (function_exists('getopt') && isset($argv)) { /* Not available on windows */
  139. $options = getopt('s:c:hd');
  140. if (array_key_exists('h', $options)) {
  141. usage();
  142. }
  143. if (array_key_exists('c', $options)) {
  144. $configFile = $options['c'];
  145. }
  146. if (array_key_exists('s', $options)) {
  147. $configSect = $options['s'];
  148. }
  149. if (array_key_exists('d', $options)) {
  150. $whiteListing = false;
  151. }
  152. if (!is_readable($configFile)) {
  153. fprintf(STDERR, "Cannot read %s\nAborted\n", $configFile);
  154. exit;
  155. }
  156. } elseif (isset($_GET)) {
  157. /* @todo make checks to avoid security leaks */
  158. if (array_key_exists('c', $_GET)) {
  159. $configFile = realpath($_GET['c']);
  160. }
  161. if (array_key_exists('s', $_GET)) {
  162. $configSect = $_GET['s'];
  163. }
  164. if (array_key_exists('d', $_GET)) {
  165. $whiteListing = ! $whiteListing;
  166. }
  167. }
  168. $config = new Zend_Config_Ini($configFile, $configSect, array("allowModifications" => true));
  169. Zend_Registry::set('config', $config);
  170. if ($whiteListing) {
  171. // Enable whitelisting for unit tests, these directories are
  172. // covered for the code coverage even they are not part of unit testing
  173. PHPUnit_Util_Filter::addDirectoryToWhitelist($config->applicationDir . '/application');
  174. PHPUnit_Util_Filter::addDirectoryToWhitelist(PHPR_LIBRARY_PATH . '/Phprojekt');
  175. }
  176. // Avoid Selenium checks
  177. PHPUnit_Util_Filter::addDirectoryToFilter('Selenium');
  178. AllTests::main();
  179. }
  180. function usage() {
  181. $doc = <<<EOF
  182. PHProjekt UnitTesting suite. Uses PHPUnit by Sebastian Bergmann.
  183. usage:
  184. php AllTests.php [OPTIONS]
  185. OPTIONS:
  186. -h show help
  187. -c <file> use <file> as configuration file, default 'configuration.php'
  188. -s <section> <section> is used to read the ini, default 'testing-mysql'
  189. -d disable whitelist filtering
  190. -l disable logging
  191. EOF;
  192. print $doc."\n";
  193. exit;
  194. }