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: Command.php 565 2010-05-07 04:56:24Z yegor256@yahoo.com $
 * @category phpRack
 */

 /**
 * @see phpRack_Adapters_ConnectionManager
 */
require_once PHPRACK_PATH . '/Adapters/ConnectionMonitor.php';

/**
 * Shell command adapter used to execute external commands and programs
 *
 * @package Adapters
 * @author netcoderpl@gmail.com
 */
class phpRack_Adapters_Shell_Command
{
    /**
     * Shell command to execute
     *
     * @var string
     * @see __construct()
     * @see run()
     */
    private $_command;

    /**
     * Process resource returned by proc_open() used for process identification
     *
     * @var string
     * @see run()
     * @see __destruct()
     */
    private $_process;

    /**
     * Pipe ids, used for select with which process pipe we want to communicate
     *
     * @see run()
     */
    const PIPE_STD_IN  = 0;
    const PIPE_STD_OUT = 1;

    /**
     * Shell command constructor
     *
     * @param string Command to execute
     * @return void
     */
    private function __construct($command)
    {
        $this->_command = $command;
    }

    /**
     * Shell command factory, to simplify calls
     *
     * @param string Command to execute
     * @return phpRack_Adapters_Shell_Command
     */
    public static function factory($command)
    {
        return new self($command);
    }

    /**
     * Execute shell command. Use asynchronous pipes to communicate
     * with child process
     *
     * We must pass custom env from _getEnv() method to to
     * proc_open() call, because on phprack.com server.
     * When we execute external php file from other process, script
     * make some strange forks and execute itself many times. This
     * behavior results server internal error.
     *
     * shell_exec() is also affected by this issue, we have earlier
     * this problem, and was solved by adding "env -i" before shell
     * command. Recently we have added PEAR support, which internally
     * execute PHP script, so problem returned.
     *
     * Direct reason of this error is $_ENV['PATH']
     * variable. When we unset it and pass modified env to
     * proc_open(). It works on Windows XP, Ubuntu Linux and solve
     * problem on phprack.com server.
     * But from some reason on MacOS there is some problem with
     * this env value reseting, and we lose some privilege? Due to
     * this fact, our unit tests fail, because PEAR test produce
     * error:
     *
     * <code>
     * touch(): Unable to create file /opt/local/lib/php/.lock
     * because Permission denied in /usr/local/PEAR/PEAR/Registry.php
     * on line 835
     * </code>
     *
     * If we pass null to proc_open() env param we have no problems
     * on MacOS, but problem on phprack.com still exists.
     *
     * That is reason why we must pass to this function custom env
     * param.
     *
     * @return string Command execution output
     * @throws Exception if from some reason command can't be executed
     * @throws Exception if command process was terminated
     * @see phpRack_Package_Php::lint()
     */
    public function run()
    {
        $descriptors = array(
            self::PIPE_STD_IN  => array('pipe', 'r'), // child process stdin
            self::PIPE_STD_OUT => array('pipe', 'w'), // child process stdout
        );

        $pipes = array();
        // execute command and get its proccess resource
        $this->_process = proc_open(
            $this->_command,
            $descriptors,
            $pipes,
            getcwd(),
            $this->_getEnv()
        );

        // if there was some problems with command execution
        if (!is_resource($this->_process)) {
            throw new Exception("Can't execute shell command '{$this->_command}'");
        }

        $output = '';

        // close stdin to avoid child process waiting for data
        fclose($pipes[self::PIPE_STD_IN]);
        unset($pipes[self::PIPE_STD_IN]);

        // set non blockiing mode for pipes
        foreach ($pipes as $pipe) {
            stream_set_blocking($pipe, false);
        }

        while (true) {
            $readPipes = array();

            // check that we readed everything from pipes
            foreach ($pipes as $pipe) {
                if (!feof($pipe)) {
                    $readPipes[] = $pipe;
                }
            }

            // we have nothing more to read
            if (empty($readPipes)) {
                break;
            }

            // set to null because we only use pipes to read
            $write  = null;
            $except = null;

            /**
             * Maximum time for which stream_select() function will lock script
             * execution.
             *
             * This short timeout allow as to return to main script and check
             * connection status
             */
            $waitTimeout = 1; // 1 second

            /**
             * Check that we have some data to read from child process pipes
             *
             * If there are some new data to read, this function will return
             * imediatelly.
             *
             * If there are NO new data to read, after 1 second it return with
             * $changedStreamsCount = 0
             *
             * $readPipes is passed, by reference and after call will contain
             * ONLY pipes with new data to read
             */
            $changedStreamsCount = stream_select($readPipes, $write, $except, $waitTimeout);

            // if child process was terminated
            if ($changedStreamsCount === false) {
                throw new Exception('Proccess was terminated');
            }

            // check client connection is still opened
            phpRack_Adapters_ConnectionMonitor::getInstance()->ping();

            // read data from pipes and attach them to output
            foreach ($readPipes as $pipe) {
                $output .= fread($pipe, 1024);
            }
        }

        // close pipes to avoid deadlock during proc_close()
        fclose($pipes[self::PIPE_STD_OUT]);

        // close proccess and cleanup
        proc_close($this->_process);
        $this->_process = null;

        return $output;
    }

    /**
     * Shell command destructor
     *
     * @return void
     */
    public function __destruct()
    {
        // if run() method was executed successfully
        if ($this->_process === null) {
            return;
        }

        // get process status
        $processStatus = proc_get_status($this->_process);
        if ($processStatus === false) {
            return;
        }

        // if process is still running, terminate it with SIGKILL
        if ($processStatus['running']) {
            proc_terminate($this->_process, 9);
        }
    }

    /**
     * Get env which should be passed to proc_open()
     *
     * @return array|null
     * @see run()
     */
    protected function _getEnv()
    {
        /**
         * @see phpRack_Adapters_Os
         */
        require_once PHPRACK_PATH . '/Adapters/Os.php';
        $os = phpRack_Adapters_Os::get();

        // we must modify env only on Linux, so we should return default env in other cases
        if ($os != phpRack_Adapters_Os::LINUX || !isset($_ENV)) {
            return null;
        }

        // we must remove PATH to avoid script forking problem on some servers
        return array_diff_key($_ENV, array('PATH' => ''));
    }
}


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

/**
 * PEAR adapter used for checking PEAR packages availability
 *
 * @package Adapters
 */
class phpRack_Adapters_Pear_Package
{
    /**
     * Package name
     *
     * @var string
     * @see __construct()
     * @see getName()
     */
    private $_name;

    /**
     * Raw package info returned from "pear info $packageName" command
     *
     * @var string
     * @see __construct()
     * @see getName()
     * @see getVersion()
     */
    private $_rawInfo;

