text:
/**
 * 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: index.js 584 2010-05-12 17:43:27Z yegor256@yahoo.com $
 * @author netcoderpl@gmail.com
 * @category phpRack
 */

$(
    function()
    {
        // List with DOM ids and test names
        var calls = phpParams.calls;

        String.prototype.stripTags = function ()
        {
            return this.replace(/<[^>]*>/g, '');
        };

        String.prototype.htmlspecialchars = function ()
        {
            return this.replace(/[<]/g, '<').replace(/[>]/g, '>');
        };

        var that = {
            focus: true,
            init: function()
            {
                $(window).blur(that.onBlur);
                $(window).focus(that.onFocus);
            },
            onBlur: function()
            {
                that.focus = false;
            },
            onFocus: function()
            {
                that.focus = true;
            },
            hasFocus: function()
            {
                return that.focus;
            }
        };
        phpRack_Window = that;
        phpRack_Window.init();

        // Our processing queue to control tests concurrency
        function phpRack_TaskQueue()
        {
            var that = {
                queue: [], // Used for storing waiting tasks
                threadsCount: 1, // How many concurent threads we can have
                activeThreadsCount: 0, // How many threads is currently running
                // Callback function executed after each task is finished
                onTaskFinish: function()
                {
                    that.activeThreadsCount--;
                    that._runNextTask();
                },
                // Add task to our processing queue
                add: function(task)
                {
                    that.queue.push(task);
                    that._runNextTask();
                },
                // Control tasks proccessing
                _runNextTask: function()
                {
                    // If we have free thread
                    if (that.activeThreadsCount < that.threadsCount) {
                        that.activeThreadsCount++;

                        // Get next task from queue and run it
                        if (that.queue.length) {
                            task = that.queue.shift();
                            // Set callback function on task, to know that we can execute next one
                            task.setOption('onFinish', that.onTaskFinish);
                            task.run();
                        }
                    }
                },
                // Set how many threads should be used for processing our task queue
                setThreadsCount: function(threadsCount)
                {
                    that.threadsCount = threadsCount;
                }
            };

            return that;
        }

        function phpRack_Timer(options)
        {
            var that = {
                elapsedSeconds: 0,
                // timer interval handler (used internally for unregister timer from window)
                intervalId: null,
                options: {onTick: null},
                // Constructor
                __construct: function(options)
                {
                    // Overwrite default options
                    $.extend(that.options, options);
                },
                // When timer is active this function will be automatically executed every second
                tick: function()
                {
                    that.elapsedSeconds++;

                    // If callback function was passed to constructor as param, execute it
                    if (that.options.onTick !== null) {
                        that.options.onTick(that);
                    }
                },
                start: function()
                {
                    // Stop timer if was earlier executed
                    that.stop();

                    // Reset timer elapsed time
                    that.elapsedSeconds = 0;

                    // Register timer function which will be called every 1000ms = 1s
                    that.intervalId = window.setInterval(that.tick, 1000);
                },
                stop: function()
                {
                    // If timer was earlier started and is still active
                    if (that.intervalId !== null) {
                        // Remove interval to stop calling tick() function every second
                        window.clearInterval(that.intervalId);
                    }
                    that.intervalId = null;
                },
                // Return elapsed seconds in format (m:ss)
                getFormattedTime: function()
                {
                    var result = '';
                    var minutes = Math.floor(that.elapsedSeconds / 60);
                    var seconds = that.elapsedSeconds % 60;
                    result += minutes + ':';
                    if (seconds < 10) {
                        result += '0';
                    }
                    result += seconds;
                    return result;
                },
                // Return elapsed seconds as integer
                getElapsedSeconds: function()
                {
                    return that.elapsedSeconds;
                }
            };

            that.__construct(options);
            return that;
        }

        function phpRack_Test(options)
        {
            // jQuery object which represent test task Element in DOM tree
            var $this = $(options.id);
            var that = {
                options: options,
                timer: null,
                isRunning: false,
                // jQuery object which represent test result Element in DOM tree
                $result: $this.find('span.result'),
                // jQuery object which represent test name Element in DOM tree
                $label: $this.find('span.label'),
                // jQuery object which represent tags Element in DOM tree
                $tags: $this.find('span.tags'),
                // jQuery object which represent test message Element in DOM tree
                $message: $this.find('pre'),
                displayTimer: false,
                timeoutId: null,
                // log lines buffer, used for control which lines should be still visible
                lines: [],
                // XMLHttpRequest object returned from $.ajax query,
                // give ability to abort connections
                xmlHttpRequest: null,
                // test execution time after which abort is possible
                abortWaitTime: 10,
                // Constructor
                __construct: function()
                {
                    // Create timer object and pass callback function to it
                    that.timer = new phpRack_Timer({onTick: that.onTimerTick});

                    // If user click on test name
                    that.$label.click(
                        function()
                        {
                            // Set that timer should be visible
                            that.displayTimer = true;

                            // Try execute test one more time
                            that.run();
                        }
                    );

                    // Attach one time event to "click to start..." text
                    if (!that.options.autoStart) {
                        that.$result.one('click', that.run);
                    }
                },
                setOption: function(key, value)
                {
                    that.options[key] = value;
                },
                onResultClick: function()
                {
                    // if test is running above that.abortWaitTime seconds abort it
                    if (that.isRunning && that.timer.getElapsedSeconds() >= that.abortWaitTime) {
                        that.xmlHttpRequest.abort();
                    } else {
                        // if test is finished, or running below than that.abortWaitTime seconds
                        if (that.$message.html()) {
                            that.$message.slideToggle();
                        }
                    }
                },
                _setStatus: function (success, message, options)
                {
                    // Update result span with OK/FAILURE depending on success param
                    if (success === true) {
                        that.$result.html(phpParams.ok).addClass('success');
                    } else {
                        that.$result.html(phpParams.failure).addClass('failure');
                    }

                    if (options && options.reload) {
                        that.$result.html(that.$result.html() + '?');
                    }

                    if (options && options.attachOutput) {
                        // Remove old execution time line
                        that.lines.pop();

                        // Remove empty line old execution time line
                        if (that.lines.length && that.lines[that.lines.length - 1].text === '') {
                            that.lines.pop();
                        }

                        // Remove lines after visibility expire time
                        while (that.lines.length > options.linesCount &&
                               that.lines[0].expireTime < (new Date()).getTime()) {
                            that.lines.shift();
                        }

                        // If new content begine with \n remove,
                        // because during lines joining we add this char
                        if (message.length && message[0] == "\n") {
                            message = message.substr(1);
                        }

                        // Add last log output to our lines set
                        $.each(
                            message.split("\n"),
                            function()
                            {
                                that.lines.push(
                                    {
                                        'text' : this,
                                        'expireTime' : (new Date()).getTime()  + options.secVisible * 1000
                                    }
                                );
                            }
                        );

                        // Create message from visible lines
                        message = '';
                        $.each(
                            that.lines,
                            function()
                            {
                                message += this.text + "\n";
                            }
                        );
                    }

                    if (options && options.tags) {
                        // cleanup tags list
                        that.$tags.empty();
                        $.each(
                            options.tags,
                            function(index, value)
                            {
                                // create new tag
                                var $tag = $('' + value + '');
                                $tag.click(
                                    function()
                                    {
                                        // set ajax call param and execute test again
                                        that.options.data['tag'] = value;
                                        that.run();
                                    }
                                );
                                // add tag to list
                                that.$tags.append($tag);
                            }
                        );
                    }

                    // Fill message pre tag with text returned from server
                    that.$message.html(message);

                    // Stop timer and update its state to user can repeat test
                    that.isRunning = false;
                    that.timer.stop();

                    // If we have registered callback function after test finish, execute it
                    if (that.options.onFinish) {
                        that.options.onFinish();
                    }
                },
                _startTimer: function()
                {
                    // Start test timer
                    that.timer.start();
                    that.onTimerTick();
                },
                // Callback function which will be called every seconds from phpRack_Timer
                onTimerTick: function()
                {
                    var elapsedSeconds = that.timer.getElapsedSeconds();
                    // If test is executed above 5s, set flag to display timer
                    if (elapsedSeconds > 5) {
                        that.displayTimer = true;
                    }

                    // Check that should display timer (User click or time execution > 5s)
                    if (that.displayTimer) {
                        var message = 'running (' + that.timer.getFormattedTime();
                        if (elapsedSeconds >= that.abortWaitTime) {
                            message += ', click to stop';
                        }
                        message += ')...';

                        that.$result.html(message);
                    }
                },
                _setReloadTimeout: function(seconds)
                {
                    that._removeReloadTimeout();

                    // if window has focus, and result message is expanded
                    if ((phpRack_Window.hasFocus() || !that.options.pauseWhenFocusLost) &&
                         that.$message.is(":visible")) {
                        var delay = seconds * 1000; // in miliseconds
                        // execute run() method with passed reload timeout
                        that.timeoutId = window.setTimeout(that.run, delay);
                    } else {
                        // if window has no focus, try again in 1 second
                        var sleepFunction = function()
                        {
                            that._setReloadTimeout(seconds);
                        };
                        window.setTimeout(sleepFunction, 1000);
                    }
                },
                _removeReloadTimeout: function()
                {
                    // If another run() is waiting for execute, ignore it
                    if (that.timeoutId) {
                        window.clearTimeout(that.timeoutId);
                    }
                },
                run: function()
                {
                    // Script still waiting for receive response from server
                    if (that.isRunning) {
                        // set flag to display timer
                        that.displayTimer = true;
                        that.onTimerTick();

                        // Prevent execution one more time because test is still running
                        return;
                    }

                    that._removeReloadTimeout();

                    // Set initial states
                    that._startTimer();
                    that.isRunning = true;
                    that.$result.html('running...');

                    // Remove earlier added handler to don't have duplicate
                    that.$result.unbind('click', that.onResultClick);
                    that.$result.bind('click', that.onResultClick);

                    // Remove added classes, because test can be executed many times
                    that.$result.removeClass('success failure');

                    // Make ajax query to server
                    that.xmlHttpRequest = $.ajax(
                        {
                            url: that.options.url,
                            data: that.options.data,
                            dataType: 'json',
                            cache: false, // Set flag to don't cache server response
                            // Standard callback if JSON returned from server is correct
                            // or have 0 bytes response
                            success: function (json)
                            {
                                // We should use standard display method without word wrap
                                that.$message.removeClass('word_wrap');

                                // If server returned no empty response
                                if (json) {
                                    // Set status to OK with log message
                                    that._setStatus(json.success, json.log.htmlspecialchars(), json.options);
                                    if (json.options) {
                                        if (json.options.reload) {
                                            that._setReloadTimeout(json.options.reload);
                                        }
                                        // Add request params which will need be send in next query
                                        if (json.options.data) {
                                            $.extend(that.options.data, json.options.data);
                                        }
                                    }
                                } else {
                                    // Set status to FAILURE with empty response message
                                    that._setStatus(false, 'Server returned empty response');
                                }
                            },
                            // Callback function if have some communication errors
                            error: function (XMLHttpRequest, textStatus, errorThrown)
                            {
                                // If we have some problem with server (Internal error, 404, 301/302 redirection)
                                if (XMLHttpRequest.status != 200) {
                                    // Create error message with headers
                                    message = XMLHttpRequest.status + ' ' + XMLHttpRequest.statusText + "\n";
                                    message += XMLHttpRequest.responseText;
                                } else {
                                    // We received malformed JSON
                                    // (php script throwed some warning, unhandled exception, extra data, etc...)
                                    if (typeof errorThrown == 'object') {
                                        message = errorThrown.toString();
                                    } else {
                                        message = errorThrown;
                                    }
                                }

                                // Use word wrap for this messages type
                                that.$message.addClass('word_wrap');

                                // Set status to FAILURE with errorThrown as message
                                that._setStatus(false, message.htmlspecialchars());
                            }
                        }
                    );
                }
            };

            that.__construct();
            return that;
        }

        // Create queue for processing our tests
        var taskQueue = new phpRack_TaskQueue();

        // Set how many threads(tests) should be executed in same time
        // (not too high to avoid Apache limit problems)
        taskQueue.setThreadsCount(2);

        for (var id in calls) {
            var call = calls[id];
            // Create test object

            var data = {};
            data[phpParams.ajaxTag] = call.fileName;
            data[phpParams.ajaxToken] = call.divId;

            var test = new phpRack_Test(
                {
                    id: call.divId,
                    url: phpParams.requestUri,
                    data: data,
                    autoStart: call.autoStart,
                    pauseWhenFocusLost: call.pauseWhenFocusLost
                }
            );

            // Add test to processing queue if has autoStart enabled
            if (call.autoStart) {
                taskQueue.add(test);
            }
        }
    }
);


