Permalink
Browse files

added phprack + initial test set

  • Loading branch information...
1 parent 5db8d1b commit 475665aa64ea9e1130814133c7165d6542a0506b Michael committed Oct 16, 2011
Showing with 9,041 additions and 0 deletions.
  1. +7 −0 application/Bootstrap.php
  2. +108 −0 library/phpRack/Adapters/Auth/Abstract.php
  3. +60 −0 library/phpRack/Adapters/Auth/Array.php
  4. +69 −0 library/phpRack/Adapters/Auth/File.php
  5. +60 −0 library/phpRack/Adapters/Auth/Plain.php
  6. +107 −0 library/phpRack/Adapters/Config.php
  7. +137 −0 library/phpRack/Adapters/Config/Ini.php
  8. +105 −0 library/phpRack/Adapters/ConnectionMonitor.php
  9. +64 −0 library/phpRack/Adapters/Cpu.php
  10. +56 −0 library/phpRack/Adapters/Cpu/Abstract.php
  11. +86 −0 library/phpRack/Adapters/Cpu/Darwin.php
  12. +110 −0 library/phpRack/Adapters/Cpu/Linux.php
  13. +99 −0 library/phpRack/Adapters/Cpu/Windows.php
  14. +98 −0 library/phpRack/Adapters/Db/Abstract.php
  15. +326 −0 library/phpRack/Adapters/Db/Mysql.php
  16. +114 −0 library/phpRack/Adapters/Db/Mysql/Result/Formatter.php
  17. +114 −0 library/phpRack/Adapters/File.php
  18. +185 −0 library/phpRack/Adapters/Files/DirectoryFilterIterator.php
  19. +63 −0 library/phpRack/Adapters/Notifier/Mail.php
  20. +165 −0 library/phpRack/Adapters/Notifier/Mail/Abstract.php
  21. +87 −0 library/phpRack/Adapters/Notifier/Mail/Sendmail.php
  22. +271 −0 library/phpRack/Adapters/Notifier/Mail/Smtp.php
  23. +85 −0 library/phpRack/Adapters/Os.php
  24. +106 −0 library/phpRack/Adapters/Pear.php
  25. +117 −0 library/phpRack/Adapters/Pear/Package.php
  26. +277 −0 library/phpRack/Adapters/Shell/Command.php
  27. +247 −0 library/phpRack/Adapters/Url.php
  28. +145 −0 library/phpRack/Assertion.php
  29. +264 −0 library/phpRack/Package.php
  30. +43 −0 library/phpRack/Package/Cpu.php
  31. +72 −0 library/phpRack/Package/Cpu/Performance.php
  32. +43 −0 library/phpRack/Package/Db.php
  33. +246 −0 library/phpRack/Package/Db/Mysql.php
  34. +114 −0 library/phpRack/Package/Disc.php
  35. +420 −0 library/phpRack/Package/Disc/File.php
  36. +61 −0 library/phpRack/Package/Disc/FreeSpace.php
  37. +42 −0 library/phpRack/Package/Network.php
  38. +68 −0 library/phpRack/Package/Network/Ports.php
  39. +114 −0 library/phpRack/Package/Network/Url.php
  40. +275 −0 library/phpRack/Package/Php.php
  41. +72 −0 library/phpRack/Package/Php/Extensions.php
  42. +72 −0 library/phpRack/Package/Php/Extensions/Fileinfo.php
  43. +147 −0 library/phpRack/Package/Php/Pear.php
  44. +60 −0 library/phpRack/Package/Php/Version.php
  45. +81 −0 library/phpRack/Package/Shell.php
  46. +99 −0 library/phpRack/Package/Simple.php
  47. +183 −0 library/phpRack/Result.php
  48. +356 −0 library/phpRack/Runner.php
  49. +335 −0 library/phpRack/Runner/Auth.php
  50. +88 −0 library/phpRack/Runner/Auth/Result.php
  51. +103 −0 library/phpRack/Runner/Logger.php
  52. +184 −0 library/phpRack/Suite.php
  53. +66 −0 library/phpRack/Suite/Test.php
  54. +61 −0 library/phpRack/Suite/library/LogViewerTest.php
  55. +51 −0 library/phpRack/Suite/library/Php5/PhpinfoTest.php
  56. +74 −0 library/phpRack/Suite/library/ServerHealth/TopProcessesTest.php
  57. +347 −0 library/phpRack/Test.php
  58. +202 −0 library/phpRack/View.php
  59. +178 −0 library/phpRack/bootstrap.php
  60. +126 −0 library/phpRack/layout/index.css
  61. +513 −0 library/phpRack/layout/index.js
  62. +76 −0 library/phpRack/layout/index.phtml
  63. +154 −0 library/phpRack/layout/jquery-1.4.2.min.js
  64. +62 −0 library/phpRack/layout/layout.phtml
  65. +38 −0 library/phpRack/layout/login.phtml
  66. BIN library/phpRack/layout/logo.png
  67. +10 −0 public/check-env.php
  68. +15 −0 tests/rack-tests/BaseTest.php
  69. +9 −0 tests/rack-tests/CachingTest.php
  70. +25 −0 tests/rack-tests/DatabaseTest.php
  71. +9 −0 tests/rack-tests/ElasticSearchTest.php
  72. +15 −0 tests/rack-tests/SoftwareMiningTest.php