    /**
     * Construct the class
     *
     * @param string Name of the package
     * @throws Exception if PEAR is not installed properly
     * @return void
     */
    public function __construct($name)
    {
        $this->_name = $name;

        $command = 'pear info ' . escapeshellarg($this->_name);
        /**
         * @see phpRack_Adapters_Shell_Command
         */
        require_once PHPRACK_PATH . '/Adapters/Shell/Command.php';
        $result = phpRack_Adapters_Shell_Command::factory($command)->run();

        if (!$result) {
            throw new Exception('PEAR is not installed properly');
        }

        $this->_rawInfo = $result;
    }

    /**
     * Get name of the package
     *
     * @return string
     */
    public function getName()
    {
        return $this->_name;
    }

    /**
     * Check whether Package exists
     *
     * @return boolean
     * @throws Exception If package has invalid version number
     * @see phpRack_Package_Pear::package()
     */
    public function getVersion()
    {
        $matches = array();
        if (!preg_match('/^Release Version\s+(\S+)/m', $this->_rawInfo, $matches)) {
            throw new Exception('Invalid version for the package');
        }
        return $matches[1];
    }

    /**
     * Get package raw info
     *
     * @return string
     * @see phpRack_Package_Pear::package()
     */
    public function getRawInfo()
    {
        return $this->_rawInfo;
    }
}

repo_name: michael-romer/zf-boilerplate

repo_language: PHP

mime_type: text/html


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

/**
 * @see phpRack_Adapters_Config
 */
require_once PHPRACK_PATH . '/Adapters/Config.php';

/**
 * Config adapter used for store test configuration loaded from INI file
 *
 * You can use it like this:
 *
 * <code>
 * // app.ini:
 * // [production]
 * // params.db.username = 'test'
 * $ini = new phpRack_Adapters_Config_Ini('app.ini', 'production');
 * assert($ini->params->db->username == 'test');
 * </code>
 *
 * @package Adapters
 */
class phpRack_Adapters_Config_Ini extends phpRack_Adapters_Config
{
    /**
     * Create config object and load selected section from INI file,
     * or all sections if $sectionName == null
     *
     * @param string Filename of INI file
     * @param string|null Section name to load, or null to load all
     * @return void
     * @throws Exception if INI file not exists
     * @throws Exception if section not exists in INI file
     * @see ConfigTest::testConfigIni() and other integration tests
     */
    public function __construct($filename, $sectionName = null)
    {
        $sections = $this->_loadSectionsFromIniFile($filename);
        // one section to return
        if ($sectionName) {
            if (!array_key_exists($sectionName, $sections)) {
                throw new Exception("Section '{$sectionName}' doesn't exist in INI file '{$filename}'");
            }
            $dataArray = $this->_sectionToArray($sections[$sectionName]);
        } else {
            // all sections to return
            foreach ($sections as $key => $section) {
                $dataArray[$key] = $this->_sectionToArray($section);
            }
        }
        parent::__construct($dataArray);
    }

    /**
     * Convert section with "key.subkey1.subkey2" values as keys
     * to multidimensional associative array
     *
     * @param array section from ini file
     * @return array
     * @see __construct()
     */
    protected function _sectionToArray($section)
    {
        $dataArray = array();
        foreach ($section as $key => $value) {
            $currentElement =& $dataArray;
            foreach (explode('.', $key) as $keyFragment) {
                $currentElement =& $currentElement[$keyFragment];
            }
            $currentElement = $value;
        }
        return $dataArray;
    }

    /**
     * Load config sections from INI file, taking into account section inheritance
     *
     * @param string INI file to load and parse
     * @return array
     * @throws Exception if config INI file not exists
     * @see __construct()
     */
    protected function _loadSectionsFromIniFile($filename)
    {
        if (!file_exists($filename)) {
            throw new Exception("INI file '{$filename}' doesn't exist");
        }
        $sections = array();
        $iniFileSections = parse_ini_file($filename, true);

        foreach ($iniFileSections as $sectionName => $data) {
            // divide section name to check it have some parent ([section : parent])
            $nameParts = explode(':', $sectionName);
            $thisSectionName = trim($nameParts[0]);

            // if section have parent
            if (isset($nameParts[1])) {
                $parentSectionName = trim($nameParts[1]);
                // merge current section values, with parent values
                $data = array_merge(
                    $sections[$parentSectionName],
                    $data
                );
            }
            $sections[$thisSectionName] = $data;
        }

        return $sections;
    }
}


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: DirectoryFilterIterator.php 611 2010-07-12 14:23:40Z yegor256@yahoo.com $
 * @category phpRack
 */

/**
 * Iterator filter class which help to get only files which match filter rules
 *
 * @package Adapters
 * @subpackage Files
 * @see phpRack_Package_Disc::showDirectory()
 */
class phpRack_Adapters_Files_DirectoryFilterIterator extends FilterIterator
{

    /**
     * Directory we're iterating
     *
     * @var string
     * @see __construct()
     */
    protected $_dir;

    /**
     * Maximum depth to be visible
     *
     * @var integer
     * @see setMaxDepth()
     */
    private $_maxDepth = null;

    /**
     * Regular expression patterns used to determine what files should be ignored
     *
     * @var string[]
     */
    private $_excludePatterns;

    /**
     * Regular expression pattern used to determine what files should returned
     *
     * @var string
     */
    private $_extensionsPattern;

    /**
     * Constructor, private, don't call it directly, instead use factory()
     *
     * @param string Path
     * @return void
     * @see factory()
     */
    public function __construct($dir)
    {
        parent::__construct(
            new RecursiveIteratorIterator(
                new RecursiveDirectoryIterator($dir),
                RecursiveIteratorIterator::SELF_FIRST
            )
        );
        $this->_dir = $dir;
    }

    /**
     * Create new iterator from directory path
     *
     * @param string Path
     * @return phpRack_Adapters_Files_DirectoryFilterIterator
     */
    public static function factory($dir)
    {
        return new self($dir);
    }

    /**
     * Set which extensions will be used as whitelist
     *
     * @param string|array Comma separated list of extensions, or list of them
     * @return $this
     */
    public function setExtensions($extensions)
    {
        if (!is_array($extensions)) {
            $extensions = explode(',', $extensions);
        }

        // Escape extension special chars to have always valid regular expression
        foreach ($extensions as &$extension) {
            preg_quote(trim($extension));
        }

        $this->_extensionsPattern = '#(\.' . implode('|', $extensions). '$)#';
        return $this;
    }