text:
<?php echo "<?xml version=\"1.0\"?>\n" ?>
<!DOCTYPE html PUBLIC
    "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

        <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8"/>

        <title>phpRack Testing Report</title>

            <img
                src='data:image/png;base64,<?php
                    echo base64_encode(
                        file_get_contents(PHPRACK_PATH . '/layout/logo.png')
                    )
                ?>'
                alt='phpRack' />
            v<?php echo PHPRACK_VERSION?>

        <?php eval("include PHPRACK_PATH . '/layout/{$this->script}';")?>

repo_name: michael-romer/zf-boilerplate

repo_language: PHP

mime_type: text/html


text:
/**
 * 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: index.css 582 2010-05-12 09:19:41Z yegor256@yahoo.com $
 * @category phpRack
 */

/* everything in the page */
body {
    font-family: Verdana;
    font-size: 12px;
}

/* all images */
img {
    border: 0;
}

/* all hyper links */
a {
    color: #25AAE1;
    text-decoration: none;
}
    /* mouse-hovered hyper links */
    a:hover {
        text-decoration: underline;
    }

/* top left logo block, including image */
#logo {
    position: relative;
    width: 264px;
    margin-bottom: 10px;
}

    /* image in the logo block */
    #logo img {
        width: 228px;
        height: 60px;
    }

    /* text label with revision number, in the logo block */
    #logo span {
        position: absolute;
        top: 2px;
        left: 212px;
        width: 100px;
        color: #25AAE1;
    }

