Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

added phprack + initial test set

  • Loading branch information...
commit 475665aa64ea9e1130814133c7165d6542a0506b 1 parent 5db8d1b
Michael authored

Showing 72 changed files with 9,041 additions and 0 deletions. Show diff stats Hide diff stats

  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
7 application/Bootstrap.php
@@ -2,6 +2,11 @@
2 2
3 3 class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
4 4 {
  5 + public function _initConfig()
  6 + {
  7 + Zend_Registry::set('config', $this->getOptions());
  8 + }
  9 +
5 10 public function _initAutoloaderNamespaces()
6 11 {
7 12 require_once APPLICATION_PATH .
@@ -60,6 +65,8 @@ public function _initLocale()
60 65 $locale = new Zend_Locale($config['resources']['locale']['default']);
61 66 }
62 67
  68 + // Zend_Locale::setDefault('de'); // check hasLanguage, sonst switch auf default siehe Zend TIcket
  69 +
63 70 Zend_Registry::set('Zend_Locale', $locale);
64 71
65 72 $translator = new Zend_Translate(
108 library/phpRack/Adapters/Auth/Abstract.php
... ... @@ -0,0 +1,108 @@
  1 +<?php
  2 +/**
  3 + * phpRack: Integration Testing Framework
  4 + *
  5 + * This source file is subject to the new BSD license that is bundled
  6 + * with this package in the file LICENSE.txt. It is also available
  7 + * through the world-wide-web at this URL: http://www.phprack.com/LICENSE.txt
  8 + * If you did not receive a copy of the license and are unable to
  9 + * obtain it through the world-wide-web, please send an email
  10 + * to license@phprack.com so we can send you a copy immediately.
  11 + *
  12 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  13 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  14 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  15 + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  16 + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  17 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  18 + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  19 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  20 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  21 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  22 + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  23 + * POSSIBILITY OF SUCH DAMAGE.
  24 + *
  25 + * @copyright Copyright (c) phpRack.com
  26 + * @version $Id: Abstract.php 619 2010-07-19 10:22:05Z yegor256@yahoo.com $
  27 + * @category phpRack
  28 + */
  29 +
  30 +/**
  31 + * Authentication abstract adapter
  32 + *
  33 + * @package Adapters
  34 + * @subpackage Auth
  35 + */
  36 +abstract class phpRack_Adapters_Auth_Abstract
  37 +{
  38 + /**
  39 + * Authentication request
  40 + *
  41 + * @var array
  42 + */
  43 + protected $_request = array(
  44 + 'login' => '',
  45 + 'hash' => ''
  46 + );
  47 +
  48 + /**
  49 + * Authentication options
  50 + *
  51 + * @var array
  52 + */
  53 + protected $_options = array();
  54 +
  55 + /**
  56 + * Set authentication options
  57 + *
  58 + * @param array
  59 + * @see phpRack_Runner_Auth::authenticate()
  60 + * @return @this
  61 + */
  62 + public function setOptions($options)
  63 + {
  64 + $this->_options = $options;
  65 + return $this;
  66 + }
  67 +
  68 + /**
  69 + * Set request login, hash
  70 + *
  71 + * @param array
  72 + * @see phpRack_Runner_Auth::authenticate()
  73 + * @return @this
  74 + */
  75 + public function setRequest($request)
  76 + {
  77 + foreach ($request as $key => $value) {
  78 + $this->_request[$key] = $value;
  79 + }
  80 + return $this;
  81 + }
  82 +
  83 + /**
  84 + * Authenticate and return an auth result
  85 + *
  86 + * @return phpRack_Runner_Auth_Result
  87 + * @see phpRack_Runner_Auth::authenticate()
  88 + */
  89 + abstract public function authenticate();
  90 +
  91 + /**
  92 + * Return an AuthResult
  93 + *
  94 + * @param boolean Success/failure of the validation
  95 + * @param string Optional error message
  96 + * @return phpRack_Runner_Auth_Result
  97 + * @see authenticate()
  98 + */
  99 + protected function _validated($result, $message = null)
  100 + {
  101 + /**
  102 + * @see phpRack_Runner_Auth_Result
  103 + */
  104 + require_once PHPRACK_PATH . '/Runner/Auth/Result.php';
  105 + return new phpRack_Runner_Auth_Result($result, $message);
  106 + }
  107 +
  108 +}
60 library/phpRack/Adapters/Auth/Array.php
... ... @@ -0,0 +1,60 @@
  1 +<?php
  2 +/**
  3 + * phpRack: Integration Testing Framework
  4 + *
  5 + * This source file is subject to the new BSD license that is bundled
  6 + * with this package in the file LICENSE.txt. It is also available
  7 + * through the world-wide-web at this URL: http://www.phprack.com/LICENSE.txt
  8 + * If you did not receive a copy of the license and are unable to
  9 + * obtain it through the world-wide-web, please send an email
  10 + * to license@phprack.com so we can send you a copy immediately.
  11 + *
  12 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  13 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  14 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  15 + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  16 + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  17 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  18 + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  19 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  20 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  21 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  22 + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  23 + * POSSIBILITY OF SUCH DAMAGE.
  24 + *
  25 + * @copyright Copyright (c) phpRack.com
  26 + * @version $Id: Array.php 616 2010-07-19 09:47:43Z yegor256@yahoo.com $
  27 + * @category phpRack
  28 + */
  29 +
  30 +/**
  31 + * @see phpRack_Adapters_Auth_Abstract
  32 + */
  33 +require_once PHPRACK_PATH . '/Adapters/Auth/Abstract.php';
  34 +
  35 +/**
  36 + * Authentication array adapter
  37 + *
  38 + * @package Adapters
  39 + * @subpackage Auth
  40 + */
  41 +class phpRack_Adapters_Auth_Array extends phpRack_Adapters_Auth_Abstract
  42 +{
  43 + /**
  44 + * Authenticate and return an auth result
  45 + *
  46 + * @return phpRack_Runner_Auth_Result
  47 + * @see phpRack_Adapters_Auth_Abstract::authenticate()
  48 + */
  49 + public function authenticate()
  50 + {
  51 + foreach ($this->_options['htpasswd'] as $login => $password) {
  52 + if (($login == $this->_request['login'])
  53 + && (md5($password) == $this->_request['hash'])
  54 + ) {
  55 + return $this->_validated(true);
  56 + }
  57 + }
  58 + return $this->_validated(false, 'Invalid login credentials provided');
  59 + }
  60 +}
69 library/phpRack/Adapters/Auth/File.php
... ... @@ -0,0 +1,69 @@
  1 +<?php
  2 +/**
  3 + * phpRack: Integration Testing Framework
  4 + *
  5 + * This source file is subject to the new BSD license that is bundled
  6 + * with this package in the file LICENSE.txt. It is also available
  7 + * through the world-wide-web at this URL: http://www.phprack.com/LICENSE.txt
  8 + * If you did not receive a copy of the license and are unable to
  9 + * obtain it through the world-wide-web, please send an email
  10 + * to license@phprack.com so we can send you a copy immediately.
  11 + *
  12 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  13 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  14 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  15 + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  16 + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  17 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  18 + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  19 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  20 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  21 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  22 + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  23 + * POSSIBILITY OF SUCH DAMAGE.
  24 + *
  25 + * @copyright Copyright (c) phpRack.com
  26 + * @version $Id: File.php 616 2010-07-19 09:47:43Z yegor256@yahoo.com $
  27 + * @category phpRack
  28 + */
  29 +
  30 +/**
  31 + * @see phpRack_Adapters_Auth_Abstract
  32 + */
  33 +require_once PHPRACK_PATH . '/Adapters/Auth/Abstract.php';
  34 +
  35 +/**
  36 + * Authentication file adapter
  37 + *
  38 + * @package Adapters
  39 + * @subpackage Auth
  40 + */
  41 +class phpRack_Adapters_Auth_File extends phpRack_Adapters_Auth_Abstract
  42 +{
  43 + /**
  44 + * Authenticate and return an auth result
  45 + *
  46 + * @return phpRack_Runner_Auth_Result
  47 + * @see phpRack_Adapters_Auth_Abstract::authenticate()
  48 + */
  49 + public function authenticate()
  50 + {
  51 + /**
  52 + * @see phpRack_Adapters_File
  53 + */
  54 + require_once PHPRACK_PATH . '/Adapters/File.php';
  55 + $file = phpRack_Adapters_File::factory($this->_options['htpasswd'])->getFileName();
  56 +
  57 + $fileContent = file($file);
  58 + foreach ($fileContent as $line) {
  59 + list($login, $password) = explode(':', $line, 2);
  60 + /* Just to make sure we don't analyze some whitespace */
  61 + $login = trim($login);
  62 + $password = trim($password);
  63 + if (($login == $this->_request['login']) && ($password == $this->_request['hash'])) {
  64 + return $this->_validated(true);
  65 + }
  66 + }
  67 + return $this->_validated(false, 'Invalid login credentials provided');
  68 + }
  69 +}
60 library/phpRack/Adapters/Auth/Plain.php
... ... @@ -0,0 +1,60 @@
  1 +<?php
  2 +/**
  3 + * phpRack: Integration Testing Framework
  4 + *
  5 + * This source file is subject to the new BSD license that is bundled
  6 + * with this package in the file LICENSE.txt. It is also available
  7 + * through the world-wide-web at this URL: http://www.phprack.com/LICENSE.txt
  8 + * If you did not receive a copy of the license and are unable to
  9 + * obtain it through the world-wide-web, please send an email
  10 + * to license@phprack.com so we can send you a copy immediately.
  11 + *
  12 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  13 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  14 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  15 + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  16 + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  17 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  18 + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  19 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  20 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  21 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  22 + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  23 + * POSSIBILITY OF SUCH DAMAGE.
  24 + *
  25 + * @copyright Copyright (c) phpRack.com
  26 + * @version $Id: Plain.php 616 2010-07-19 09:47:43Z yegor256@yahoo.com $
  27 + * @category phpRack
  28 + */
  29 +
  30 +/**
  31 + * @see phpRack_Adapters_Auth_Abstract
  32 + */
  33 +require_once PHPRACK_PATH . '/Adapters/Auth/Abstract.php';
  34 +
  35 +/**
  36 + * Authentication plain adapter
  37 + *
  38 + * @package Adapters
  39 + * @subpackage Auth
  40 + */
  41 +class phpRack_Adapters_Auth_Plain extends phpRack_Adapters_Auth_Abstract
  42 +{
  43 + /**
  44 + * Authenticate and return an auth result
  45 + *
  46 + * @return phpRack_Runner_Auth_Result
  47 + * @see phpRack_Adapters_Auth_Abstract::authenticate()
  48 + */
  49 + public function authenticate()
  50 + {
  51 + $auth = $this->_options['auth'];
  52 + if ($auth['username'] != $this->_request['login']) {
  53 + return $this->_validated(false, 'Invalid login');
  54 + }
  55 + if (md5($auth['password']) != $this->_request['hash']) {
  56 + return $this->_validated(false, 'Invalid password');
  57 + }
  58 + return $this->_validated(true);
  59 + }
  60 +}
107 library/phpRack/Adapters/Config.php
... ... @@ -0,0 +1,107 @@
  1 +<?php
  2 +/**
  3 + * phpRack: Integration Testing Framework
  4 + *
  5 + * This source file is subject to the new BSD license that is bundled
  6 + * with this package in the file LICENSE.txt. It is also available
  7 + * through the world-wide-web at this URL: http://www.phprack.com/LICENSE.txt
  8 + * If you did not receive a copy of the license and are unable to
  9 + * obtain it through the world-wide-web, please send an email
  10 + * to license@phprack.com so we can send you a copy immediately.
  11 + *
  12 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  13 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  14 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  15 + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  16 + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  17 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  18 + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  19 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  20 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  21 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  22 + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  23 + * POSSIBILITY OF SUCH DAMAGE.
  24 + *
  25 + * @copyright Copyright (c) phpRack.com
  26 + * @version $Id: Config.php 545 2010-05-04 09:40:46Z yegor256@yahoo.com $
  27 + * @category phpRack
  28 + */
  29 +
  30 +
  31 +/**
  32 + * Config adapter used for store tests configuration and provide object
  33 + * oriented access methods
  34 + *
  35 + * You can use it like this:
  36 + *
  37 + * <code>
  38 + * $config = new phpRack_Adapters_Config(
  39 + * array(
  40 + * 'alpha' => array(
  41 + * 'beta' => 123,
  42 + * )
  43 + * )
  44 + * );
  45 + * assert($config->alpha->beta == 123);
  46 + * </code>
  47 + *
  48 + * @package Adapters
  49 + */
  50 +class phpRack_Adapters_Config
  51 +{
  52 + /**
  53 + * Contains array of configuration data
  54 + *
  55 + * @var array
  56 + * @see __construct()
  57 + */
  58 + protected $_data;
  59 +
  60 + /**
  61 + * Create object oriented config container
  62 + *
  63 + * @param array Config data as array
  64 + * @return void
  65 + * @see ConfigTest::testConfigIni() and other integration tests
  66 + */
  67 + public function __construct(array $data)
  68 + {
  69 + $this->_data = array();
  70 + foreach ($data as $key => $value) {
  71 + if (is_array($value)) {
  72 + $this->_data[$key] = new self($value);
  73 + } else {
  74 + $this->_data[$key] = $value;
  75 + }
  76 + }
  77 + }
  78 +
  79 + /**
  80 + * Magic method which provide access to configuration options
  81 + *
  82 + * @param string Name of config option
  83 + * @return mixed
  84 + * @throws Exception if config option not exists
  85 + * @see ConfigTest::testConfigIni() and other integration tests
  86 + */
  87 + public function __get($name)
  88 + {
  89 + if (!array_key_exists($name, $this->_data)) {
  90 + throw new Exception("Config option '{$name}' doesn't exist");
  91 + }
  92 + return $this->_data[$name];
  93 + }
  94 +
  95 + /**
  96 + * Magic method which provide possibility to check whether some
  97 + * configuration option exists
  98 + *
  99 + * @param string Name of config option
  100 + * @return boolean
  101 + * @see ConfigTest::testConfigIni() and other integration tests
  102 + */
  103 + public function __isset($name)
  104 + {
  105 + return isset($this->_data[$name]);
  106 + }
  107 +}
137 library/phpRack/Adapters/Config/Ini.php
... ... @@ -0,0 +1,137 @@
  1 +<?php
  2 +/**
  3 + * phpRack: Integration Testing Framework
  4 + *
  5 + * This source file is subject to the new BSD license that is bundled
  6 + * with this package in the file LICENSE.txt. It is also available
  7 + * through the world-wide-web at this URL: http://www.phprack.com/LICENSE.txt
  8 + * If you did not receive a copy of the license and are unable to
  9 + * obtain it through the world-wide-web, please send an email
  10 + * to license@phprack.com so we can send you a copy immediately.
  11 + *
  12 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  13 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  14 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  15 + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  16 + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  17 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  18 + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  19 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  20 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  21 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  22 + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  23 + * POSSIBILITY OF SUCH DAMAGE.
  24 + *
  25 + * @copyright Copyright (c) phpRack.com
  26 + * @version $Id: Ini.php 545 2010-05-04 09:40:46Z yegor256@yahoo.com $
  27 + * @category phpRack
  28 + */
  29 +
  30 +/**
  31 + * @see phpRack_Adapters_Config
  32 + */
  33 +require_once PHPRACK_PATH . '/Adapters/Config.php';
  34 +
  35 +/**
  36 + * Config adapter used for store test configuration loaded from INI file
  37 + *
  38 + * You can use it like this:
  39 + *
  40 + * <code>
  41 + * // app.ini:
  42 + * // [production]
  43 + * // params.db.username = 'test'
  44 + * $ini = new phpRack_Adapters_Config_Ini('app.ini', 'production');
  45 + * assert($ini->params->db->username == 'test');
  46 + * </code>
  47 + *
  48 + * @package Adapters
  49 + */
  50 +class phpRack_Adapters_Config_Ini extends phpRack_Adapters_Config
  51 +{
  52 + /**
  53 + * Create config object and load selected section from INI file,
  54 + * or all sections if $sectionName == null
  55 + *
  56 + * @param string Filename of INI file
  57 + * @param string|null Section name to load, or null to load all
  58 + * @return void
  59 + * @throws Exception if INI file not exists
  60 + * @throws Exception if section not exists in INI file
  61 + * @see ConfigTest::testConfigIni() and other integration tests
  62 + */
  63 + public function __construct($filename, $sectionName = null)
  64 + {
  65 + $sections = $this->_loadSectionsFromIniFile($filename);
  66 + // one section to return
  67 + if ($sectionName) {
  68 + if (!array_key_exists($sectionName, $sections)) {
  69 + throw new Exception("Section '{$sectionName}' doesn't exist in INI file '{$filename}'");
  70 + }
  71 + $dataArray = $this->_sectionToArray($sections[$sectionName]);
  72 + } else {
  73 + // all sections to return
  74 + foreach ($sections as $key => $section) {
  75 + $dataArray[$key] = $this->_sectionToArray($section);
  76 + }
  77 + }
  78 + parent::__construct($dataArray);
  79 + }
  80 +
  81 + /**
  82 + * Convert section with "key.subkey1.subkey2" values as keys
  83 + * to multidimensional associative array
  84 + *
  85 + * @param array section from ini file
  86 + * @return array
  87 + * @see __construct()
  88 + */
  89 + protected function _sectionToArray($section)
  90 + {
  91 + $dataArray = array();
  92 + foreach ($section as $key => $value) {
  93 + $currentElement =& $dataArray;
  94 + foreach (explode('.', $key) as $keyFragment) {
  95 + $currentElement =& $currentElement[$keyFragment];
  96 + }
  97 + $currentElement = $value;
  98 + }
  99 + return $dataArray;
  100 + }
  101 +
  102 + /**
  103 + * Load config sections from INI file, taking into account section inheritance
  104 + *
  105 + * @param string INI file to load and parse
  106 + * @return array
  107 + * @throws Exception if config INI file not exists
  108 + * @see __construct()
  109 + */
  110 + protected function _loadSectionsFromIniFile($filename)
  111 + {
  112 + if (!file_exists($filename)) {
  113 + throw new Exception("INI file '{$filename}' doesn't exist");
  114 + }
  115 + $sections = array();
  116 + $iniFileSections = parse_ini_file($filename, true);
  117 +
  118 + foreach ($iniFileSections as $sectionName => $data) {
  119 + // divide section name to check it have some parent ([section : parent])
  120 + $nameParts = explode(':', $sectionName);
  121 + $thisSectionName = trim($nameParts[0]);
  122 +
  123 + // if section have parent
  124 + if (isset($nameParts[1])) {
  125 + $parentSectionName = trim($nameParts[1]);
  126 + // merge current section values, with parent values
  127 + $data = array_merge(
  128 + $sections[$parentSectionName],
  129 + $data
  130 + );
  131 + }
  132 + $sections[$thisSectionName] = $data;
  133 + }
  134 +
  135 + return $sections;
  136 + }
  137 +}
105 library/phpRack/Adapters/ConnectionMonitor.php
... ... @@ -0,0 +1,105 @@
  1 +<?php
  2 +/**
  3 + * phpRack: Integration Testing Framework
  4 + *
  5 + * This source file is subject to the new BSD license that is bundled
  6 + * with this package in the file LICENSE.txt. It is also available
  7 + * through the world-wide-web at this URL: http://www.phprack.com/LICENSE.txt
  8 + * If you did not receive a copy of the license and are unable to
  9 + * obtain it through the world-wide-web, please send an email
  10 + * to license@phprack.com so we can send you a copy immediately.
  11 + *
  12 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  13 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  14 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  15 + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  16 + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  17 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  18 + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  19 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  20 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  21 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  22 + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  23 + * POSSIBILITY OF SUCH DAMAGE.
  24 + *
  25 + * @copyright Copyright (c) phpRack.com
  26 + * @version $Id: ConnectionMonitor.php 545 2010-05-04 09:40:46Z yegor256@yahoo.com $
  27 + * @category phpRack
  28 + */
  29 +
  30 +/**
  31 + * Connection monitor used to check whether connection between client
  32 + * and our script is still opened
  33 + *
  34 + * @package Adapters
  35 + * @author netcoderpl@gmail.com
  36 + */
  37 +class phpRack_Adapters_ConnectionMonitor
  38 +{
  39 + /**
  40 + * Connection status last checked time
  41 + *
  42 + * @var int
  43 + * @see ping()
  44 + */
  45 + private $_lastCheckTime = null;
  46 +
  47 + /**
  48 + * Connection status checking interval
  49 + *
  50 + * @var int
  51 + * @see ping()
  52 + */
  53 + private $_checkInterval = 1; // 1 second
  54 +
  55 + /**
  56 + * phpRack_Adapters_ConnectionMonitor instance
  57 + *
  58 + * @var phpRack_Adapters_ConnectionMonitor
  59 + * @see getInstance()
  60 + */
  61 + private static $_instance;
  62 +
  63 + /**
  64 + * Get phpRack_Adapters_ConnectionMonitor instance
  65 + *
  66 + * @return phpRack_Adapters_ConnectionMonitor
  67 + */
  68 + public static function getInstance()
  69 + {
  70 + if (self::$_instance === null) {
  71 + self::$_instance = new self();
  72 + }
  73 +
  74 + return self::$_instance;
  75 + }
  76 +
  77 + /**
  78 + * Check client connection is still opened. We can check it by sending
  79 + * space char " " every $this->_checkInterval second.
  80 + *
  81 + * After that PHP can detect connection status. If it was closed objects
  82 + * destructors will be automatically executed and script stop work.
  83 + *
  84 + * @return void
  85 + */
  86 + public function ping()
  87 + {
  88 + if ($this->_lastCheckTime === null
  89 + || $this->_lastCheckTime + $this->_checkInterval < time()
  90 + ) {
  91 + echo ' ';
  92 +
  93 + /**
  94 + * Bypass output buffering, without it PHP may not recognize that
  95 + * connection is closed
  96 + */
  97 + if (ob_get_level()) {
  98 + ob_flush();
  99 + }
  100 +
  101 + flush();
  102 + $this->_lastCheckTime = time();
  103 + }
  104 + }
  105 +}
64 library/phpRack/Adapters/Cpu.php
... ... @@ -0,0 +1,64 @@
  1 +<?php
  2 +/**
  3 + * phpRack: Integration Testing Framework
  4 + *
  5 + * This source file is subject to the new BSD license that is bundled
  6 + * with this package in the file LICENSE.txt. It is also available
  7 + * through the world-wide-web at this URL: http://www.phprack.com/LICENSE.txt
  8 + * If you did not receive a copy of the license and are unable to
  9 + * obtain it through the world-wide-web, please send an email
  10 + * to license@phprack.com so we can send you a copy immediately.
  11 + *
  12 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  13 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  14 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  15 + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  16 + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  17 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  18 + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  19 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  20 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  21 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  22 + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  23 + * POSSIBILITY OF SUCH DAMAGE.
  24 + *
  25 + * @copyright Copyright (c) phpRack.com
  26 + * @version $Id: Cpu.php 545 2010-05-04 09:40:46Z yegor256@yahoo.com $
  27 + * @category phpRack
  28 + */
  29 +
  30 +
  31 +/**
  32 + * CPU adapter used to get details about available processor
  33 + *
  34 + * @package Adapters
  35 + */
  36 +class phpRack_Adapters_Cpu
  37 +{
  38 + /**
  39 + * CPU adapter factory return adapter depending on operating system
  40 + *
  41 + * @return phpRack_Adapters_Cpu_Abstract
  42 + * @throws Exception If OS is not supported
  43 + * @see For MacOS I think we should use system_profiler shell command.
  44 + * After that we can parse it output in similar way like we do it for
  45 + * Windows or Linux
  46 + * @todo #17 How about Mac OS? There is no /proc directory in Mac OS
  47 + */
  48 + public static function factory()
  49 + {
  50 + /**
  51 + * @see phpRack_Adapters_Os
  52 + */
  53 + require_once PHPRACK_PATH . '/Adapters/Os.php';
  54 + $os = phpRack_Adapters_Os::get();
  55 + $classFile = PHPRACK_PATH . '/Adapters/Cpu/' . ucfirst($os) . '.php';
  56 +
  57 + if (!file_exists($classFile)) {
  58 + throw new Exception("OS '{$os}' is not supported yet");
  59 + }
  60 + eval ('require_once $classFile;'); // for ZCA validation
  61 + $className = 'phpRack_Adapters_Cpu_' . ucfirst($os);
  62 + return new $className();
  63 + }
  64 +}
56 library/phpRack/Adapters/Cpu/Abstract.php
... ... @@ -0,0 +1,56 @@
  1 +<?php
  2 +/**
  3 + * phpRack: Integration Testing Framework
  4 + *
  5 + * This source file is subject to the new BSD license that is bundled
  6 + * with this package in the file LICENSE.txt. It is also available
  7 + * through the world-wide-web at this URL: http://www.phprack.com/LICENSE.txt
  8 + * If you did not receive a copy of the license and are unable to
  9 + * obtain it through the world-wide-web, please send an email
  10 + * to license@phprack.com so we can send you a copy immediately.
  11 + *
  12 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  13 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  14 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  15 + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  16 + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  17 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  18 + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  19 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  20 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  21 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  22 + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  23 + * POSSIBILITY OF SUCH DAMAGE.
  24 + *
  25 + * @copyright Copyright (c) phpRack.com
  26 + * @version $Id: Abstract.php 545 2010-05-04 09:40:46Z yegor256@yahoo.com $
  27 + * @category phpRack
  28 + */
  29 +
  30 +/**
  31 + * Abstract CPU adapter
  32 + *
  33 + * @package Adapters
  34 + * @subpackage Cpu
  35 + * @see phpRack_Adapters_Cpu::factory()
  36 + */
  37 +abstract class phpRack_Adapters_Cpu_Abstract
  38 +{
  39 + /**
  40 + * Get CPU BogoMips
  41 + *
  42 + * @return float
  43 + * @throws Exception If unable to get BogoMips
  44 + * @see phpRack_Package_Cpu_Performance::atLeast()
  45 + */
  46 + abstract public function getBogoMips();
  47 +
  48 + /**
  49 + * Get CPU frequency in MHz
  50 + *
  51 + * @return float
  52 + * @throws Exception If can't get cpu frequency
  53 + * @see getBogoMips()
  54 + */
  55 + abstract public function getCpuFrequency();
  56 +}
86 library/phpRack/Adapters/Cpu/Darwin.php
... ... @@ -0,0 +1,86 @@
  1 +<?php
  2 +/**
  3 + * phpRack: Integration Testing Framework
  4 + *
  5 + * This source file is subject to the new BSD license that is bundled
  6 + * with this package in the file LICENSE.txt. It is also available
  7 + * through the world-wide-web at this URL: http://www.phprack.com/LICENSE.txt
  8 + * If you did not receive a copy of the license and are unable to
  9 + * obtain it through the world-wide-web, please send an email
  10 + * to license@phprack.com so we can send you a copy immediately.
  11 + *
  12 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  13 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  14 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  15 + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  16 + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  17 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  18 + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  19 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  20 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  21 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  22 + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  23 + * POSSIBILITY OF SUCH DAMAGE.
  24 + *
  25 + * @copyright Copyright (c) phpRack.com
  26 + * @version $Id: Linux.php 447 2010-04-24 03:59:09Z yegor256@yahoo.com $
  27 + * @category phpRack
  28 + */
  29 +
  30 +/**
  31 + * @see phpRack_Adapters_Cpu_Abstract
  32 + */
  33 +require_once PHPRACK_PATH . '/Adapters/Cpu/Abstract.php';
  34 +
  35 +/**
  36 + * Darwin CPU Adapter (Mac OS)
  37 + *
  38 + * @package Adapters
  39 + * @subpackage Cpu
  40 + * @todo #17 Should be implemented
  41 + */
  42 +class phpRack_Adapters_Cpu_Darwin extends phpRack_Adapters_Cpu_Abstract
  43 +{
  44 + /**
  45 + * Get CPU BogoMips
  46 + *
  47 + * @return float
  48 + * @see phpRack_Package_Cpu_Performance::atLeast()
  49 + * @see phpRack_Adapters_Cpu_Abstract::getBogoMips()
  50 + */
  51 + public function getBogoMips()
  52 + {
  53 + return $this->getCpuFrequency() * 2;
  54 + }
  55 +
  56 + /**
  57 + * Get CPU frequency in MHz
  58 + *
  59 + * @return float
  60 + * @throws Exception If can't get cpu frequency
  61 + * @see getBogoMips()
  62 + * @see phpRack_Adapters_Cpu_Abstract::getCpuFrequency()
  63 + */
  64 + public function getCpuFrequency()
  65 + {
  66 + /**
  67 + * @see phpRack_Adapters_Shell_Command
  68 + */
  69 + require_once PHPRACK_PATH . '/Adapters/Shell/Command.php';
  70 + $data = phpRack_Adapters_Shell_Command::factory(
  71 + 'system_profiler SPHardwareDataType -xml 2>&1'
  72 + )->run();
  73 + $xml = simplexml_load_string($data);
  74 + if (!($xml instanceof SimpleXMLElement)) {
  75 + throw new Exception("Invalid result from system_profiler: '{$data}'");
  76 + }
  77 + $nodes = $xml->xpath('//string[preceding-sibling::key="current_processor_speed"]');
  78 + $node = strval($nodes[0]);
  79 +
  80 + if (strpos($node, 'GHz') === false) {
  81 + throw new Exception("Strange frequency from system_profiler: '{$node}'");
  82 + }
  83 +
  84 + return floatval($node) * 1000;
  85 + }
  86 +}
110 library/phpRack/Adapters/Cpu/Linux.php
... ... @@ -0,0 +1,110 @@
  1 +<?php
  2 +/**
  3 + * phpRack: Integration Testing Framework
  4 + *
  5 + * This source file is subject to the new BSD license that is bundled
  6 + * with this package in the file LICENSE.txt. It is also available
  7 + * through the world-wide-web at this URL: http://www.phprack.com/LICENSE.txt
  8 + * If you did not receive a copy of the license and are unable to
  9 + * obtain it through the world-wide-web, please send an email
  10 + * to license@phprack.com so we can send you a copy immediately.
  11 + *
  12 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  13 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  14 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  15 + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  16 + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  17 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  18 + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  19 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  20 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  21 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  22 + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  23 + * POSSIBILITY OF SUCH DAMAGE.
  24 + *
  25 + * @copyright Copyright (c) phpRack.com
  26 + * @version $Id: Linux.php 545 2010-05-04 09:40:46Z yegor256@yahoo.com $
  27 + * @category phpRack
  28 + */
  29 +
  30 +/**
  31 + * @see phpRack_Adapters_Cpu_Abstract
  32 + */
  33 +require_once PHPRACK_PATH . '/Adapters/Cpu/Abstract.php';
  34 +
  35 +/**
  36 + * Linux CPU Adapter
  37 + *
  38 + * @package Adapters
  39 + * @subpackage Cpu
  40 + */
  41 +class phpRack_Adapters_Cpu_Linux extends phpRack_Adapters_Cpu_Abstract
  42 +{
  43 + /**
  44 + * Get CPU BogoMips
  45 + *
  46 + * @return float
  47 + * @throws Exception If unable to get BogoMips
  48 + * @see phpRack_Package_Cpu_Performance::atLeast()
  49 + * @see phpRack_Adapters_Cpu_Abstract::getBogoMips()
  50 + */
  51 + public function getBogoMips()
  52 + {
  53 + $matches = array();
  54 + // on Linux parse ouput of "cat /proc/cpuinfo" command
  55 + if (
  56 + !preg_match(
  57 + '/^bogomips\s*:\s*(.*)/m',
  58 + $this->_getCpuInfoData(), // Exception is possible here
  59 + $matches
  60 + )
  61 + ) {
  62 + throw new Exception("Unable to find bogomips value in cpuinfo");
  63 + }
  64 + return floatval($matches[1]);
  65 + }
  66 +
  67 + /**
  68 + * Get CPU frequency in MHz
  69 + *
  70 + * @return float
  71 + * @throws Exception If can't get cpu frequency
  72 + * @see getBogoMips()
  73 + * @see phpRack_Adapters_Cpu_Abstract::getCpuFrequency()
  74 + */
  75 + public function getCpuFrequency()
  76 + {
  77 + // on Linux parse ouput of "cat /proc/cpuinfo" command
  78 + $matches = array();
  79 + if (
  80 + !preg_match(
  81 + '/^cpu MHz\s*:\s*(.*)/m',
  82 + $this->_getCpuInfoData(), // Exception is possible here
  83 + $matches
  84 + )
  85 + ) {
  86 + throw new Exception('Unable to find CPU MHz value in cpuinfo');
  87 + }
  88 + return floatval($matches[1]);
  89 + }
  90 +
  91 + /**
  92 + * Get result of "cat /proc/cpuinfo" shell command execution
  93 + *
  94 + * @return string
  95 + * @throws Exception If unable to execute shell command
  96 + * @see getBogoMips()
  97 + * @see getCpuFrequency()
  98 + */
  99 + private function _getCpuInfoData()
  100 + {
  101 + $command = 'cat /proc/cpuinfo';
  102 + /**
  103 + * @see phpRack_Adapters_Shell_Command
  104 + */
  105 + require_once PHPRACK_PATH . '/Adapters/Shell/Command.php';
  106 + // Exception is possible here
  107 + $result = phpRack_Adapters_Shell_Command::factory($command)->run();
  108 + return $result;
  109 + }
  110 +}
99 library/phpRack/Adapters/Cpu/Windows.php
... ... @@ -0,0 +1,99 @@
  1 +<?php
  2 +/**
  3 + * phpRack: Integration Testing Framework
  4 + *
  5 + * This source file is subject to the new BSD license that is bundled
  6 + * with this package in the file LICENSE.txt. It is also available
  7 + * through the world-wide-web at this URL: http://www.phprack.com/LICENSE.txt
  8 + * If you did not receive a copy of the license and are unable to
  9 + * obtain it through the world-wide-web, please send an email
  10 + * to license@phprack.com so we can send you a copy immediately.
  11 + *
  12 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  13 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  14 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  15 + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  16 + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  17 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  18 + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  19 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  20 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  21 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  22 + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  23 + * POSSIBILITY OF SUCH DAMAGE.
  24 + *
  25 + * @copyright Copyright (c) phpRack.com
  26 + * @version $Id: Windows.php 545 2010-05-04 09:40:46Z yegor256@yahoo.com $
  27 + * @category phpRack
  28 + */
  29 +
  30 +/**
  31 + * @see phpRack_Adapters_Cpu_Abstract
  32 + */
  33 +require_once PHPRACK_PATH . '/Adapters/Cpu/Abstract.php';
  34 +
  35 +/**
  36 + * Windows CPU Adapter
  37 + *
  38 + * @package Adapters
  39 + * @subpackage Cpu
  40 + */
  41 +class phpRack_Adapters_Cpu_Windows extends phpRack_Adapters_Cpu_Abstract
  42 +{
  43 + /**
  44 + * Get CPU BogoMips
  45 + *
  46 + * @return float
  47 + * @throws Exception If unable to get BogoMips
  48 + * @see phpRack_Package_Cpu_Performance::atLeast()
  49 + * @see phpRack_Adapters_Cpu_Abstract::getBogoMips()
  50 + */
  51 + public function getBogoMips()
  52 + {
  53 + /**
  54 + * On Windows return approximated result which can be calculated using
  55 + * this formula: CPU clock * 2
  56 + */
  57 + return $this->getCpuFrequency() * 2;
  58 + }
  59 +
  60 + /**
  61 + * Get CPU frequency in MHz
  62 + *
  63 + * @return float
  64 + * @throws Exception If can't get cpu frequency
  65 + * @see getBogoMips()
  66 + * @see phpRack_Adapters_Cpu_Abstract::getCpuFrequency()
  67 + */
  68 + public function getCpuFrequency()
  69 + {
  70 + $wmi = new COM('Winmgmts://');
  71 + $query = 'SELECT maxClockSpeed FROM CIM_Processor';
  72 +
  73 + // get CPUS-s data
  74 + $cpus = $wmi->execquery($query);
  75 + $maxClockSpeed = 0;