    /**
     * Set pattern which will be used as blacklist
     *
     * @param string|array Regular expression pattern, or list of them
     * @return $this
     */
    public function setExclude($excludePatterns)
    {
        if (!is_array($excludePatterns)) {
            $excludePatterns = array($excludePatterns);
        }
        $this->_excludePatterns = $excludePatterns;
        return $this;
    }

    /**
     * Set maximum directory depth
     *
     * @param integer Maximum depth
     * @return $this
     */
    public function setMaxDepth($maxDepth)
    {
        $this->_maxDepth = $maxDepth;
        return $this;
    }

    /**
     * Callback function which will be called to determine current file should be in collection or no
     *
     * @return boolean
     */
    public function accept()
    {
        $file = $this->current();

        // Ignore "dots files" which appear in some systems
        if (trim($file, '.') == '') {
            return false;
        }

        if (!is_null($this->_maxDepth)
            && substr_count(substr($file, strlen($this->_dir) + 1), '/') > $this->_maxDepth
        ) {
            return false;
        }

        // Ignore files which don't match extensionsPattern
        if ($this->_extensionsPattern && !preg_match($this->_extensionsPattern, $file)) {
            return false;
        }

        // Ignore files which match excludePattern
        if ($this->_excludePatterns) {
            foreach ($this->_excludePatterns as $pattern) {
                if (preg_match($pattern, $file)) {
                    return false;
                }
            }
        }

        // Everything rest is allowable
        return true;
    }

}


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

/**
 * Mail adapter used for mailing phpRack reports
 *
 * @package Adapters
 */
class phpRack_Adapters_Notifier_Mail
{
    /**
     * Factory method to get one of Sendmail or Smtp class instances.
     *
     * Depends on options specified. Available options depend on transport
     * you choose.
     *
     * @see phpRack_Adapters_Notifier_Mail_Smtp
     * @see phpRack_Adapters_Notifier_Mail_Sendmail
     * @param array List of parameters
     * @return phpRack_Adapters_Mail
     * @throws Exception
     */
    public static function factory($class = 'sendmail', array $params = array())
    {
        $transport = ucfirst(strtolower($class));
        /**
         * @see phpRack_Adapters_Notifier_Mail_Abstract
         */
        $classFile = PHPRACK_PATH . "/Adapters/Notifier/Mail/{$transport}.php";
        if (!file_exists($classFile)) {
            throw new Exception("Transport {$transport} is absent");
        }
        eval("require_once '{$classFile}';"); // for ZCA validation
        $transportClass = 'phpRack_Adapters_Notifier_Mail_' . $transport;
        return new $transportClass($params);
    }
}


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

/**
 * @see phpRack_Adapters_Notifier_Mail_Abstract
 */
require_once PHPRACK_PATH . '/Adapters/Notifier/Mail/Abstract.php';

/**
 * Sendmail implementation of phpRack mail
 *
 * @see phpRack_Notifier_Mail_Abstract
 */
class phpRack_Adapters_Notifier_Mail_Sendmail extends phpRack_Adapters_Notifier_Mail_Abstract
{
    /**
     * Preparing and sending mail.
     *
     * Function returns result of the operation
     *
     * @return bool
     * @link http://php.net/manual/en/function.mail.php
     */
    public function send()
    {
        $this->_validateBeforeSend();
        return mail(
            $this->_to[0],
            $this->_getEncodedSubject(),
            $this->_getEncodedBody(),
            $this->_getHeaders()
        );
    }

    /**
     * Function builds headers for mail
     *
     * @return string Plain list with headers
     * @see send()
     */
    private function _getHeaders()
    {
        $headers = array();
        if (count($this->_to) > 1) {
            $headers['Cc'] = implode(', ', array_slice($this->_to, 1));
        }
        $headers['From'] = $this->_from;
        $headers['MIME-Version'] = '1.0';
        $headers['Content-Type'] = 'text/plain; charset=UTF-8';
        $headers['Content-transfer-encoding'] = 'base64';

        return implode(
            "\r\n",
            array_map(
                create_function('$v, $k', 'return $k . ": " . $v;'),
                $headers,
                array_keys($headers)
            )
        );
    }
}


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

/**
 * @see phpRack_Adapters_Notifier_Mail_Abstract
 */
require_once PHPRACK_PATH . '/Adapters/Notifier/Mail/Abstract.php';

/**
 * Smtp implementation of phpRack mail
 *
 * @see phpRack_Notifier_Mail_Abstract
 */