/* list of tasks */
#task-list {
}

    /* one individual task */
    #task-list .task {
        padding: 5px;
    }

        /* log of the task execution */
        #task-list .task pre {
            padding: 5px;
            margin-left: 10px;
            border-left: 2px solid #25AAE1;
        }

    /* still processing... */
    #task-list .result {
        cursor: pointer;
        color: gray;
    }

    /* task label, with the name of the test */
    #task-list .label {
        cursor: pointer;
    }

    /* task tag, with the value of param */
    #task-list .tag {
        cursor: pointer;
        margin-left: 20px;
    }

    /* finished with success */
    #task-list .success {
        color: green !important;
        text-decoration: underline;
    }

    /* finished with failure */
    #task-list .failure {
        color: red !important;
        font-weight: bold;
        text-decoration: underline;
    }

/* wrapping of words when the result is not a formatted text */
.word_wrap {
    white-space: pre-wrap; /* css-3 */
    white-space: -moz-pre-wrap; /* Mozilla, since 1999 */
    white-space: -pre-wrap; /* Opera 4-6 */
    white-space: -o-pre-wrap; /* Opera 7 */
    word-wrap: break-word; /* Internet Explorer 5.5+ */
    width: 900px;
}


text:
<?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();
    }
}


text:
<?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]);
    }
}