View
7 application/Bootstrap.php
@@ -2,6 +2,11 @@
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
+ public function _initConfig()
+ {
+ Zend_Registry::set('config', $this->getOptions());
+ }
+
public function _initAutoloaderNamespaces()
{
require_once APPLICATION_PATH .
@@ -60,6 +65,8 @@ public function _initLocale()
$locale = new Zend_Locale($config['resources']['locale']['default']);
}
+ // Zend_Locale::setDefault('de'); // check hasLanguage, sonst switch auf default siehe Zend TIcket
+
Zend_Registry::set('Zend_Locale', $locale);
$translator = new Zend_Translate(
View
108 library/phpRack/Adapters/Auth/Abstract.php
@@ -0,0 +1,108 @@
+<?php
+/**
+ * phpRack: Integration Testing Framework
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt. It is also available
+ * through the world-wide-web at this URL: http://www.phprack.com/LICENSE.txt
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@phprack.com so we can send you a copy immediately.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @copyright Copyright (c) phpRack.com
+ * @version $Id: Abstract.php 619 2010-07-19 10:22:05Z yegor256@yahoo.com $
+ * @category phpRack
+ */
+
+/**
+ * Authentication abstract adapter
+ *
+ * @package Adapters
+ * @subpackage Auth
+ */
+abstract class phpRack_Adapters_Auth_Abstract
+{
+ /**
+ * Authentication request
+ *
+ * @var array
+ */
+ protected $_request = array(
+ 'login' => '',
+ 'hash' => ''
+ );
+
+ /**
+ * Authentication options
+ *
+ * @var array
+ */
+ protected $_options = array();
+
+ /**
+ * Set authentication options
+ *
+ * @param array
+ * @see phpRack_Runner_Auth::authenticate()
+ * @return @this
+ */
+ public function setOptions($options)
+ {
+ $this->_options = $options;
+ return $this;
+ }
+
+ /**
+ * Set request login, hash
+ *
+ * @param array
+ * @see phpRack_Runner_Auth::authenticate()
+ * @return @this
+ */
+ public function setRequest($request)
+ {
+ foreach ($request as $key => $value) {
+ $this->_request[$key] = $value;
+ }
+ return $this;
+ }
+
+ /**
+ * Authenticate and return an auth result
+ *
+ * @return phpRack_Runner_Auth_Result
+ * @see phpRack_Runner_Auth::authenticate()
+ */
+ abstract public function authenticate();
+
+ /**
+ * Return an AuthResult
+ *
+ * @param boolean Success/failure of the validation
+ * @param string Optional error message
+ * @return phpRack_Runner_Auth_Result
+ * @see authenticate()
+ */
+ protected function _validated($result, $message = null)
+ {
+ /**
+ * @see phpRack_Runner_Auth_Result
+ */
+ require_once PHPRACK_PATH . '/Runner/Auth/Result.php';
+ return new phpRack_Runner_Auth_Result($result, $message);
+ }
+
+}
View
60 library/phpRack/Adapters/Auth/Array.php
@@ -0,0 +1,60 @@
+<?php
+/**
+ * phpRack: Integration Testing Framework
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt. It is also available
+ * through the world-wide-web at this URL: http://www.phprack.com/LICENSE.txt
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@phprack.com so we can send you a copy immediately.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @copyright Copyright (c) phpRack.com
+ * @version $Id: Array.php 616 2010-07-19 09:47:43Z yegor256@yahoo.com $
+ * @category phpRack
+ */
+
+/**
+ * @see phpRack_Adapters_Auth_Abstract
+ */
+require_once PHPRACK_PATH . '/Adapters/Auth/Abstract.php';
+
+/**
+ * Authentication array adapter
+ *
+ * @package Adapters
+ * @subpackage Auth
+ */
+class phpRack_Adapters_Auth_Array extends phpRack_Adapters_Auth_Abstract
+{
+ /**
+ * Authenticate and return an auth result
+ *
+ * @return phpRack_Runner_Auth_Result
+ * @see phpRack_Adapters_Auth_Abstract::authenticate()
+ */
+ public function authenticate()
+ {
+ foreach ($this->_options['htpasswd'] as $login => $password) {
+ if (($login == $this->_request['login'])
+ && (md5($password) == $this->_request['hash'])
+ ) {
+ return $this->_validated(true);
+ }
+ }
+ return $this->_validated(false, 'Invalid login credentials provided');
+ }
+}
View
69 library/phpRack/Adapters/Auth/File.php
@@ -0,0 +1,69 @@
+<?php
+/**
+ * phpRack: Integration Testing Framework
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt. It is also available
+ * through the world-wide-web at this URL: http://www.phprack.com/LICENSE.txt
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@phprack.com so we can send you a copy immediately.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @copyright Copyright (c) phpRack.com
+ * @version $Id: File.php 616 2010-07-19 09:47:43Z yegor256@yahoo.com $
+ * @category phpRack
+ */
+
+/**
+ * @see phpRack_Adapters_Auth_Abstract
+ */
+require_once PHPRACK_PATH . '/Adapters/Auth/Abstract.php';
+
+/**
+ * Authentication file adapter
+ *
+ * @package Adapters
+ * @subpackage Auth
+ */
+class phpRack_Adapters_Auth_File extends phpRack_Adapters_Auth_Abstract
+{
+ /**
+ * Authenticate and return an auth result
+ *
+ * @return phpRack_Runner_Auth_Result
+ * @see phpRack_Adapters_Auth_Abstract::authenticate()
+ */
+ public function authenticate()
+ {
+ /**
+ * @see phpRack_Adapters_File
+ */
+ require_once PHPRACK_PATH . '/Adapters/File.php';
+ $file = phpRack_Adapters_File::factory($this->_options['htpasswd'])->getFileName();
+
+ $fileContent = file($file);
+ foreach ($fileContent as $line) {
+ list($login, $password) = explode(':', $line, 2);
+ /* Just to make sure we don't analyze some whitespace */
+ $login = trim($login);
+ $password = trim($password);
+ if (($login == $this->_request['login']) && ($password == $this->_request['hash'])) {
+ return $this->_validated(true);
+ }
+ }
+ return $this->_validated(false, 'Invalid login credentials provided');
+ }
+}
View
60 library/phpRack/Adapters/Auth/Plain.php
@@ -0,0 +1,60 @@
+<?php
+/**
+ * phpRack: Integration Testing Framework
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt. It is also available
+ * through the world-wide-web at this URL: http://www.phprack.com/LICENSE.txt
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@phprack.com so we can send you a copy immediately.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @copyright Copyright (c) phpRack.com
+ * @version $Id: Plain.php 616 2010-07-19 09:47:43Z yegor256@yahoo.com $
+ * @category phpRack
+ */
+
+/**
+ * @see phpRack_Adapters_Auth_Abstract
+ */
+require_once PHPRACK_PATH . '/Adapters/Auth/Abstract.php';
+
+/**
+ * Authentication plain adapter
+ *
+ * @package Adapters
+ * @subpackage Auth
+ */
+class phpRack_Adapters_Auth_Plain extends phpRack_Adapters_Auth_Abstract
+{
+ /**
+ * Authenticate and return an auth result
+ *
+ * @return phpRack_Runner_Auth_Result
+ * @see phpRack_Adapters_Auth_Abstract::authenticate()
+ */
+ public function authenticate()
+ {
+ $auth = $this->_options['auth'];
+ if ($auth['username'] != $this->_request['login']) {
+ return $this->_validated(false, 'Invalid login');
+ }
+ if (md5($auth['password']) != $this->_request['hash']) {
+ return $this->_validated(false, 'Invalid password');
+ }
+ return $this->_validated(true);
+ }
+}
View
107 library/phpRack/Adapters/Config.php
@@ -0,0 +1,107 @@
+<?php
+/**
+ * phpRack: Integration Testing Framework
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt. It is also available
+ * through the world-wide-web at this URL: http://www.phprack.com/LICENSE.txt
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@phprack.com so we can send you a copy immediately.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @copyright Copyright (c) phpRack.com
+ * @version $Id: Config.php 545 2010-05-04 09:40:46Z yegor256@yahoo.com $
+ * @category phpRack
+ */
+
+
+/**
+ * Config adapter used for store tests configuration and provide object
+ * oriented access methods
+ *
+ * You can use it like this:
+ *
+ * <code>
+ * $config = new phpRack_Adapters_Config(
+ * array(
+ * 'alpha' => array(
+ * 'beta' => 123,
+ * )
+ * )
+ * );
+ * assert($config->alpha->beta == 123);
+ * </code>
+ *
+ * @package Adapters
+ */
+class phpRack_Adapters_Config
+{
+ /**
+ * Contains array of configuration data
+ *
+ * @var array
+ * @see __construct()
+ */
+ protected $_data;
+
+ /**
+ * Create object oriented config container
+ *
+ * @param array Config data as array
+ * @return void
+ * @see ConfigTest::testConfigIni() and other integration tests
+ */
+ public function __construct(array $data)
+ {
+ $this->_data = array();
+ foreach ($data as $key => $value) {
+ if (is_array($value)) {
+ $this->_data[$key] = new self($value);
+ } else {
+ $this->_data[$key] = $value;
+ }
+ }
+ }
+
+ /**
+ * Magic method which provide access to configuration options
+ *
+ * @param string Name of config option
+ * @return mixed
+ * @throws Exception if config option not exists
+ * @see ConfigTest::testConfigIni() and other integration tests
+ */
+ public function __get($name)
+ {
+ if (!array_key_exists($name, $this->_data)) {
+ throw new Exception("Config option '{$name}' doesn't exist");
+ }
+ return $this->_data[$name];
+ }
+
+ /**
+ * Magic method which provide possibility to check whether some
+ * configuration option exists
+ *
+ * @param string Name of config option
+ * @return boolean
+ * @see ConfigTest::testConfigIni() and other integration tests
+ */
+ public function __isset($name)
+ {
+ return isset($this->_data[$name]);
+ }
+}
View
137 library/phpRack/Adapters/Config/Ini.php
@@ -0,0 +1,137 @@
+<?php
+/**
+ * phpRack: Integration Testing Framework
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt. It is also available
+ * through the world-wide-web at this URL: http://www.phprack.com/LICENSE.txt
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@phprack.com so we can send you a copy immediately.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @copyright Copyright (c) phpRack.com
+ * @version $Id: Ini.php 545 2010-05-04 09:40:46Z yegor256@yahoo.com $
+ * @category phpRack
+ */
+
+/**
+ * @see phpRack_Adapters_Config
+ */
+require_once PHPRACK_PATH . '/Adapters/Config.php';
+
+/**
+ * Config adapter used for store test configuration loaded from INI file
+ *
+ * You can use it like this:
+ *
+ * <code>
+ * // app.ini:
+ * // [production]
+ * // params.db.username = 'test'
+ * $ini = new phpRack_Adapters_Config_Ini('app.ini', 'production');
+ * assert($ini->params->db->username == 'test');
+ * </code>
+ *
+ * @package Adapters
+ */
+class phpRack_Adapters_Config_Ini extends phpRack_Adapters_Config
+{
+ /**
+ * Create config object and load selected section from INI file,
+ * or all sections if $sectionName == null
+ *
+ * @param string Filename of INI file
+ * @param string|null Section name to load, or null to load all
+ * @return void
+ * @throws Exception if INI file not exists
+ * @throws Exception if section not exists in INI file
+ * @see ConfigTest::testConfigIni() and other integration tests
+ */
+ public function __construct($filename, $sectionName = null)
+ {
+ $sections = $this->_loadSectionsFromIniFile($filename);
+ // one section to return
+ if ($sectionName) {
+ if (!array_key_exists($sectionName, $sections)) {
+ throw new Exception("Section '{$sectionName}' doesn't exist in INI file '{$filename}'");
+ }
+ $dataArray = $this->_sectionToArray($sections[$sectionName]);
+ } else {
+ // all sections to return
+ foreach ($sections as $key => $section) {
+ $dataArray[$key] = $this->_sectionToArray($section);
+ }
+ }
+ parent::__construct($dataArray);
+ }
+
+ /**
+ * Convert section with "key.subkey1.subkey2" values as keys
+ * to multidimensional associative array
+ *
+ * @param array section from ini file
+ * @return array
+ * @see __construct()
+ */
+ protected function _sectionToArray($section)
+ {
+ $dataArray = array();
+ foreach ($section as $key => $value) {
+ $currentElement =& $dataArray;
+ foreach (explode('.', $key) as $keyFragment) {
+ $currentElement =& $currentElement[$keyFragment];
+ }
+ $currentElement = $value;
+ }
+ return $dataArray;
+ }
+
+ /**
+ * Load config sections from INI file, taking into account section inheritance
+ *
+ * @param string INI file to load and parse
+ * @return array
+ * @throws Exception if config INI file not exists
+ * @see __construct()
+ */
+ protected function _loadSectionsFromIniFile($filename)
+ {
+ if (!file_exists($filename)) {
+ throw new Exception("INI file '{$filename}' doesn't exist");
+ }
+ $sections = array();
+ $iniFileSections = parse_ini_file($filename, true);
+
+ foreach ($iniFileSections as $sectionName => $data) {
+ // divide section name to check it have some parent ([section : parent])
+ $nameParts = explode(':', $sectionName);
+ $thisSectionName = trim($nameParts[0]);
+
+ // if section have parent
+ if (isset($nameParts[1])) {
+ $parentSectionName = trim($nameParts[1]);
+ // merge current section values, with parent values
+ $data = array_merge(
+ $sections[$parentSectionName],
+ $data
+ );
+ }
+ $sections[$thisSectionName] = $data;
+ }
+
+ return $sections;
+ }
+}
View
105 library/phpRack/Adapters/ConnectionMonitor.php
@@ -0,0 +1,105 @@
+<?php
+/**
+ * phpRack: Integration Testing Framework
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt. It is also available
+ * through the world-wide-web at this URL: http://www.phprack.com/LICENSE.txt
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@phprack.com so we can send you a copy immediately.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @copyright Copyright (c) phpRack.com
+ * @version $Id: ConnectionMonitor.php 545 2010-05-04 09:40:46Z yegor256@yahoo.com $
+ * @category phpRack
+ */
+
+/**
+ * Connection monitor used to check whether connection between client
+ * and our script is still opened
+ *
+ * @package Adapters
+ * @author netcoderpl@gmail.com
+ */
+class phpRack_Adapters_ConnectionMonitor
+{
+ /**
+ * Connection status last checked time
+ *
+ * @var int
+ * @see ping()
+ */
+ private $_lastCheckTime = null;
+
+ /**
+ * Connection status checking interval
+ *
+ * @var int
+ * @see ping()
+ */
+ private $_checkInterval = 1; // 1 second
+
+ /**
+ * phpRack_Adapters_ConnectionMonitor instance
+ *
+ * @var phpRack_Adapters_ConnectionMonitor
+ * @see getInstance()
+ */
+ private static $_instance;
+
+ /**
+ * Get phpRack_Adapters_ConnectionMonitor instance
+ *
+ * @return phpRack_Adapters_ConnectionMonitor
+ */
+ public static function getInstance()
+ {
+ if (self::$_instance === null) {
+ self::$_instance = new self();
+ }
+
+ return self::$_instance;
+ }
+
+ /**
+ * Check client connection is still opened. We can check it by sending
+ * space char " " every $this->_checkInterval second.
+ *
+ * After that PHP can detect connection status. If it was closed objects
+ * destructors will be automatically executed and script stop work.
+ *
+ * @return void
+ */
+ public function ping()
+ {
+ if ($this->_lastCheckTime === null
+ || $this->_lastCheckTime + $this->_checkInterval < time()
+ ) {
+ echo ' ';
+
+ /**
+ * Bypass output buffering, without it PHP may not recognize that
+ * connection is closed
+ */
+ if (ob_get_level()) {
+ ob_flush();
+ }
+
+ flush();
+ $this->_lastCheckTime = time();
+ }
+ }
+}
View
64 library/phpRack/Adapters/Cpu.php
@@ -0,0 +1,64 @@
+<?php
+/**
+ * phpRack: Integration Testing Framework
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt. It is also available
+ * through the world-wide-web at this URL: http://www.phprack.com/LICENSE.txt
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@phprack.com so we can send you a copy immediately.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @copyright Copyright (c) phpRack.com
+ * @version $Id: Cpu.php 545 2010-05-04 09:40:46Z yegor256@yahoo.com $
+ * @category phpRack
+ */
+
+
+/**
+ * CPU adapter used to get details about available processor
+ *
+ * @package Adapters
+ */
+class phpRack_Adapters_Cpu
+{
+ /**
+ * CPU adapter factory return adapter depending on operating system
+ *
+ * @return phpRack_Adapters_Cpu_Abstract
+ * @throws Exception If OS is not supported
+ * @see For MacOS I think we should use system_profiler shell command.
+ * After that we can parse it output in similar way like we do it for
+ * Windows or Linux
+ * @todo #17 How about Mac OS? There is no /proc directory in Mac OS
+ */
+ public static function factory()
+ {
+ /**
+ * @see phpRack_Adapters_Os
+ */
+ require_once PHPRACK_PATH . '/Adapters/Os.php';
+ $os = phpRack_Adapters_Os::get();
+ $classFile = PHPRACK_PATH . '/Adapters/Cpu/' . ucfirst($os) . '.php';
+
+ if (!file_exists($classFile)) {
+ throw new Exception("OS '{$os}' is not supported yet");
+ }
+ eval ('require_once $classFile;'); // for ZCA validation
+ $className = 'phpRack_Adapters_Cpu_' . ucfirst($os);
+ return new $className();
+ }
+}
View
56 library/phpRack/Adapters/Cpu/Abstract.php
@@ -0,0 +1,56 @@
+<?php
+/**
+ * phpRack: Integration Testing Framework
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt. It is also available
+ * through the world-wide-web at this URL: http://www.phprack.com/LICENSE.txt
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@phprack.com so we can send you a copy immediately.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @copyright Copyright (c) phpRack.com
+ * @version $Id: Abstract.php 545 2010-05-04 09:40:46Z yegor256@yahoo.com $
+ * @category phpRack
+ */
+
+/**
+ * Abstract CPU adapter
+ *
+ * @package Adapters
+ * @subpackage Cpu
+ * @see phpRack_Adapters_Cpu::factory()
+ */
+abstract class phpRack_Adapters_Cpu_Abstract
+{
+ /**
+ * Get CPU BogoMips
+ *
+ * @return float
+ * @throws Exception If unable to get BogoMips
+ * @see phpRack_Package_Cpu_Performance::atLeast()
+ */
+ abstract public function getBogoMips();
+
+ /**
+ * Get CPU frequency in MHz
+ *
+ * @return float
+ * @throws Exception If can't get cpu frequency
+ * @see getBogoMips()
+ */
+ abstract public function getCpuFrequency();
+}
View
86 library/phpRack/Adapters/Cpu/Darwin.php
@@ -0,0 +1,86 @@
+<?php
+/**
+ * phpRack: Integration Testing Framework
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt. It is also available
+ * through the world-wide-web at this URL: http://www.phprack.com/LICENSE.txt
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@phprack.com so we can send you a copy immediately.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @copyright Copyright (c) phpRack.com
+ * @version $Id: Linux.php 447 2010-04-24 03:59:09Z yegor256@yahoo.com $
+ * @category phpRack
+ */
+
+/**
+ * @see phpRack_Adapters_Cpu_Abstract
+ */
+require_once PHPRACK_PATH . '/Adapters/Cpu/Abstract.php';
+
+/**
+ * Darwin CPU Adapter (Mac OS)
+ *
+ * @package Adapters
+ * @subpackage Cpu
+ * @todo #17 Should be implemented
+ */
+class phpRack_Adapters_Cpu_Darwin extends phpRack_Adapters_Cpu_Abstract
+{
+ /**
+ * Get CPU BogoMips
+ *
+ * @return float
+ * @see phpRack_Package_Cpu_Performance::atLeast()
+ * @see phpRack_Adapters_Cpu_Abstract::getBogoMips()
+ */
+ public function getBogoMips()
+ {
+ return $this->getCpuFrequency() * 2;
+ }
+
+ /**
+ * Get CPU frequency in MHz
+ *
+ * @return float
+ * @throws Exception If can't get cpu frequency
+ * @see getBogoMips()
+ * @see phpRack_Adapters_Cpu_Abstract::getCpuFrequency()
+ */
+ public function getCpuFrequency()
+ {
+ /**
+ * @see phpRack_Adapters_Shell_Command
+ */
+ require_once PHPRACK_PATH . '/Adapters/Shell/Command.php';
+ $data = phpRack_Adapters_Shell_Command::factory(
+ 'system_profiler SPHardwareDataType -xml 2>&1'
+ )->run();
+ $xml = simplexml_load_string($data);
+ if (!($xml instanceof SimpleXMLElement)) {
+ throw new Exception("Invalid result from system_profiler: '{$data}'");
+ }
+ $nodes = $xml->xpath('//string[preceding-sibling::key="current_processor_speed"]');
+ $node = strval($nodes[0]);
+
+ if (strpos($node, 'GHz') === false) {
+ throw new Exception("Strange frequency from system_profiler: '{$node}'");
+ }
+
+ return floatval($node) * 1000;
+ }
+}
View
110 library/phpRack/Adapters/Cpu/Linux.php
@@ -0,0 +1,110 @@
+<?php
+/**
+ * phpRack: Integration Testing Framework
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt. It is also available
+ * through the world-wide-web at this URL: http://www.phprack.com/LICENSE.txt
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@phprack.com so we can send you a copy immediately.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @copyright Copyright (c) phpRack.com
+ * @version $Id: Linux.php 545 2010-05-04 09:40:46Z yegor256@yahoo.com $
+ * @category phpRack
+ */
+
+/**
+ * @see phpRack_Adapters_Cpu_Abstract
+ */
+require_once PHPRACK_PATH . '/Adapters/Cpu/Abstract.php';
+
+/**
+ * Linux CPU Adapter
+ *
+ * @package Adapters
+ * @subpackage Cpu
+ */
+class phpRack_Adapters_Cpu_Linux extends phpRack_Adapters_Cpu_Abstract
+{
+ /**
+ * Get CPU BogoMips
+ *
+ * @return float
+ * @throws Exception If unable to get BogoMips
+ * @see phpRack_Package_Cpu_Performance::atLeast()
+ * @see phpRack_Adapters_Cpu_Abstract::getBogoMips()
+ */
+ public function getBogoMips()
+ {
+ $matches = array();
+ // on Linux parse ouput of "cat /proc/cpuinfo" command
+ if (
+ !preg_match(
+ '/^bogomips\s*:\s*(.*)/m',
+ $this->_getCpuInfoData(), // Exception is possible here
+ $matches
+ )
+ ) {
+ throw new Exception("Unable to find bogomips value in cpuinfo");
+ }
+ return floatval($matches[1]);
+ }
+
+ /**
+ * Get CPU frequency in MHz
+ *
+ * @return float
+ * @throws Exception If can't get cpu frequency
+ * @see getBogoMips()
+ * @see phpRack_Adapters_Cpu_Abstract::getCpuFrequency()
+ */
+ public function getCpuFrequency()
+ {
+ // on Linux parse ouput of "cat /proc/cpuinfo" command
+ $matches = array();
+ if (
+ !preg_match(
+ '/^cpu MHz\s*:\s*(.*)/m',
+ $this->_getCpuInfoData(), // Exception is possible here
+ $matches
+ )
+ ) {
+ throw new Exception('Unable to find CPU MHz value in cpuinfo');
+ }
+ return floatval($matches[1]);
+ }
+
+ /**
+ * Get result of "cat /proc/cpuinfo" shell command execution
+ *
+ * @return string
+ * @throws Exception If unable to execute shell command
+ * @see getBogoMips()
+ * @see getCpuFrequency()
+ */
+ private function _getCpuInfoData()
+ {
+ $command = 'cat /proc/cpuinfo';
+ /**
+ * @see phpRack_Adapters_Shell_Command
+ */
+ require_once PHPRACK_PATH . '/Adapters/Shell/Command.php';
+ // Exception is possible here
+ $result = phpRack_Adapters_Shell_Command::factory($command)->run();
+ return $result;
+ }
+}
View
99 library/phpRack/Adapters/Cpu/Windows.php
@@ -0,0 +1,99 @@
+<?php
+/**
+ * phpRack: Integration Testing Framework
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt. It is also available
+ * through the world-wide-web at this URL: http://www.phprack.com/LICENSE.txt
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@phprack.com so we can send you a copy immediately.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @copyright Copyright (c) phpRack.com
+ * @version $Id: Windows.php 545 2010-05-04 09:40:46Z yegor256@yahoo.com $
+ * @category phpRack
+ */
+
+/**
+ * @see phpRack_Adapters_Cpu_Abstract
+ */
+require_once PHPRACK_PATH . '/Adapters/Cpu/Abstract.php';
+
+/**
+ * Windows CPU Adapter
+ *
+ * @package Adapters
+ * @subpackage Cpu
+ */
+class phpRack_Adapters_Cpu_Windows extends phpRack_Adapters_Cpu_Abstract
+{
+ /**
+ * Get CPU BogoMips
+ *
+ * @return float
+ * @throws Exception If unable to get BogoMips
+ * @see phpRack_Package_Cpu_Performance::atLeast()
+ * @see phpRack_Adapters_Cpu_Abstract::getBogoMips()
+ */
+ public function getBogoMips()
+ {
+ /**
+ * On Windows return approximated result which can be calculated using
+ * this formula: CPU clock * 2
+ */
+ return $this->getCpuFrequency() * 2;
+ }
+
+ /**
+ * Get CPU frequency in MHz
+ *
+ * @return float
+ * @throws Exception If can't get cpu frequency
+ * @see getBogoMips()
+ * @see phpRack_Adapters_Cpu_Abstract::getCpuFrequency()
+ */
+ public function getCpuFrequency()
+ {
+ $wmi = new COM('Winmgmts://');
+ $query = 'SELECT maxClockSpeed FROM CIM_Processor';
+
+ // get CPUS-s data
+ $cpus = $wmi->execquery($query);
+ $maxClockSpeed = 0;
+
+ /**
+ * We must iterate through all CPU-s because $cpus is object
+ * and we can't get single entry by $cpus[0]->maxClockSpeed
+ */
+ foreach ($cpus as $cpu) {
+ $maxClockSpeed = max($maxClockSpeed, $cpu->maxClockSpeed);
+ }
+
+ /**
+ * If returned $cpus set was empty(some error occured)
+ *
+ * We can't check it earlier with empty($cpus) or count($cpus)
+ * because $cpus is object and doesn't implement countable
+ * interface.
+ */
+ if (!$maxClockSpeed) {
+ throw new Exception(
+ "Unable to get maxClockSpeed using COM 'Winmgmts://' and '{$query}' query"
+ );
+ }
+ return floatval($maxClockSpeed);
+ }
+}
View
98 library/phpRack/Adapters/Db/Abstract.php
@@ -0,0 +1,98 @@
+<?php
+/**
+ * phpRack: Integration Testing Framework
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt. It is also available
+ * through the world-wide-web at this URL: http://www.phprack.com/LICENSE.txt
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@phprack.com so we can send you a copy immediately.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @copyright Copyright (c) phpRack.com
+ * @version $Id: Abstract.php 545 2010-05-04 09:40:46Z yegor256@yahoo.com $
+ * @category phpRack
+ */
+
+/**
+ * Abstract adapter for DB connectivity
+ *
+ * @package Adapters
+ * @subpackage Db
+ */
+abstract class phpRack_Adapters_Db_Abstract
+{
+
+ /**
+ * Connect to the server
+ *
+ * @param string JDBC URL to connect to the server
+ * @return void
+ * @see http://java.sun.com/docs/books/tutorial/jdbc/basics/connecting.html
+ * @throws Exception If something wrong happens there
+ */
+ abstract public function connect($url);
+
+ /**
+ * Execute SQL query on the server
+ *
+ * @param string SQL query
+ * @return string Raw result from the server, in text
+ * @throws Exception If something wrong happens there
+ */
+ abstract public function query($sql);
+
+ /**
+ * Parse JDBC URL and return its components
+ *
+ * This method matches URLSs like:
+ *
+ * <code>
+ * jdbc:mysql://localhost:3306/test?username=login&password=password
+ * jdbc:mysql://localhost:3306/test
+ * jdbc:mysql://localhost:3306
+ * jdbc:mysql://localhost
+ * </code>
+ *
+ * Mandatory parts of the URL are: "adapter", "host". All other params are
+ * optional and could be omitted.
+ *
+ * @param string JDBC URL to parse
+ * @throws Exception If JDBC URL have wrong format
+ * @return array We set "adapter", "host", "port", "database", "params"
+ */
+ protected function _parseJdbcUrl($url)
+ {
+ $pattern = '#^jdbc:(?P<adapter>[^:]+)'
+ . '://(?P<host>[^:/]+)'
+ . '(?::(?P<port>\d+))?'
+ . '(?:/(?P<database>[^?]+))?'
+ . '(?:\?(?P<params>.*))?$#';
+
+ $matches = array();
+ if (!preg_match($pattern, $url, $matches)) {
+ throw new Exception('JDBC URL parse error');
+ }
+
+ // Convert params string to array
+ if (isset($matches['params'])) {
+ $paramsString = $matches['params'];
+ parse_str($paramsString, $matches['params']);
+ }
+
+ return $matches;
+ }
+}
View
326 library/phpRack/Adapters/Db/Mysql.php
@@ -0,0 +1,326 @@
+<?php
+/**
+ * phpRack: Integration Testing Framework
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt. It is also available
+ * through the world-wide-web at this URL: http://www.phprack.com/LICENSE.txt
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@phprack.com so we can send you a copy immediately.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @copyright Copyright (c) phpRack.com
+ * @version $Id: Mysql.php 611 2010-07-12 14:23:40Z yegor256@yahoo.com $
+ * @category phpRack
+ */
+
+/**
+ * @see phpRack_Adapters_Db_Abstract
+ */
+require_once PHPRACK_PATH . '/Adapters/Db/Abstract.php';
+
+/**
+ * MySQL adapter
+ *
+ * The class is using native PHP mysql_ methods, without any specific
+ * extensions like PDO or Mysqli.
+ *
+ * @package Adapters
+ * @subpackage Db
+ */
+class phpRack_Adapters_Db_Mysql extends phpRack_Adapters_Db_Abstract
+{
+
+ /**
+ * Current mysql connection link identifier
+ *
+ * @var int Result of mysql_connect()
+ * @see connect()
+ */
+ private $_connection;
+
+ /**
+ * Destructor automatically close opened connection
+ *
+ * @return void
+ */
+ public function __destruct()
+ {
+ $this->closeConnection();
+ }
+
+ /**
+ * Connect to the server
+ *
+ * @param string JDBC URL to connect to the server
+ * @return void
+ * @see http://java.sun.com/docs/books/tutorial/jdbc/basics/connecting.html
+ * @throws Exception If MySQL extension is not loaded
+ * @throws Exception If any of the required params are missed in the URL
+ */
+ public function connect($url)
+ {
+ // Parse JDBC URl, and throw exception if it is invalid
+ $jdbcUrlParts = $this->_parseJdbcUrl($url);
+
+ if (!extension_loaded('mysql')) {
+ throw new Exception('MySQL extension is not loaded');
+ }
+
+ $server = $jdbcUrlParts['host'];
+
+ // Check whether server port was set in JDBC URL
+ if (isset($jdbcUrlParts['port'])) {
+ $server .= ':' . $jdbcUrlParts['port'];
+ }
+
+ // Check whether username was set in JDBC URL
+ if (isset($jdbcUrlParts['params']['username'])) {
+ $username = $jdbcUrlParts['params']['username'];
+ } else {
+ $username = ini_get('mysql.default_user');
+ }
+
+ // Check whether password was set in JDBC URL
+ if (isset($jdbcUrlParts['params']['password'])) {
+ $password = $jdbcUrlParts['params']['password'];
+ } else {
+ $password = ini_get('mysql.default_password');
+ }
+
+ // Try to connect with MySQL server
+ $this->_connection = @mysql_connect($server, $username, $password);
+
+ if (!$this->_connection) {
+ throw new Exception("Can't connect to MySQL server: '{$server}'");
+ }
+
+ // Check whether database was set in JDBC URL
+ if (!empty($jdbcUrlParts['database'])) {
+ // Try to set this database as current
+ if (!@mysql_select_db($jdbcUrlParts['database'], $this->_connection)) {
+ throw new Exception("Can't select database '{$jdbcUrlParts['database']}'");
+ }
+ }
+ }
+
+ /**
+ * Execute SQL query on the server
+ *
+ * @param string SQL query
+ * @return string Raw result from the server, in text
+ * @throws Exception If something wrong happens there
+ * @see mysql_query()
+ */
+ public function query($sql)
+ {
+ if (!$this->_connection) {
+ throw new Exception('connect() method should be called before');
+ }
+
+ $result = mysql_query($sql, $this->_connection);
+
+ // INSERT, UPDATE, DELETE, DROP, USE etc type queries
+ // on success return just true
+ if ($result === true) {
+ return '';
+ }
+
+ // Something goes wrong
+ if ($result === false) {
+ throw new Exception('MySQL query error: ' . mysql_error());
+ }
+
+ // SELECT, SHOW type queries
+ // if MySQL server returned some rows, format them for return
+ if (mysql_num_rows($result)) {
+ /**
+ * @see phpRack_Adapters_Db_Mysql_Result_Formatter
+ */
+ require_once PHPRACK_PATH . '/Adapters/Db/Mysql/Result/Formatter.php';
+ $response = phpRack_Adapters_Db_Mysql_Result_Formatter::formatResult($result);
+ } else {
+ $response = '';
+ }
+
+ return $response;
+ }
+
+ /**
+ * Show database schema
+ *
+ * @return string Raw result from the server, in text
+ * @throws Exception If connect() method wasn't executed earlier
+ * @throws Exception If no database was selected as current
+ * @throws Exception Passed from query()
+ * @see phpRack_Package_Db_Mysql::showSchema()
+ */
+ public function showSchema()
+ {
+ if (!$this->isConnected()) {
+ throw new Exception('You must call connect() method before');
+ }
+
+ if (!$this->isDatabaseSelected()) {
+ throw new Exception('No database selected yet');
+ }
+
+ $response = '';
+ $queries = array('SHOW TABLES', 'SHOW TRIGGERS', 'SHOW PROCEDURE STATUS');
+ foreach ($queries as $query) {
+ $response .= sprintf(
+ "'%s' returns:\n%s\n",
+ $query,
+ $result = $this->query($query) // Exception is possible here
+ );
+
+ if ($query == 'SHOW TABLES') {
+ // foreach table show CREATE TABLE
+ foreach (array_slice(explode("\n", $result), 1, -1) as $tableName) {
+ $query = sprintf("SHOW CREATE TABLE `%s`", addcslashes(trim($tableName), '`'));
+ $response .= sprintf(
+ "'%s' returns:\n%s\n",
+ $query,
+ $this->query($query) // Exception is possible
+ );
+ }
+ }
+ }
+ return $response;
+ }
+
+ /**
+ * Show connections and their status
+ *
+ * @return string Raw result from the server, in text
+ * @throws Exception If connect() method wasn't executed earlier
+ * @see phpRack_Package_Db_Mysql::showConnections()
+ */
+ public function showConnections()
+ {
+ if (!$this->isConnected()) {
+ throw new Exception('You must call connect() method before');
+ }
+
+ $answer = $this->query('SHOW GRANTS FOR CURRENT_USER');
+ if (!preg_match('~GRANT (PROCESS|ALL)~', $answer)) {
+ return false;
+ }
+
+ return $this->query('SHOW FULL PROCESSLIST');
+ }
+
+ /**
+ * Show server info
+ *
+ * @return string Raw result from the server, in text
+ * @throws Exception If connect() method wasn't executed earlier
+ * @see phpRack_Package_Db_Mysql::showServerInfo()
+ */
+ public function showServerInfo()
+ {
+ $out = '';
+
+ // Users privileges. We must check grants for it
+ $privileges = $this->query('SHOW GRANTS FOR CURRENT_USER');
+ if (preg_match('~GRANT (ALL|SELECT ON (`mysql`|\*)\.\*)~', $privileges)) {
+ $dbUsers = $this->query(
+ 'SELECT CONCAT(User, "\'@\'", Host) FROM `mysql`.`user`'
+ );
+ $dbUsers = explode("\n", rtrim($dbUsers, "\n"));
+ $dbUsers = array_map('trim', $dbUsers);
+ for ($i=1; $i<count($dbUsers); $i++) {
+ $priv = $this->query("SHOW GRANTS FOR '{$dbUsers[$i]}'");
+ $out .= preg_replace('~GRANT (.+?) TO.*~', '\1', trim($priv));
+ $out .= "\n\n";
+ }
+ }
+
+ // Table stats. We do not need to check privileges here
+ $dbList = $this->query('SHOW DATABASES');
+ $dbList = explode("\n", rtrim($dbList, "\n"));
+ if (count($dbList) > 2) {
+ $dbList = array_map('trim', $dbList);
+ for ($i=2; $i<count($dbList); $i++) {
+ $out .= "Database: {$dbList[$i]}\n";
+ $out .= $this->query(
+ "SELECT COUNT(TABLE_NAME) AS 'Count Of Tables',
+ SUM(TABLE_ROWS) AS 'Count Of Rows',
+ SUM(DATA_LENGTH) AS 'Size Of Data',
+ SUM(INDEX_LENGTH) AS 'Index Size'
+ FROM `information_schema`.`TABLES`
+ WHERE TABLE_SCHEMA = '{$dbList[$i]}'"
+ );
+ $out .= "\n";
+ }
+ }
+
+ // Mysql version. We do not need to check privileges here
+ $out .= $this->query("SHOW VARIABLES LIKE 'version'") . "\n";
+
+ // Mysql variables. We do not need to check privileges here
+ $out .= $this->query('SHOW GLOBAL VARIABLES') . "\n";
+ return $out;
+ }
+
+ /**
+ * Return true if adapter is connected with database
+ *
+ * @return boolean
+ * @see $this->_connection
+ */
+ public function isConnected()
+ {
+ if ($this->_connection) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * Return true if some database was selected for use
+ *
+ * @return boolean
+ */
+ public function isDatabaseSelected()
+ {
+ $result = $this->query('SELECT DATABASE()');
+ /**
+ * @see phpRack_Adapters_Db_Mysql_Result_Formatter
+ */
+ require_once PHPRACK_PATH . '/Adapters/Db/Mysql/Result/Formatter.php';
+
+ if (trim(phpRack_Adapters_Db_Mysql_Result_Formatter::removeColumnHeadersLine($result)) == '') {
+ return false;
+ } else {
+ return true;
+ }
+ }
+
+ /**
+ * Close connection to database, if was earlier opened
+ *
+ * @return void
+ */
+ public function closeConnection()
+ {
+ if (is_resource($this->_connection)) {
+ mysql_close($this->_connection);
+ $this->_connection = null;
+ }
+ }
+}
View
114 library/phpRack/Adapters/Db/Mysql/Result/Formatter.php
@@ -0,0 +1,114 @@
+<?php
+/**
+ * phpRack: Integration Testing Framework
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt. It is also available
+ * through the world-wide-web at this URL: http://www.phprack.com/LICENSE.txt
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@phprack.com so we can send you a copy immediately.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @copyright Copyright (c) phpRack.com
+ * @version $Id: Formatter.php 611 2010-07-12 14:23:40Z yegor256@yahoo.com $
+ * @category phpRack
+ */
+
+/**
+ * MySQL adapter result formatter
+ *
+ * @package Adapters
+ * @subpackage Db
+ */
+class phpRack_Adapters_Db_Mysql_Result_Formatter
+{
+ /**
+ * Format SQL query result with spaces for better readability
+ *
+ * @param resource returned from mysql_query()
+ * @return string formatted query result as plain text
+ * @see phpRack_Adapters_Db_Mysql::query()
+ */
+ public static function formatResult($result)
+ {
+ $response = '';
+ // margin between columns in spaces
+ $columnsMargin = 2;
+
+ // create array for storing columns meta data
+ $columns = array_fill(0, mysql_num_fields($result), array());
+
+ // determine columns lenght and create columns headers
+ foreach ($columns as $columnIndex => &$column) {
+ // get column data for this index
+ $column['meta'] = mysql_fetch_field($result, $columnIndex);
+
+ // set what length should has this columns (get max length from data and column name)
+ $column['length'] = max(strlen($column['meta']->name), $column['meta']->max_length);
+
+ // add centered column header
+ $response .= str_pad($column['meta']->name, $column['length'], ' ', STR_PAD_BOTH);
+
+ // add margin between columns for better readability
+ $response .= str_repeat(' ', $columnsMargin);
+ }
+
+ $response .= "\n";
+
+ // foreach row in result
+ while (false !== ($row = mysql_fetch_row($result))) {
+ // foreach column in result row
+ foreach ($row as $columnIndex => $value) {
+ $column = &$columns[$columnIndex];
+
+ // choose which padding type we should use
+ if ($column['meta']->numeric) {
+ $padType = STR_PAD_LEFT;
+ } else {
+ $padType = STR_PAD_RIGHT;
+ }
+ // pad value with spaces for have equal width in all rows
+ $response .= str_pad($value, $column['length'], ' ', $padType);
+
+ // add margin between columns for better readability
+ $response .= str_repeat(' ', $columnsMargin);
+ }
+ $response .= "\n";
+ }
+
+ return $response;
+ }
+
+ /**
+ * Remove header line from query result, which is added by _formatResult()
+ * method. Sometimes we just need raw result without this extra line.
+ *
+ * @param string query result with header line
+ * @return string
+ * @see formatResult()
+ * @see phpRack_Adapters_Db_Mysql::isDatabaseSelected()
+ */
+ public static function removeColumnHeadersLine($result)
+ {
+ $pos = strpos($result, "\n");
+ // If we have only headers line
+ if ($pos === false || strlen($result) == $pos + 1) {
+ return '';
+ }
+ return substr($result, $pos + 1);
+ }
+
+}
View
114 library/phpRack/Adapters/File.php
@@ -0,0 +1,114 @@
+<?php
+/**
+ * phpRack: Integration Testing Framework
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt. It is also available
+ * through the world-wide-web at this URL: http://www.phprack.com/LICENSE.txt
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@phprack.com so we can send you a copy immediately.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @copyright Copyright (c) phpRack.com
+ * @version $Id: Package.php 82 2010-03-16 13:46:41Z yegor256@yahoo.com $
+ * @category phpRack
+ */
+
+/**
+ * One file to work with
+ *
+ * @package Adapters
+ */
+class phpRack_Adapters_File
+{
+
+ /**
+ * Absolute file name
+ *
+ * @var string
+ */
+ protected $_fileName;
+
+ /**
+ * Constructor
+ *
+ * @param string File name
+ * @return void
+ * @see _convertFileName()
+ */
+ public function __construct($fileName)
+ {
+ $this->_fileName = $this->_convertFileName($fileName);
+ }
+
+ /**
+ * Create an instance of this class
+ *
+ * @param string File name
+ * @return phpRack_Adapters_File
+ * @see _convertFileName()
+ */
+ public static function factory($fileName)
+ {
+ return new self($fileName);
+ }
+
+ /**
+ * Returns an absolute file name
+ *
+ * @param string File name
+ * @return string
+ * @see _convertFileName()
+ */
+ public function getFileName()
+ {
+ return $this->_fileName;
+ }
+
+ /**
+ * Converts file name from any form possible to an absolute path
+ *
+ * For example, you can use it like this, inside any package:
+ *
+ * <code>
+ * // convert it to PHPRACK_PATH . '/../test.php'
+ * $file = $this->_convertFileName('/../test.php');
+ * // returns '/home/my/test.php'
+ * $file = $this->_convertFileName('/home/my/test.php');
+ * // returns 'c:/Windows/System32/my.dll'
+ * $file = $this->_convertFileName('c:/Windows/System32/my.dll');
+ * </code>
+ *
+ * If the file not found, it doesn't affect the result of this method. The
+ * result always contain an absolute path of the file. This method doesn't
+ * do any operations with the file, just re-constructs its name.
+ *
+ * @param string File name, as it is provided (raw form)
+ * @return string
+ */
+ protected function _convertFileName($fileName)
+ {
+ switch (true) {
+ // relative name started with '/..', or '../', or './'
+ case preg_match('/^\/?\.\.?\//', $fileName):
+ return PHPRACK_PATH . '/' . $fileName;
+
+ default:
+ return $fileName;
+ }
+ }
+
+}
View
185 library/phpRack/Adapters/Files/DirectoryFilterIterator.php
@@ -0,0 +1,185 @@
+<?php
+/**
+ * phpRack: Integration Testing Framework
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt. It is also available
+ * through the world-wide-web at this URL: http://www.phprack.com/LICENSE.txt
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@phprack.com so we can send you a copy immediately.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @copyright Copyright (c) phpRack.com
+ * @version $Id: DirectoryFilterIterator.php 611 2010-07-12 14:23:40Z yegor256@yahoo.com $
+ * @category phpRack
+ */
+
+/**
+ * Iterator filter class which help to get only files which match filter rules
+ *
+ * @package Adapters
+ * @subpackage Files
+ * @see phpRack_Package_Disc::showDirectory()
+ */
+class phpRack_Adapters_Files_DirectoryFilterIterator extends FilterIterator
+{
+
+ /**
+ * Directory we're iterating
+ *
+ * @var string
+ * @see __construct()
+ */
+ protected $_dir;
+
+ /**
+ * Maximum depth to be visible
+ *
+ * @var integer
+ * @see setMaxDepth()
+ */
+ private $_maxDepth = null;
+
+ /**
+ * Regular expression patterns used to determine what files should be ignored
+ *
+ * @var string[]
+ */
+ private $_excludePatterns;
+
+ /**
+ * Regular expression pattern used to determine what files should returned
+ *
+ * @var string
+ */
+ private $_extensionsPattern;
+
+ /**
+ * Constructor, private, don't call it directly, instead use factory()
+ *
+ * @param string Path
+ * @return void
+ * @see factory()
+ */
+ public function __construct($dir)
+ {
+ parent::__construct(
+ new RecursiveIteratorIterator(
+ new RecursiveDirectoryIterator($dir),
+ RecursiveIteratorIterator::SELF_FIRST
+ )
+ );
+ $this->_dir = $dir;
+ }
+
+ /**
+ * Create new iterator from directory path
+ *
+ * @param string Path
+ * @return phpRack_Adapters_Files_DirectoryFilterIterator
+ */
+ public static function factory($dir)
+ {
+ return new self($dir);
+ }
+
+ /**
+ * Set which extensions will be used as whitelist
+ *
+ * @param string|array Comma separated list of extensions, or list of them
+ * @return $this
+ */
+ public function setExtensions($extensions)
+ {
+ if (!is_array($extensions)) {
+ $extensions = explode(',', $extensions);
+ }
+
+ // Escape extension special chars to have always valid regular expression
+ foreach ($extensions as &$extension) {
+ preg_quote(trim($extension));
+ }
+
+ $this->_extensionsPattern = '#(\.' . implode('|', $extensions). '$)#';
+ return $this;
+ }
+
+ /**
+ * Set pattern which will be used as blacklist
+ *
+ * @param string|array Regular expression pattern, or list of them
+ * @return $this
+ */
+ public function setExclude($excludePatterns)
+ {
+ if (!is_array($excludePatterns)) {
+ $excludePatterns = array($excludePatterns);
+ }
+ $this->_excludePatterns = $excludePatterns;
+ return $this;
+ }
+
+ /**
+ * Set maximum directory depth
+ *
+ * @param integer Maximum depth
+ * @return $this
+ */
+ public function setMaxDepth($maxDepth)
+ {
+ $this->_maxDepth = $maxDepth;
+ return $this;
+ }
+
+ /**
+ * Callback function which will be called to determine current file should be in collection or no
+ *
+ * @return boolean
+ */
+ public function accept()
+ {
+ $file = $this->current();
+
+ // Ignore "dots files" which appear in some systems
+ if (trim($file, '.') == '') {
+ return false;
+ }
+
+ if (!is_null($this->_maxDepth)
+ && substr_count(substr($file, strlen($this->_dir) + 1), '/') > $this->_maxDepth
+ ) {
+ return false;
+ }
+
+ // Ignore files which don't match extensionsPattern
+ if ($this->_extensionsPattern && !preg_match($this->_extensionsPattern, $file)) {
+ return false;
+ }
+
+ // Ignore files which match excludePattern
+ if ($this->_excludePatterns) {
+ foreach ($this->_excludePatterns as $pattern) {
+ if (preg_match($pattern, $file)) {
+ return false;
+ }
+ }
+ }
+
+ // Everything rest is allowable
+ return true;
+ }
+
+}
View
63 library/phpRack/Adapters/Notifier/Mail.php
@@ -0,0 +1,63 @@
+<?php
+/**
+ * phpRack: Integration Testing Framework
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt. It is also available
+ * through the world-wide-web at this URL: http://www.phprack.com/LICENSE.txt
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@phprack.com so we can send you a copy immediately.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @copyright Copyright (c) phpRack.com
+ * @version $Id: Mail.php 545 2010-05-04 09:40:46Z yegor256@yahoo.com $
+ * @category phpRack
+ */
+
+/**
+ * Mail adapter used for mailing phpRack reports
+ *
+ * @package Adapters
+ */
+class phpRack_Adapters_Notifier_Mail
+{
+ /**
+ * Factory method to get one of Sendmail or Smtp class instances.
+ *
+ * Depends on options specified. Available options depend on transport
+ * you choose.
+ *
+ * @see phpRack_Adapters_Notifier_Mail_Smtp
+ * @see phpRack_Adapters_Notifier_Mail_Sendmail
+ * @param array List of parameters
+ * @return phpRack_Adapters_Mail
+ * @throws Exception
+ */
+ public static function factory($class = 'sendmail', array $params = array())
+ {
+ $transport = ucfirst(strtolower($class));
+ /**
+ * @see phpRack_Adapters_Notifier_Mail_Abstract
+ */
+ $classFile = PHPRACK_PATH . "/Adapters/Notifier/Mail/{$transport}.php";
+ if (!file_exists($classFile)) {
+ throw new Exception("Transport {$transport} is absent");
+ }
+ eval("require_once '{$classFile}';"); // for ZCA validation
+ $transportClass = 'phpRack_Adapters_Notifier_Mail_' . $transport;
+ return new $transportClass($params);
+ }
+}
View
165 library/phpRack/Adapters/Notifier/Mail/Abstract.php
@@ -0,0 +1,165 @@
+<?php
+/**
+ * phpRack: Integration Testing Framework
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt. It is also available
+ * through the world-wide-web at this URL: http://www.phprack.com/LICENSE.txt
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@phprack.com so we can send you a copy immediately.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @copyright Copyright (c) phpRack.com
+ * @version $Id: Abstract.php 545 2010-05-04 09:40:46Z yegor256@yahoo.com $
+ * @category phpRack
+ */
+
+/**
+ * Abstract class for the phpRack_Adapters_Notifier_Mail_*
+ *
+ * @package Adapters
+ */
+abstract class phpRack_Adapters_Notifier_Mail_Abstract
+{
+ /**
+ * Our array with list of options
+ *
+ * @var array
+ * @see __construct()
+ */
+ protected $_options = array();
+
+ /**
+ * Default text of the body
+ *
+ * @var string
+ * @see setBody()
+ */
+ protected $_body;
+
+ /**
+ * List of destination e-mail addresses
+ *
+ * @var string
+ * @see setTo()
+ */
+ protected $_to = array();
+
+ /**
+ * Sender e-mail address
+ *
+ * @var string
+ */
+ protected $_from = 'no-reply@phprack.com';
+
+ /**
+ * Default message subject
+ *
+ * @var string
+ * @see setSubject()
+ */
+ protected $_subject = 'phpRack';
+
+ /**
+ * Constructor
+ *
+ * @param array List of parameters
+ * @return void
+ */
+ public function __construct(array $options = array())
+ {
+ $this->_options = $options;
+ }
+
+ /**
+ * Assigns body of a mail
+ *
+ * @param string Text to be assigned
+ * @return phpRack_Adapters_Mail
+ */
+ public function setBody($plain)
+ {
+ $this->_body = trim($plain);
+ return $this;
+ }
+
+ /**
+ * Assigns subject of a mail
+ *
+ * @param string
+ * @return phpRack_Adapters_Mail
+ */
+ public function setSubject($text)
+ {
+ $this->_subject = $text;
+ return $this;
+ }
+
+ /**
+ * Sets destination mail or mails.
+ *
+ * @param string|array $mails
+ * @return phpRack_Adapters_Mail
+ */
+ public function setTo($mails)
+ {
+ $this->_to = (!is_array($mails)) ? array($mails) : $mails;
+ return $this;
+ }