class phpRack_Adapters_Notifier_Mail_Smtp
    extends phpRack_Adapters_Notifier_Mail_Abstract
{
    /**
     * Connection entry point
     *
     * @var resource
     * @see _connect()
     * @see _query()
     */
    protected $_connection;

    /**
     * Stores debug information
     *
     * @var array
     * @see _log()
     */
    protected $_log = array();

    /**
     * Connection address for the stream
     *
     * @var string
     * @see _connect();
     */
    protected $_address;

    /**
     * Constructor for the smtp protocol.
     *
     * Creates address to connect to
     *
     * @param array List of parameters
     * @return void
     */
    public function __construct(array $options = array())
    {
        parent::__construct($options);

        $host = '127.0.0.1';
        if (!empty($this->_options['host'])) {
            $host = $this->_options['host'];
        }

        $port = 25;
        if (!empty($this->_options['port'])) {
            $port = (int)$this->_options['port'];
        }

        $protocol = 'tcp';
        if (!empty($this->_options['tls'])) {
            $protocol = 'tls';
        }

        $this->_address = $protocol . '://' . $host . ':' . $port;
    }

    /**
     * Prepares and sends an mail
     *
     * @throws Exception if connection doesn't established
     * @return void
     */
    public function send()
    {
        // Validating data
        $this->_validateBeforeSend();

        // Connecting
        $this->_connect();

        // Hello server
        $this->_query('EHLO ' . php_uname('n'))->_mustBe(220)->_mustBe(250);

        // If we must use STARTTLS
        if (strpos($this->_getLog(), 'STARTTLS') !== false) {
            $this->_query('STARTTLS')->_mustBe(220, 180);
            if (!@stream_socket_enable_crypto($this->_connection, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) {
                $this->_log("Can't apply TLS encryption", true);
            }
            // Hello once again
            $this->_query('EHLO ' . php_uname('n'))->_mustBe(250);
        }

        // Auth info
        $this->_query('AUTH LOGIN')->_mustBe(334)
            ->_query(base64_encode($this->_options['username']))->_mustBe(334)
            ->_query(base64_encode($this->_options['password']))->_mustBe(235);

        // Basic set
        $this->_query('MAIL FROM:<' . $this->_from . '>')->_mustBe(250)
            ->_query('RCPT TO:<' . $this->_to[0] . '>')->_mustBe(250)
            ->_query('DATA')->_mustBe(354);

        // Mail headers
        $toList = $this->_to;

        $this->_query('From: <' . $this->_from . '>')
            ->_query('To: <' . array_shift($toList) . '>');

        if (count($toList)) {
            $this->_query('Cc: <' . implode('>,<', $toList) . '>');
        }

        $this->_query('Subject: ' . $this->_getEncodedSubject())
            ->_query('MIME-Version: 1.0')
            ->_query('Content-Type: text/plain; charset=UTF-8')
            ->_query('Content-transfer-encoding: base64')
            ->_query("\r\n")
            ->_query($this->_getEncodedBody());

        // Closing data part and sending
        $this->_query('.')->_mustBe(250, 600)
            ->_query('QUIT')->_mustBe(221, 600);
    }

    /**
     * Connects to the stream and returns connection status
     *
     * @return void
     * @throws Exception if can't connect to the mail server
     */
    protected function _connect()
    {
        $this->_connection = @stream_socket_client($this->_address);
        if ($this->_connection === false) {
            $this->_log("Can't connect to the mail server: {$this->_address}", true);
        }
    }

    /**
     * Writes data to the connetion (stream)
     *
     * @var string Message to send to SMTP server
     * @return $this
     * @throws Exception if can't write to the stream
     */
    protected function _query($msg)
    {
        if (@fwrite($this->_connection, $msg . "\r\n") === false) {
            $this->_log("Can't write to a socket", true);
        }
        $this->_log($msg, false);
        return $this;
    }

    /**
     * Reads stream. Moves caret and checks for a code or codes.
     *
     * Second parameter used as time limit for read stream
     *
     * @var int|array $code
     * @var int Timeout (Default: 300)
     * @throws Exception if can't change stream timeout
     * @throws Exception if can't read from the socket
     * @see _log()
     * @return $this
     */
    protected function _mustBe($code, $timeout = 300)
    {
        if (!is_array($code)) {
            $code = array($code);
        }

        if (!@stream_set_timeout($this->_connection, $timeout)) {
            $this->_log("Can't change stream timeout", true);
        }

        $hasError = true;
        $log = $msg = $cmd = '';
        do {
            $log .= $data = @fgets($this->_connection, 1024);
            if ($data === false) {
                $this->_log("Can't read from the socket", true);
            }
            sscanf($data, '%d%s', $cmd, $msg);
            if (in_array($cmd, $code)) {
                $hasError = false;
            }
        } while (strpos($msg, '-') === 0);

        $this->_log($log, $hasError);
        return $this;
    }

    /**
     * Logs information about queries
     * and response to debug
     *
     * @see _mustBe()
     * @see _query()
     * @param string $msg
     * @param bool $throwError
     * @throws Exception if $throwError eq. true
     * @return void
     */
    protected function _log($msg, $throwError = false)
    {
        $this->_log[] = $msg;
        if ($throwError) {
            throw new Exception($this->_getLog());
        }
    }

    /**
     * Returns information about queries and response in plain format
     *
     * @return string
     */
    protected function _getLog()
    {
        return implode("\n", $this->_log);
    }

    /**
     * Destructor.
     *
     * Closes connection if needed
     *
     * @throws Exception if can't close connection
     * @return void
     */
    public function __destruct()
    {
        if (is_resource($this->_connection)) {
            if (@fclose($this->_connection) === false) {
                $this->_log("Can't close connection", 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: Abstract.php 545 2010-05-04 09:40:46Z yegor256@yahoo.com $
 * @category phpRack
 */

/**
 * Abstract class for the phpRack_Adapters_Notifier_Mail_*
 *
 * @package Adapters
 */
abstract class phpRack_Adapters_Notifier_Mail_Abstract
{
    /**
     * Our array with list of options
     *
     * @var array
     * @see __construct()
     */
    protected $_options = array();

    /**
     * Default text of the body
     *
     * @var string
     * @see setBody()
     */
    protected $_body;

    /**
     * List of destination e-mail addresses
     *
     * @var string
     * @see setTo()
     */
    protected $_to = array();

    /**
     * Sender e-mail address
     *
     * @var string
     */
    protected $_from = 'no-reply@phprack.com';

    /**
     * Default message subject
     *
     * @var string
     * @see setSubject()
     */
    protected $_subject = 'phpRack';

    /**
     * Constructor
     *
     * @param array List of parameters
     * @return void
     */
    public function __construct(array $options = array())
    {
        $this->_options = $options;
    }

    /**
     * Assigns body of a mail
     *
     * @param string Text to be assigned
     * @return phpRack_Adapters_Mail
     */
    public function setBody($plain)
    {
        $this->_body = trim($plain);
        return $this;
    }

    /**
     * Assigns subject of a mail
     *
     * @param string
     * @return phpRack_Adapters_Mail
     */
    public function setSubject($text)
    {
        $this->_subject = $text;
        return $this;
    }

    /**
     * Sets destination mail or mails.
     *
     * @param string|array $mails
     * @return phpRack_Adapters_Mail
     */
    public function setTo($mails)
    {
        $this->_to = (!is_array($mails)) ? array($mails) : $mails;
        return $this;
    }

    /**
     * Checks if we are ready to build mail
     *
     * @return bool
     * @see phpRack_Adapters_Notifier_Mail_Sendmail->send()
     * @see phpRack_Adapters_Notifier_Mail_Smtp->send()
     * @throws Exception if To not defined
     * @throws Exception if Body not defined
     */
    protected function _validateBeforeSend()
    {
        if (!count($this->_to)) {
            throw new Exception('Recipients are not specified');
        }
        if (empty($this->_body)) {
            throw new Exception('Body is not specified');
        }
        return true;
    }

    /**
     * Encodes subject to UTF-8
     *
     * @see setSubject()
     * @return string base64 encoded string with special chars
     */
    protected function _getEncodedSubject()
    {
        return '=?UTF-8?B?' . base64_encode($this->_subject) . '?=';
    }

    /**
     * Encodes body to UTF-8.
     * Output text has fixed width
     *
     * @see setBody()
     * @return string base64 encoded string
     */
    protected function _getEncodedBody()
    {
        return rtrim(chunk_split(base64_encode($this->_body), 72, "\n"));
    }
}


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
 */

/**
 * @see phpRack_Package
 */
require_once PHPRACK_PATH . '/Package.php';

/**
 * CPU related assertions
 *
 * @package Tests
 */
class phpRack_Package_Cpu extends phpRack_Package
{

}


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: Db.php 169 2010-03-23 07:04:08Z yegor256@yahoo.com $
 * @category phpRack
 */

/**
 * @see phpRack_Package
 */
require_once PHPRACK_PATH . '/Package.php';

/**
 * Assertions related to SHELL
 *
 * @package Tests
 */
class phpRack_Package_Shell extends phpRack_Package
{

    /**
     * Execute a command and tries to find a regex inside it's result
     *
     * Use it like this, to make sure that PHP scripts are started
     * by "apache" user:
     *
     * <code>
     * class MyTest extends phpRack_Test {
     *   public function testAuthorship() {
     *     $this->assert->shell->exec('whoami', '/apache/');
     *   }
     * }
     * </code>
     *
     * @param string Command to run
     * @param string Regular exception
     * @return $this
     */
    public function exec($cmd, $regex = null)
    {
        /**
         * @see phpRack_Adapters_Shell_Command
         */
        require_once PHPRACK_PATH . '/Adapters/Shell/Command.php';
        $result = phpRack_Adapters_Shell_Command::factory($cmd)->run();

        $this->_log('$ ' . $cmd);
        $this->_log($result);
        if (!is_null($regex)) {
            if (!preg_match($regex, $result)) {
                $this->_failure("Result of '{$cmd}' doesn't match regex '{$regex}': '{$result}'");
            } else {
                $this->_success("Result of '{$cmd}' matches regex '{$regex}'");
            }
        }
        return $this;
    }

}


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

/**
 * @see phpRack_Package
 */
require_once PHPRACK_PATH . '/Package.php';

/**
 * Network-related assertions
 *
 * @package Tests
 */
class phpRack_Package_Network extends phpRack_Package
{
}


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: Simple.php 587 2010-05-17 05:52:02Z yegor256@yahoo.com $
 * @category phpRack
 */

/**
 * @see phpRack_Package
 */
require_once PHPRACK_PATH . '/Package.php';

/**
 * Simple package, for simple assertions
 *
 * @package Tests
 */
class phpRack_Package_Simple extends phpRack_Package
{

    /**
     * Just fail the test
     *
     * @param string Message to show
     * @return $this
     */
    public function fail($msg)
    {
        $this->_failure($msg);
        return $this;
    }

    /**
     * Mark the test as successful
     *
     * @param string Message to show
     * @return $this
     */
    public function success($msg)
    {
        $this->_success($msg);
        return $this;
    }

    /**
     * Is it true?
     *
     * @param mixed Variable to check
     * @return $this
     */
    public function isTrue($var)
    {
        if ($var) {
            $this->_success('Variable is TRUE, success');
        } else {
            $this->_failure('Failed to assert that variable is TRUE');
        }
        return $this;
    }

    /**
     * Is it false?
     *
     * @param mixed Variable to check
     * @return $this
     */
    public function isFalse($var)
    {
        if (!$var) {
            $this->_success('Variable is FALSE, success');
        } else {
            $this->_failure('Failed to assert that variable is FALSE');
        }
        return $this;
    }

}


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

/**
 * @see phpRack_Package
 */
require_once PHPRACK_PATH . '/Package.php';

/**
 * DB related assertions
 *
 * @package Tests
 */
class phpRack_Package_Db extends phpRack_Package
{

}


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

/**
 * @see phpRack_Package
 */
require_once PHPRACK_PATH . '/Package.php';

/**
 * Local HDD related assertions
 *
 * @package Tests
 */
class phpRack_Package_Disc extends phpRack_Package
{

    /**
     * Show directory structure
     *
     * @param string Relative path, in relation to the location of {@link PHPRACK_PATH} file
     * @param array List of options
     * @return $this
     */
    public function showDirectory($dir, array $options = array())
    {
        require_once PHPRACK_PATH . '/Adapters/File.php';
        $dir = phpRack_Adapters_File::factory($dir)->getFileName();

        if (!file_exists($dir)) {
            $this->_failure("Directory '{$dir}' is absent");
            return $this;
        }

        $this->_log("Directory tree '" . realpath($dir) . "':");

        // Create our file iterator
        require_once PHPRACK_PATH . '/Adapters/Files/DirectoryFilterIterator.php';
        $iterator = phpRack_Adapters_Files_DirectoryFilterIterator::factory($dir);
        if (array_key_exists('exclude', $options)) {
            $iterator->setExclude($options['exclude']);
        }

        if (array_key_exists('maxDepth', $options)) {
            $iterator->setMaxDepth($options['maxDepth']);
        }
        $this->_log(
            implode(
                "\n",
                $this->_convertDirectoriesToLines($iterator, $dir)
            )
        );

        return $this;
    }

    /**
     * Convert list of files to lines to show
     *
     * @param Iterator List of files
     * @param string Parent directory name, absolute
     * @return void
     * @see showDirectory()
     */
    protected function _convertDirectoriesToLines(Iterator $iterator, $dir)
    {
        $lines = array();
        foreach ($iterator as $file) {
            $name = substr($file, strlen($dir) + 1);

            $line = str_repeat('  ', substr_count($name, '/')) . $file->getBaseName();
            $attribs = array();

            if ($file->isFile()) {
                $attribs[] = $file->getSize() . ' bytes';
                $attribs[] = date('d-M-y H:i:s', $file->getMTime());
                $attribs[] = sprintf('0x%o', $file->getPerms());
            }

            if ($file->isLink()) {
                $attribs[] = "link to '{$file->getRealPath()}']";
            }

            $lines[] = $line . ($attribs ? ': ' . implode('; ', $attribs) : false);
        }
        return $lines;
    }

}


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: Php.php 605 2010-07-08 05:00:52Z yegor256@yahoo.com $
 * @category phpRack
 */

/**
 * @see phpRack_Package
 */
require_once PHPRACK_PATH . '/Package.php';

/**
 * PHP related assertions
 *
 * @package Tests
 */
class phpRack_Package_Php extends phpRack_Package
{
    /**
     * Format of a megabyte
     *
     * @see http://en.wikipedia.org/wiki/Megabyte
     * @var int
     */
    const SIZE_FORMAT = 1024;

    /**
     * Storage for the ini value
     *
     * @var string
     */
    protected $_iniValue;

    /**
     * Check php.ini param with expected value
     *
     * Good example:
     *
     *
     * class MyTest extends phpRack_Test {
     *   public fuction testPhpIni() {
     *     $this->assert->php->ini('short_open_tag');
     *   }
     * }
     *
     *
     * @param string Name of param to check
     * @param mixed Expected value
     * @return $this
     */
    public function ini($param, $expected = true)
    {
        $this->_iniValue = ini_get($param);
        if ($this->_iniValue != $expected) {
            $this->_failure(
                "php.ini '{$param}' is set to '{$this->_iniValue}', while '{$expected}' expected"
            );
        } else {
            $this->_log("php.ini '{$param}' is set to '{$this->_iniValue}', it's OK");
        }
        return $this;
    }

    /**
     * Check value according required size
     *
     * Example:
     *
     *
     * class MyTest extends phpRack_Test {
     *   public fuction testPhpIniAtleast() {
     *     $this->assert->php->ini('memory_limit')->atLeast('128M');
     *   }
     * }
     *
     *
     * @param string value to check
     * @return $this
     */
    public function atLeast($value)
    {
        // checking digit part
        if (!preg_match('~^\d+(K|M|G)?$~i', $value)) {
            $this->_failure("php.ini value has incorrect numeric format: '{$value}'");
            return $this;
        }

        if ($this->_sizeFormat($value) < $this->_sizeFormat($this->_iniValue)) {
            $this->_success("php.ini value is set to {$this->_iniValue}, {$value} required");
        } else {
            $this->_failure("php.ini value has only {$this->_iniValue}, but {$value} is required");
        }

        // check
        return $this;
    }

    /**
     * Show phpinfo() in proper format
     *
     * @return $this
     */
    public function phpinfo()
    {
        ob_start();
        phpinfo(INFO_ALL);
        $html = ob_get_clean();

        // maybe it's CLI version, not HTML?
        if (strpos($html, '<') !== 0) {
            $this->_log($html);
            return $this;
        }

        // clean HTML out of special symbols
        $html = preg_replace('/&(#\d+|\w+);/', ' ', $html);

        $lines = array();
        $xml = simplexml_load_string($html);
        foreach ($xml->xpath("//tr | //h1 | //h2") as $line) {
            switch (strtolower($line->getName())) {
                case 'tr':
                    $ln = '';
                    foreach ($line->children() as $td) {
                        $ln .= trim(strval($td)) . "\t";
                    }
                    $line = $ln;
                    break;
                case 'h1':
                    $line = "\n\n= {$line} =";
                    break;
                case 'h2':
                    $line = "\n== {$line} ==";
                    break;
            }
            $lines[] = strval($line);
        }
        $this->_log(implode("\n", $lines));

        return $this;
    }

    /**
     * Check files in directory have correct php syntax
     *
     * Possible options are:
     *
     *
     * class MyTest extends phpRack_Test {
     *   public function testCodeValidity() {
     *     $this->assert->php->lint(
     *       '/home/myproject/php', // path to PHP files
     *       array(
     *         'extensions' => 'php,phtml', // comma-separated list of extensions to parse
     *         'exclude' => array('/\.svn/'), // list of RegExps to exclude
     *         'verbose' => true, // show detailed log, with one file per line
     *       )
     *     );
     *   }
     * }
     *
     *
     * @param string Directory path to check
     * @param array List of options
     * @return $this
     */
    public function lint($dir, array $options = array())
    {
        require_once PHPRACK_PATH . '/Adapters/File.php';
        $dir = phpRack_Adapters_File::factory($dir)->getFileName();

        if (!file_exists($dir)) {
            $this->_failure("Directory '{$dir}' does not exist");
            return $this;
        }

        // Create our file iterator
        require_once PHPRACK_PATH . '/Adapters/Files/DirectoryFilterIterator.php';
        $iterator = phpRack_Adapters_Files_DirectoryFilterIterator::factory($dir);

        if (!empty($options['exclude'])) {
            $iterator->setExclude($options['exclude']);
        }

        if (!empty($options['extensions'])) {
            $iterator->setExtensions($options['extensions']);
        }

        $lintCommand = 'php -l';

        $valid = $invalid = 0;
        foreach ($iterator as $file) {
            $file = realpath($file->getPathname());
            $command = $lintCommand . ' ' . escapeshellarg($file) . ' 2>&1';

            /**
             * @see phpRack_Adapters_Shell_Command
             */
            require_once PHPRACK_PATH . '/Adapters/Shell/Command.php';
            $output = phpRack_Adapters_Shell_Command::factory($command)->run();

            if (preg_match('#^No syntax errors detected#', $output)) {
                if (!empty($options['verbose'])) {
                    $this->_success("File '{$file}' is valid");
                }
                $valid++;
            } else {
                $this->_failure("File '{$file}' is NOT valid:");
                $this->_log($output);
                $invalid++;
            }
        }

        // notify phpRack about success in the test
        if (!$invalid) {
            $this->_success("{$valid} files are LINT-valid");
        }
        $this->_log(
            sprintf(
                '%d files LINT-checked, among them: %d valid and %d invalid',
                $valid + $invalid,
                $valid,
                $invalid
            )
        );
        return $this;
    }

    /**
     * Convert string into size
     *
     * @param mixed value to convert
     * @return int
     */
    protected function _sizeFormat($value)
    {
        // set of sizes
        $sizeSet = array(
            'K' => self::SIZE_FORMAT,
            'M' => self::SIZE_FORMAT * self::SIZE_FORMAT,
            'G' => self::SIZE_FORMAT * self::SIZE_FORMAT * self::SIZE_FORMAT,
        );

        // calculation
        $size = $mask = '';
        sscanf($value, '%d%s', $size, $mask);
        if ($mask) {
            $size *= $sizeSet[$mask];
        }
        return $size;
    }
}


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

/**
 * @see phpRack_Package
 */
require_once PHPRACK_PATH . '/Package.php';

/**
 * @see phpRack_Adapters_Db_Mysql
 */
require_once PHPRACK_PATH . '/Adapters/Db/Mysql.php';

/**
 * Db abstract
 *
 * @package Tests
 */
class phpRack_Package_Db_Mysql extends phpRack_Package
{
    /**
     * MySQL adapter
     *
     * @var phpRack_Adapters_Db_Mysql
     * @see __construct()
     */
    private $_adapter;

    /**
     * Construct the class
     *
     * @param phpRack_Result
     * @return void
     * @see phpRack_Package::__construct()
     */
    public function __construct(phpRack_Result $result)
    {
        parent::__construct($result);
        $this->_adapter = new phpRack_Adapters_Db_Mysql();
    }

    /**
     * Check that we can connect to mysql server
     *
     * This method converts connection parameters to JDBC URL, and uses
     * DB adapter in order to establish a real connection with MySQL. We
     * url-encode all parameters, since JDBC URL is just an URL after all.
     *
     * @param string Host
     * @param integer Port
     * @param string User name
     * @param string User password
     * @return $this
     * @see phpRack_Adapters_Db_Mysql
     */
    public function connect($host, $port, $username, $password)
    {
        $jdbcUrl = "jdbc:mysql://{$host}:{$port}"
            . '?username=' . urlencode($username)
            . '&password=' . urlencode($password);

        try {
            $this->_adapter->connect($jdbcUrl);
            $this->_success("Connected successfully to MySQL server '{$host}':'{$port}'");
        } catch(Exception $e) {
            assert($e instanceof Exception); // for ZCA only
            $this->_failure("Can't connect to MySQL server '{$host}':'{$port}', login: '{$username}'");
        }

        return $this;
    }

    /**
     * Check that database exists, and selects this database as current
     *
     * @param string Database name
     * @return $this
     * @see connect()
     * @throws Exception If this method is called before connect()
     */
    public function dbExists($dbName)
    {
        if (!$this->_adapter->isConnected()) {
            throw new Exception('You must call connect() method before');
        }

        try {
            $this->_adapter->query(sprintf("USE `%s`", addcslashes($dbName, '`')));
            $this->_success("Database '{$dbName}' exists");
        } catch (Exception $e) {
            $this->_failure($e->getMessage());
        }

        return $this;
    }

    /**
     * Check that table exists
     *
     * @param string Table name
     * @return $this
     * @see connect()
     * @throws Exception If this method is called before connect()
     * @throws Exception If this method is called before dbExists()
     */
    public function tableExists($tableName)
    {
        if (!$this->_adapter->isConnected()) {
            throw new Exception('You must call connect() method before');
        }

        if (!$this->_adapter->isDatabaseSelected()) {
            throw new Exception('You must call dbExists() method before');
        }

        $response = $this->_adapter->query(sprintf("SHOW TABLES LIKE '%s'", addslashes($tableName)));
        if ($response == '') {
            $this->_failure("Table '{$tableName}' doesn't exist");
        } else {
            $this->_success("Table '{$tableName}' exists");
        }

        return $this;
    }

    /**
     * Execute query and return results
     *
     * @param string Query to execute
     * @return $this
     * @see connect()
     * @throws Exception If this method is called before connect()
     */
    public function query($query)
    {
        if (!$this->_adapter->isConnected()) {
            throw new Exception('You must call connect() method before');
        }

        try {
            $result = $this->_adapter->query($query);
            $this->_log($result);
        } catch (Exception $e) {
            $this->_failure($e->getMessage());
        }

        return $this;
    }

    /**
     * Show database schema
     *
     * @return $this
     * @throws Exception If this method is called before connect()
     * @throws Exception If this method is called before dbExists()
     * @throws Exception If something wrong happen during getting database schema
     */
    public function showSchema()
    {
        if (!$this->_adapter->isConnected()) {
            throw new Exception('You must call connect() method before');
        }

        if (!$this->_adapter->isDatabaseSelected()) {
            throw new Exception('You must call dbExists() method before');
        }

        $result = $this->_adapter->showSchema();
        $this->_log($result);

        return $this;
    }

    /**
     * Show connections and their status
     *
     * @return $this
     * @throws Exception If this method is called before connect()
     */
    public function showConnections()
    {
        if (!$this->_adapter->isConnected()) {
            throw new Exception('You must call connect() method before');
        }

        $result = $this->_adapter->showConnections();
        if ($result === false) {
            $this->_failure('MySQL user does not have GRANT PROCESS|ALL permissions');
        }

        $this->_log($result);
        return $this;
    }

    /**
     * Show server info
     *
     * @return $this
     * @throws Exception If this method is called before connect()
     */
    public function showServerInfo()
    {
        if (!$this->_adapter->isConnected()) {
            throw new Exception('You must call connect() method before');
        }

        $this->_log($this->_adapter->showServerInfo());
        return $this;
    }

    /**
     * Close connection to db
     *
     * @return void
     */
    public function closeConnection()
    {
        $this->_adapter->closeConnection();
    }
}


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
 */

/**
 * @see phpRack_Package
 */
require_once PHPRACK_PATH . '/Package.php';

/**
 * @see phpRack_Adapters_Url
 */
require_once PHPRACK_PATH . '/Adapters/Url.php';

/**
 * Network check using Url
 *
 * @package Tests
 */
class phpRack_Package_Network_Url extends phpRack_Package
{
    /**
     * Adapter used for cummunication with server
     *
     * @var phpRack_Adapters_Url
     * @see url()
     * @see regexp()
     */
    private $_adapter;

    /**
     * Contain url passed to url function, used in other methods of this class
     *
     * @var string
     * @see url()
     * @see regex()
     */
    private $_url;

    /**
     * Set URL and validate it
     *
     * @param string URL
     * @param array Options which will affect connection
     * @return $this
     * @throws Exception if URL is invalid
     */
    public function url($url, $options = array())
    {
        $this->_adapter = phpRack_Adapters_Url::factory($url, $options);
        $this->_url = $url;
        return $this;
    }

    /**
     * Make HTTP call and check that pattern exists in result
     *
     * @param string Pattern to check
     * @return $this
     * @see url()
     * @throws Exception If this method is called before url()
     * @throws Exception If can't connect
     */
    public function regex($pattern)
    {
        if (empty($this->_url)) {
            throw new Exception('url() function must be called before');
        }

        $content = $this->_adapter->getContent();

        $found = @preg_match($pattern, $content);

        // If regexp pattern is invalid, try to use it as string pattern
        if ($found === false) {
            $this->_log('Regex is not valid, try to use it as string');
            $found = (strpos($content, $pattern) !== false);
        }

        // If pattern was found in content
        if ($found) {
            $this->_success("Pattern '{$pattern}' was found on '{$this->_url}'");
        } else {
            $this->_failure("Pattern '{$pattern}' was NOT found on '{$this->_url}'");
        }

        return $this;
    }
}


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

/**
 * @see phpRack_Package
 */
require_once PHPRACK_PATH . '/Package.php';

/**
 * @see phpRack_Adapters_Url
 */
require_once PHPRACK_PATH . '/Adapters/Url.php';

/**
 * Ports on the server
 *
 * @package Tests
 */
class phpRack_Package_Network_Ports extends phpRack_Package
{

    /**
     * This port is open on this machine as INPUT port?
     *
     * @param integer Port number to check
     * @param string IP address of the server to check
     * @return $this
     */
    public function isOpen($port, $server = '127.0.0.1')
    {
        $urlAdapter = phpRack_Adapters_Url::factory("{$server}:{$port}");

        if ($urlAdapter->isAccessible()) {
            $this->_success("Port '{$port}' is open at '{$server}', it's OK");
        } else {
            $this->_failure("Port '{$port}' is NOT open at '{$server}'");
        }

        return $this;
    }

}


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

/**
 * @see phpRack_Package
 */
require_once PHPRACK_PATH . '/Package.php';

/**
 * PHP-version related assertions
 *
 * @package Tests
 */
class phpRack_Package_Php_Version extends phpRack_Package
{

    /**
     * Current version is newer than given one?
     *
     * @param string Version name
     * @return $this
     * @see http://www.php.net/manual/en/function.version-compare.php
     */
    public function atLeast($version)
    {
        if (version_compare(phpversion(), $version) >= 0) {
            $this->_success('PHP version is ' . phpversion() . ", newer or equal to {$version}");
        } else {
            $this->_failure('PHP version is ' . phpversion() . ", older than {$version}");
        }
        return $this;
    }

}


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

/**
 * @see phpRack_Package
 */
require_once PHPRACK_PATH . '/Package.php';

/**
 * PHP related assertions
 *
 * @package Tests
 */
class phpRack_Package_Php_Extensions extends phpRack_Package
{

    /**
     * Show full list of loaded extensions
     *
     * @return $this
     */
    public function showAll()
    {
        $list = get_loaded_extensions();
        $this->_log('PHP extensions loaded: ' . implode(', ', $list));
        return $this;
    }

    /**
     * Given extension is loaded?
     *
     * @param string Name of the extension to check
     * @return $this
     */
    public function isLoaded($name)
    {
        if (extension_loaded($name)) {
            $this->_success("PHP extension '{$name}' is loaded");
        } else {
            $this->_failure("PHP extension '{$name}' is NOT loaded: extension_loaded('{$name}') returned FALSE");
        }

        return $this;
    }

}


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_Package
 */
require_once PHPRACK_PATH . '/Package.php';

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

/**
 * PEAR package used for checking PEAR packages availability
 *
 * @package Tests
 */
class phpRack_Package_Php_Pear extends phpRack_Package
{

    /**
     * Pear adapter
     *
     * @var phpRack_Adapters_Pear
     * @see __construct()
     */
    private $_pear;

    /**
     * Pear package
     *
     * @var phpRack_Adapters_Pear
     * @see package()
     */
    private $_package;

    /**
     * Construct the class
     *
     * @param phpRack_Result
     * @return void
     * @see phpRack_Package::__construct()
     */
    public function __construct(phpRack_Result $result)
    {
        parent::__construct($result);
        $this->_pear = new phpRack_Adapters_Pear();
    }

    /**
     * Check whether PEAR package exists
     *
     * @param string Package name to check
     * @return $this
     * @see PearTest::testPearPackages()
     */
    public function package($name)
    {
        try {
            $this->_package = $this->_pear->getPackage($name);
            if (is_null($this->_package)) {
                $this->_failure("PEAR '{$name}' package does NOT exist");
            } else {
                $this->_success("PEAR '{$name}' package exists, ver.{$this->_package->getVersion()}");
            }
        } catch (Exception $e) {
            $this->_failure("PEAR problem: {$e->getMessage()}");
        }
        return $this;
    }

    /**
     * Check that least this version of PEAR package is present
     *
     * @param string Version number, required
     * @return $this
     * @see PearTest::testPearPackages()
     */
    public function atLeast($requiredVersion)
    {
        if (is_null($this->_package)) {
            $this->_failure("PEAR package is absent, can't compare versions");
            return $this;
        }

        $currentVersion = $this->_package->getVersion();

        if (version_compare($currentVersion, $requiredVersion, '>=')) {
            $this->_success("PEAR '{$this->_package->getName()}' package version is '{$currentVersion}'");
        } else {
            $this->_failure(
                "PEAR '{$this->_package->getName()}' package version is '{$currentVersion}'"
                . ", but '{$requiredVersion}' is required"
            );
        }
        return $this;
    }

    /**
     * Show full list of installed packages
     *
     * @return $this
     * @see PearTest::testShowPearPackages()
     */
    public function showList()
    {
        try {
            $packages = $this->_pear->getAllPackages();

            $this->_log("Installed PEAR packages:");
            foreach ($packages as $package) {
                $this->_log($package->getRawInfo());
            }
        } catch (Exception $e) {
            $this->_failure("PEAR problem: {$e->getMessage()}");
        }
        return $this;
    }

}


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: Extensions.php 25 2010-02-20 09:30:13Z yegor256@yahoo.com $
 * @category phpRack
 */

/**
 * @see phpRack_Package
 */
require_once PHPRACK_PATH . '/Package.php';

/**
 * fileinfo to validate
 *
 * @package Tests
 */
class phpRack_Package_Php_Extensions_Fileinfo extends phpRack_Package
{

    /**
     * Extension is properly configured?
     *
     * @return $this
     */
    public function isAlive()
    {
        if (!extension_loaded('fileinfo')) {
            $this->_failure("Extension 'fileinfo' is NOT loaded, we can't validate it any further");
            return $this;
        }

        $magic = '/usr/share/misc/magic';
        $finfo = new finfo(FILEINFO_MIME, $magic);
        if (!$finfo) {
            $this->_failure("finfo() failed to load magic: '{$magic}'");
            return $this;
        }

        $type = @$finfo->file(__FILE__);
        if (strpos($type, 'text/') !== 0) {
            $this->_failure("finfo() failed to detect PHP file type, returned: '{$type}'");
            return $this;
        }

        $this->_success("Extension 'fileinfo' is configured properly");
        return $this;
    }

}


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

/**
 * @see phpRack_Package
 */
require_once PHPRACK_PATH . '/Package.php';

/**
 * CPU Performance check
 *
 * @package Tests
 */
class phpRack_Package_Cpu_Performance extends phpRack_Package
{
    /**
     * Check whether server CPU has least this BogoMips
     *
     * @param float required BogoMips
     * @return $this
     * @see PerformanceTest::testServerIsFast()
     */
    public function atLeast($bogoMips)
    {
        /**
         * @see phpRack_Adapters_Cpu
         */
        require_once PHPRACK_PATH . '/Adapters/Cpu.php';

        try {
            $cpu = phpRack_Adapters_Cpu::factory();
            $currentBogoMips = $cpu->getBogoMips();
            if ($currentBogoMips >= $bogoMips) {
                $this->_success("CPU is fast enough with '{$currentBogoMips}' BogoMips");
            } else {
                $this->_failure(
                    "CPU is too slow. " .
                    "It has only '{$currentBogoMips}' BogoMips, but '{$bogoMips}' is required"
                );
            }
        } catch (Exception $e) {
            $this->_failure("CPU problem: {$e->getMessage()}");
        }
        return $this;
    }
}