text:
<?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;
        }
    }

}


text:
<?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: Url.php 545 2010-05-04 09:40:46Z yegor256@yahoo.com $
 * @category phpRack
 */

/**
 * Socket based adapter which help checking remote url accessibility
 * and retrieve content from them
 *
 * @package Adapters
 */
class phpRack_Adapters_Url
{
    /**
     * Socket returned by fsockopen()
     *
     * @see connect()
     * @var resource
     */
    private $_socket;

    /**
     * Host name, set in __construct
     *
     * @see __construct()
     */
    private $_host;

    /**
     * Port number used to connect with host.
     * Can be changed by passing URL with custom one to __construct()
     *
     * @see __construct()
     * @var integer
     */
    private $_port = 80;

    /**
     * Connection options, can be overwritten by passing new values as array
     * to constructor as second parameter
     *
     * @var array
     * @see __construct()
     * @see connect()
     * @see getContent()
     */
    private $_options = array(
        'connectTimeout' => 2,    // timeouts in seconds
        'readTimeout'    => 60
    );

    /**
     * Constructor
     *
     * @param string URL
     * @param array Options
     * @return void
     * @throws Exception if URL is not valid
     * @throws Exception if some of passed options is not recognized
     */
    public function __construct($url, array $options = array())
    {
        // If url has not sheme defined - add it
        if (!preg_match('#^\w+://#', $url)) {
            $url = 'http://' . $url;
        }

        $urlParts = @parse_url($url);

        // If there was url parsing error
        if ($urlParts === false) {
            throw new Exception('This is NOT valid url');
        }

        // Set host
        $this->_host = $urlParts['host'];

        // Set url path
        if (isset($urlParts['path'])) {
            $this->_path = $urlParts['path'];
        } else {
            $this->_path = '/';
        }

        // Check if have query params after "?", if yes attach them to our _path
        if (isset($urlParts['query'])) {
            $this->_path .= '?' . $urlParts['query'];
        }

        // Check if port number was passed in URL
        if (isset($urlParts['port'])) {
            $this->_port = $urlParts['port'];
        }

        // Overwrite default options
        foreach ($options as $option => $value) {
            if (!array_key_exists($option, $this->_options)) {
                throw new Exception("Option '{$option}' is not recognized");
            }
            $this->_options[$option] = $value;
        }
    }

    /**
     * Factory, to simplify calls
     *
     * @param string URL
     * @param array Options
     * @return phpRack_Adapters_Url
     */
    public static function factory($url, array $options = array())
    {
        return new self($url, $options);
    }

    /**
     * Create connection to server
     *
     * @return void
     * @throws Exception if can't connect to server
     */
    protected function _connect()
    {
        // If we are not connected
        if (!$this->_socket) {
            $errorNumber = null;
            $errorString = null;

            // Try to open connection to server
            $this->_socket = @fsockopen(
                $this->_host,
                $this->_port,
                $errorNumber,
                $errorString,
                $this->_options['connectTimeout']
            );
        }

        // If can't connect
        if (!$this->_socket) {
            throw new Exception (
                "Can't connect to '{$this->_host}':'{$this->_port}'"
                . " Error #'{$errorNumber}': '{$errorString}'"
            );
        }
    }

    /**
     * Close current connection
     *
     * @return void
     */
    protected function _disconnect()
    {
        // If we are connected
        if (is_resource($this->_socket)) {
            fclose($this->_socket);
            $this->_socket = null;
        }
    }

    /**
     * Check whether URL is accessible
     *
     * @return boolean
     */
    public function isAccessible()
    {
        try {
            $this->_connect();
        } catch (Exception $e) {
            assert($e instanceof Exception); // for ZCA only
            return false;
        }

        return true;
    }

    /**
     * Get content of URL passed to constructor
     *
     * @see __construct()
     * @return string Content of URL
     * @throws Exception If can't get content for some reason
     */
    public function getContent()
    {
        // Try to connect with server, if can't will throw exception
        $this->_connect();

        // Create HTTP request
        $request = "GET {$this->_path} HTTP/1.1\r\n"
            . "Host: {$this->_host}\r\n"
            . "Connection: Close\r\n\r\n\r\n";

        // Send request
        fwrite($this->_socket, $request);

        $response = '';

        stream_set_timeout($this->_socket, $this->_options['readTimeout']);

        // Key must be underscored because of array format
        // returned by stream_get_meta_data() function
        $info = array('timed_out' => false);
        // Receive response
        while (!feof($this->_socket) && !$info['timed_out']) {
            $line = fgets($this->_socket, 1024);
            $response .= $line;
            $info = stream_get_meta_data($this->_socket);
        }

        // Close connection
        $this->_disconnect();

        // If connection timeouted
        if ($info['timed_out']) {
            throw new Exception('Connection timed out!');
        }

        return $response;
    }
}


text:
<?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();
        }
    }
}


text:
<?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: Os.php 545 2010-05-04 09:40:46Z yegor256@yahoo.com $
 * @category phpRack
 */

/**
 * OS adapter used to get information where script is executed
 *
 * @package Adapters
 */
class phpRack_Adapters_Os
{
    /**
     * System constants used for simplify comparisions
     */
    const WINDOWS = 'Windows';
    const LINUX = 'Linux';
    const DARWIN = 'Darwin';

    /**
     * Recognize OS and return its name as string (Windows, Linux, etc)
     *
     * @return string
     * @see phpRack_Adapters_Cpu::factory()
     * @throws Exception if operating system can't be recognized
     */
    public static function get()
    {
        switch (true) {
            /* windows */
            case (substr(PHP_OS, 0, 3) === 'WIN'):
                return self::WINDOWS;

            /* Mac OS and Mac OS X */
            case (substr(PHP_OS, 0, 6) === 'Darwin'):
                return self::DARWIN;

            /* Linux */
            case (substr(PHP_OS, 0, 5) === 'Linux'):
                return self::LINUX;

            /* all other systems */
            default:
                throw new Exception('Unknown operating system');
        }
    }

    /**
     * Is it *NIX system?
     *
     * Everything which is NOT windows is Unix. Very rough assumption, but this
     * is enough for now.
     *
     * @return boolean
     */
    public static function isUnix()
    {
        return (self::get() != self::WINDOWS);
    }
}


text:
<?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: Pear.php 545 2010-05-04 09:40:46Z yegor256@yahoo.com $
 * @category phpRack
 */

/**
 * @see phpRack_Adapters_Pear_Package
 */
require_once PHPRACK_PATH . '/Adapters/Pear/Package.php';

/**
 * PEAR adapter used for checking PEAR packages availability
 *
 * @package Adapters
 */
class phpRack_Adapters_Pear
{
    /**
     * Find and create new package
     *
     * @param string Package name
     * @return phpRack_Adapters_Pear_Package|null
     * @throws Exception If PEAR is not installed properly
     * @see phpRack_Package_Pear::package()
     */
    public function getPackage($name)
    {
        $package = new phpRack_Adapters_Pear_Package($name);
        try {
            $package->getVersion();
        } catch (Exception $e) {
            assert($e instanceof Exception); // for ZCA only
            return null;
        }
        return $package;
    }

    /**
     * Get full list of installed packages
     *
     * @return array of phpRack_Adapters_Pear_Package
     * @throws Exception If some problem appear during package informations loading
     * @see phpRack_Package_Pear::showList()
     */
    public function getAllPackages()
    {
        $packages = array();
        $command = 'pear list -a';
        /**
         * @see phpRack_Adapters_Shell_Command
         */
        require_once PHPRACK_PATH . '/Adapters/Shell/Command.php';
        $result = phpRack_Adapters_Shell_Command::factory($command)->run();

        // divide command output by channels
        foreach (explode("\n\n", $result) as $channel) {
            $lines = explode("\n", $channel);
            $matches = array();

            // get channel name
            if (!preg_match('/CHANNEL ([^:]+):/', $lines[0], $matches)) {
                continue;
            }

            $channelName = $matches[1];

            // skip 3 first lines (channel, separator, packages header line)
            $packageLines = array_slice($lines, 3);

            foreach ($packageLines as $packageLine) {
                // get package name
                if (preg_match('/^(\w+)/', $packageLine, $matches)) {
                    // set full package name with channel
                    $packageName = "{$channelName}/{$matches[1]}";
                    $packages[] = new phpRack_Adapters_Pear_Package($packageName);
                }
            }
        }

        return $packages;
    }
}


text:
<?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;
        }
    }
}


text:
<?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;
    }
}


text:
<?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);
    }

}


text:
<?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;
    }
}


text:
<?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);
    }
}


text:
<?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();
}


text:
<?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;
    }
}


text:
<?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');
    }
}


text:
<?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);
    }
}


text:
<?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');
    }
}


text:
<?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);
    }

}