You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@shindig.apache.org by ch...@apache.org on 2008/08/02 16:11:44 UTC
svn commit: r681982 [22/27] - in /incubator/shindig/trunk/php: external/
external/PHPUnit/ external/PHPUnit/Extensions/
external/PHPUnit/Extensions/Database/
external/PHPUnit/Extensions/Database/Constraint/
external/PHPUnit/Extensions/Database/DB/ exte...
Added: incubator/shindig/trunk/php/external/PHPUnit/Util/Metrics/Project.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/external/PHPUnit/Util/Metrics/Project.php?rev=681982&view=auto
==============================================================================
--- incubator/shindig/trunk/php/external/PHPUnit/Util/Metrics/Project.php (added)
+++ incubator/shindig/trunk/php/external/PHPUnit/Util/Metrics/Project.php Sat Aug 2 07:11:35 2008
@@ -0,0 +1,485 @@
+<?php
+/**
+ * PHPUnit
+ *
+ * Copyright (c) 2002-2008, Sebastian Bergmann <sb...@sebastian-bergmann.de>.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * * Neither the name of Sebastian Bergmann nor the names of his
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * 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.
+ *
+ * @category Testing
+ * @package PHPUnit
+ * @author Sebastian Bergmann <sb...@sebastian-bergmann.de>
+ * @copyright 2002-2008 Sebastian Bergmann <sb...@sebastian-bergmann.de>
+ * @license http://www.opensource.org/licenses/bsd-license.php BSD License
+ * @version SVN: $Id: Project.php 1985 2007-12-26 18:11:55Z sb $
+ * @link http://www.phpunit.de/
+ * @since File available since Release 3.2.0
+ */
+
+@include_once 'Image/GraphViz.php';
+
+require_once 'PHPUnit/Util/Filter.php';
+require_once 'PHPUnit/Util/Metrics.php';
+
+PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT');
+
+/**
+ * Project-Level Metrics.
+ *
+ * @category Testing
+ * @package PHPUnit
+ * @author Sebastian Bergmann <sb...@sebastian-bergmann.de>
+ * @copyright 2002-2008 Sebastian Bergmann <sb...@sebastian-bergmann.de>
+ * @license http://www.opensource.org/licenses/bsd-license.php BSD License
+ * @version Release: 3.2.9
+ * @link http://www.phpunit.de/
+ * @since Class available since Release 3.2.0
+ */
+class PHPUnit_Util_Metrics_Project extends PHPUnit_Util_Metrics
+{
+ protected static $CPD_IGNORE_LIST = array(
+ T_INLINE_HTML,
+ T_COMMENT,
+ T_DOC_COMMENT,
+ T_OPEN_TAG,
+ T_OPEN_TAG_WITH_ECHO,
+ T_CLOSE_TAG,
+ T_WHITESPACE
+ );
+
+ protected $classes = array();
+ protected $files = array();
+ protected $functions = array();
+
+ protected $cls = 0;
+ protected $clsa = 0;
+ protected $clsc = 0;
+ protected $interfs = 0;
+ protected $roots = 0;
+ protected $leafs = 0;
+ protected $maxDit = 0;
+
+ protected $cpdDuplicates = array();
+ protected $cpdHashes = array();
+ protected $dependencies = array();
+
+ /**
+ * Constructor.
+ *
+ * @param array $files
+ * @param array $codeCoverage
+ * @param boolean $cpd
+ * @param integer $cpdMinLines
+ * @param integer $cpdMinMatches
+ * @access public
+ */
+ public function __construct(Array $files, &$codeCoverage = array(), $cpd = FALSE, $cpdMinLines = 5, $cpdMinMatches = 70)
+ {
+ foreach ($files as $file) {
+ if (file_exists($file)) {
+ $this->files[$file] = PHPUnit_Util_Metrics_File::factory(
+ $file, $codeCoverage
+ );
+
+ foreach ($this->files[$file]->getFunctions() as $function) {
+ $this->functions[$function->getFunction()->getName()] = $function;
+ }
+
+ foreach ($this->files[$file]->getClasses() as $class) {
+ $className = $class->getClass()->getName();
+ $package = $class->getPackage();
+
+ $this->classes[$className] = $class;
+
+ if ($class->getClass()->isInterface()) {
+ $this->interfs++;
+ } else {
+ if ($class->getClass()->isAbstract()) {
+ $this->clsa++;
+ } else {
+ $this->clsc++;
+ }
+
+ $this->cls++;
+ }
+ }
+ }
+ }
+
+ $numClasses = count($this->classes);
+
+ foreach ($this->classes as $a => $b) {
+ foreach ($this->classes as $c => $d) {
+ $this->dependencies[$a][$c] = 0;
+ }
+ }
+
+ foreach ($this->classes as $className => $class) {
+ foreach ($class->getDependencies() as $dependency) {
+ $this->dependencies[$className][$dependency] = 1;
+ }
+
+ $class->setProject($this);
+
+ if ($class->getNOC() == 0) {
+ $this->leafs++;
+ }
+
+ else if ($class->getClass()->getParentClass() === FALSE) {
+ $this->roots++;
+ }
+
+ $this->maxDit = max($this->maxDit, $class->getDit());
+ }
+
+ if ($cpd) {
+ $this->copyPasteDetection($cpdMinLines, $cpdMinMatches);
+ }
+ }
+
+ /**
+ * Returns the classes of this project.
+ *
+ * @return array
+ * @access public
+ */
+ public function getClasses()
+ {
+ return $this->classes;
+ }
+
+ /**
+ * A class.
+ *
+ * @param string $className
+ * @return ReflectionClass
+ * @access public
+ */
+ public function getClass($className)
+ {
+ return $this->classes[$className];
+ }
+
+ /**
+ * Returns the dependencies between the classes of this project.
+ *
+ * @return array
+ * @access public
+ */
+ public function getDependencies()
+ {
+ return $this->dependencies;
+ }
+
+ /**
+ * Returns the dependencies between the classes of this project
+ * as GraphViz/DOT markup.
+ *
+ * @return Image_GraphViz
+ * @access public
+ * @since Method available since Release 3.2.2
+ */
+ public function getDependenciesAsDOT()
+ {
+ if (class_exists('Image_GraphViz', FALSE)) {
+ $graph = new Image_GraphViz(
+ TRUE,
+ array(
+ 'overlap' => 'scale',
+ 'splines' => 'true',
+ 'sep' => '.1',
+ 'fontsize' => '8'
+ )
+ );
+
+ foreach (array_keys($this->dependencies) as $className) {
+ $graph->addNode($className);
+ }
+
+ foreach ($this->dependencies as $from => $dependencies) {
+ foreach ($dependencies as $to => $flag) {
+ if ($flag === 1) {
+ $graph->addEdge(array($from => $to));
+ }
+ }
+ }
+
+ return $graph;
+ } else {
+ throw new RuntimeException;
+ }
+ }
+
+ /**
+ * Returns the duplicates found by the Copy & Paste Detection (CPD).
+ *
+ * @return array
+ * @access public
+ */
+ public function getDuplicates()
+ {
+ return $this->cpdDuplicates;
+ }
+
+ /**
+ * Returns the files of this project.
+ *
+ * @return array
+ * @access public
+ */
+ public function getFiles()
+ {
+ return $this->files;
+ }
+
+ /**
+ * A file.
+ *
+ * @param string $className
+ * @return ReflectionClass
+ * @access public
+ */
+ public function getFile($filename)
+ {
+ return $this->files[$filename];
+ }
+
+ /**
+ * Functions.
+ *
+ * @return array
+ * @access public
+ */
+ public function getFunctions()
+ {
+ return $this->functions;
+ }
+
+ /**
+ * A function.
+ *
+ * @param string $functionName
+ * @return ReflectionClass
+ * @access public
+ */
+ public function getFunction($functionName)
+ {
+ return $this->functions[$functionName];
+ }
+
+ /**
+ * Returns the Number of Classes (CLS) for the project.
+ *
+ * @return integer
+ * @access public
+ * @see http://www.aivosto.com/project/help/pm-oo-misc.html
+ */
+ public function getCLS()
+ {
+ return $this->cls;
+ }
+
+ /**
+ * Returns the Number of Abstract Classes (CLSa) for the project.
+ *
+ * @return integer
+ * @access public
+ * @see http://www.aivosto.com/project/help/pm-oo-misc.html
+ */
+ public function getCLSa()
+ {
+ return $this->clsa;
+ }
+
+ /**
+ * Returns the Number of Concrete Classes (CLSc) for the project.
+ *
+ * @return integer
+ * @access public
+ * @see http://www.aivosto.com/project/help/pm-oo-misc.html
+ */
+ public function getCLSc()
+ {
+ return $this->clsc;
+ }
+
+ /**
+ * Returns the Number of Root Classes (ROOTS) for the project.
+ *
+ * @return integer
+ * @access public
+ * @see http://www.aivosto.com/project/help/pm-oo-misc.html
+ */
+ public function getRoots()
+ {
+ return $this->roots;
+ }
+
+ /**
+ * Returns the Number of Leaf Classes (LEAFS) for the project.
+ *
+ * @return integer
+ * @access public
+ * @see http://www.aivosto.com/project/help/pm-oo-misc.html
+ */
+ public function getLeafs()
+ {
+ return $this->leafs;
+ }
+
+ /**
+ * Returns the Number of Interfaces (INTERFS) for the project.
+ *
+ * @return integer
+ * @access public
+ * @see http://www.aivosto.com/project/help/pm-oo-misc.html
+ */
+ public function getInterfs()
+ {
+ return $this->interfs;
+ }
+
+ /**
+ * Returns the Maximum Depth of Intheritance Tree (maxDIT) for the project.
+ *
+ * @return integer
+ * @access public
+ * @see http://www.aivosto.com/project/help/pm-oo-misc.html
+ */
+ public function getMaxDit()
+ {
+ return $this->maxDit;
+ }
+
+ /**
+ * Copy & Paste Detection (CPD).
+ *
+ * @param integer $minLines
+ * @param integer $minMatches
+ * @access protected
+ * @author Johann-Peter Hartmann <jo...@mayflower.de>
+ */
+ protected function copyPasteDetection($minLines, $minMatches)
+ {
+ foreach ($this->files as $file) {
+ $currentTokenPositions = array();
+ $currentSignature = '';
+ $lines = $file->getLines();
+ $tokens = $file->getTokens();
+ $tokenNr = 0;
+ $line = 1;
+
+ foreach (array_keys($tokens) as $key) {
+ $token = $tokens[$key];
+
+ if (is_string($token)) {
+ $line += substr_count($token, "\n");
+ } else {
+ if (!in_array($token[0], self::$CPD_IGNORE_LIST)) {
+ $currentTokenPositions[$tokenNr++] = $line;
+ $currentSignature .= chr($token[0] & 255) . pack('N*', crc32($token[1]));
+ }
+
+ $line += substr_count($token[1], "\n");
+ }
+ }
+
+ $tokenNr = 0;
+ $firstLine = 0;
+ $found = FALSE;
+
+ if (count($currentTokenPositions) > 0) {
+ do {
+ $line = $currentTokenPositions[$tokenNr];
+
+ $hash = substr(
+ md5(
+ substr(
+ $currentSignature, $tokenNr * 5,
+ $minMatches * 5
+ ),
+ TRUE
+ ),
+ 0,
+ 8
+ );
+
+ if (isset($this->cpdHashes[$hash])) {
+ $found = TRUE;
+
+ if ($firstLine === 0) {
+ $firstLine = $line;
+ $firstHash = $hash;
+ $firstToken = $tokenNr;
+ }
+ } else {
+ if ($found) {
+ if ($line + 1 - $firstLine > $minLines) {
+ $this->cpdDuplicates[] = array(
+ 'fileA' => $this->cpdHashes[$firstHash][0],
+ 'firstLineA' => $this->cpdHashes[$firstHash][1],
+ 'fileB' => $file,
+ 'firstLineB' => $firstLine,
+ 'numLines' => $line + 1 - $firstLine,
+ 'numTokens' => $tokenNr + 1 - $firstToken
+ );
+ }
+
+ $found = FALSE;
+ $firstLine = 0;
+ }
+
+ $this->cpdHashes[$hash] = array($file, $line);
+ }
+
+ $tokenNr++;
+ } while ($tokenNr <= (count($currentTokenPositions) -
+ $minMatches )+1);
+ }
+
+ if ($found) {
+ if ($line + 1 - $firstLine > $minLines) {
+ $this->cpdDuplicates[] = array(
+ 'fileA' => $this->cpdHashes[$firstHash][0],
+ 'firstLineA' => $this->cpdHashes[$firstHash][1],
+ 'fileB' => $file,
+ 'firstLineB' => $firstLine,
+ 'numLines' => $line + 1 - $firstLine,
+ 'numTokens' => $tokenNr + 1 - $firstToken
+ );
+ }
+
+ $found = FALSE;
+ }
+ }
+ }
+}
+?>
Added: incubator/shindig/trunk/php/external/PHPUnit/Util/PDO.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/external/PHPUnit/Util/PDO.php?rev=681982&view=auto
==============================================================================
--- incubator/shindig/trunk/php/external/PHPUnit/Util/PDO.php (added)
+++ incubator/shindig/trunk/php/external/PHPUnit/Util/PDO.php Sat Aug 2 07:11:35 2008
@@ -0,0 +1,357 @@
+<?php
+/**
+ * PHPUnit
+ *
+ * Copyright (c) 2002-2008, Sebastian Bergmann <sb...@sebastian-bergmann.de>.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * * Neither the name of Sebastian Bergmann nor the names of his
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * 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.
+ *
+ * @category Testing
+ * @package PHPUnit
+ * @author Sebastian Bergmann <sb...@sebastian-bergmann.de>
+ * @copyright 2002-2008 Sebastian Bergmann <sb...@sebastian-bergmann.de>
+ * @license http://www.opensource.org/licenses/bsd-license.php BSD License
+ * @version SVN: $Id: PDO.php 1985 2007-12-26 18:11:55Z sb $
+ * @link http://www.phpunit.de/
+ * @since File available since Release 3.1.4
+ */
+
+require_once 'PHPUnit/Util/Filter.php';
+
+PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT');
+
+/**
+ * PDO helpers.
+ *
+ * @category Testing
+ * @package PHPUnit
+ * @author Sebastian Bergmann <sb...@sebastian-bergmann.de>
+ * @copyright 2002-2008 Sebastian Bergmann <sb...@sebastian-bergmann.de>
+ * @license http://www.opensource.org/licenses/bsd-license.php BSD License
+ * @version Release: 3.2.9
+ * @link http://www.phpunit.de/
+ * @since Class available since Release 3.1.4
+ */
+class PHPUnit_Util_PDO
+{
+ public static function factory($dsn)
+ {
+ $parsed = self::parseDSN($dsn);
+
+ switch ($parsed['phptype']) {
+ case 'mysql': {
+ $database = null;
+ $charset = null;
+ $host = null;
+ $port = null;
+ $socket = null;
+ $user = null;
+ $pass = null;
+ $driverOptions = null;
+
+ foreach ( $parsed as $key => $val )
+ {
+ switch ( $key )
+ {
+ case 'database':
+ case 'dbname':
+ $database = $val;
+ break;
+
+ case 'charset':
+ $charset = $val;
+ break;
+
+ case 'host':
+ case 'hostspec':
+ $host = $val;
+ break;
+
+ case 'port':
+ $port = $val;
+ break;
+
+ case 'socket':
+ $socket = $val;
+ break;
+
+ case 'user':
+ case 'username':
+ $user = $val;
+ break;
+
+ case 'pass':
+ case 'password':
+ $pass = $val;
+ break;
+
+ case 'driver-opts':
+ $driverOptions = $val;
+ break;
+ }
+ }
+
+ if ( !isset( $database ) )
+ {
+ throw new InvalidArgumentException;
+ }
+
+ $dsn = "mysql:dbname=$database";
+
+ if ( isset( $host ) && $host )
+ {
+ $dsn .= ";host=$host";
+ }
+
+ if ( isset( $port ) && $port )
+ {
+ $dsn .= ";port=$port";
+ }
+
+ if ( isset( $charset ) && $charset )
+ {
+ $dsn .= ";charset=$charset";
+ }
+
+ if ( isset( $socket ) && $socket )
+ {
+ $dsn .= ";unix_socket=$socket";
+ }
+
+ $dbh = new PDO($dsn, $user, $pass, $driverOptions);
+ }
+ break;
+
+ case 'sqlite': {
+ $dbh = new PDO($dsn);
+ }
+ break;
+
+ default: {
+ throw new InvalidArgumentException;
+ }
+ }
+
+ $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+
+ return $dbh;
+ }
+
+ /**
+ * Returns the Data Source Name as a structure containing the various parts of the DSN.
+ *
+ * Additional keys can be added by appending a URI query string to the
+ * end of the DSN.
+ *
+ * The format of the supplied DSN is in its fullest form:
+ * <code>
+ * phptype(dbsyntax)://username:password@protocol+hostspec/database?option=8&another=true
+ * </code>
+ *
+ * Most variations are allowed:
+ * <code>
+ * phptype://username:password@protocol+hostspec:110//usr/db_file.db?mode=0644
+ * phptype://username:password@hostspec/database_name
+ * phptype://username:password@hostspec
+ * phptype://username@hostspec
+ * phptype://hostspec/database
+ * phptype://hostspec
+ * phptype(dbsyntax)
+ * phptype
+ * </code>
+ *
+ * This function is 'borrowed' from PEAR /DB.php .
+ *
+ * @param string $dsn Data Source Name to be parsed
+ *
+ * @return array an associative array with the following keys:
+ * + phptype: Database backend used in PHP (mysql, odbc etc.)
+ * + dbsyntax: Database used with regards to SQL syntax etc.
+ * + protocol: Communication protocol to use (tcp, unix etc.)
+ * + hostspec: Host specification (hostname[:port])
+ * + database: Database to use on the DBMS server
+ * + username: User name for login
+ * + password: Password for login
+ */
+ public static function parseDSN( $dsn )
+ {
+ $parsed = array(
+ 'phptype' => false,
+ 'dbsyntax' => false,
+ 'username' => false,
+ 'password' => false,
+ 'protocol' => false,
+ 'hostspec' => false,
+ 'port' => false,
+ 'socket' => false,
+ 'database' => false,
+ );
+
+ if ( is_array( $dsn ) )
+ {
+ $dsn = array_merge( $parsed, $dsn );
+ if ( !$dsn['dbsyntax'] )
+ {
+ $dsn['dbsyntax'] = $dsn['phptype'];
+ }
+ return $dsn;
+ }
+
+ // Find phptype and dbsyntax
+ if ( ( $pos = strpos( $dsn, '://' ) ) !== false )
+ {
+ $str = substr( $dsn, 0, $pos );
+ $dsn = substr( $dsn, $pos + 3 );
+ }
+ else
+ {
+ $str = $dsn;
+ $dsn = null;
+ }
+
+ // Get phptype and dbsyntax
+ // $str => phptype(dbsyntax)
+ if ( preg_match( '|^(.+?)\((.*?)\)$|', $str, $arr ) )
+ {
+ $parsed['phptype'] = $arr[1];
+ $parsed['dbsyntax'] = !$arr[2] ? $arr[1] : $arr[2];
+ }
+ else
+ {
+ $parsed['phptype'] = $str;
+ $parsed['dbsyntax'] = $str;
+ }
+
+ if ( !count( $dsn ) )
+ {
+ return $parsed;
+ }
+
+ // Get (if found): username and password
+ // $dsn => username:password@protocol+hostspec/database
+ if ( ( $at = strrpos( (string) $dsn, '@' ) ) !== false )
+ {
+ $str = substr( $dsn, 0, $at );
+ $dsn = substr( $dsn, $at + 1 );
+ if ( ( $pos = strpos( $str, ':' ) ) !== false )
+ {
+ $parsed['username'] = rawurldecode( substr( $str, 0, $pos ) );
+ $parsed['password'] = rawurldecode( substr( $str, $pos + 1 ) );
+ }
+ else
+ {
+ $parsed['username'] = rawurldecode( $str );
+ }
+ }
+
+ // Find protocol and hostspec
+
+ if ( preg_match( '|^([^(]+)\((.*?)\)/?(.*?)$|', $dsn, $match ) )
+ {
+ // $dsn => proto(proto_opts)/database
+ $proto = $match[1];
+ $proto_opts = $match[2] ? $match[2] : false;
+ $dsn = $match[3];
+ }
+ else
+ {
+ // $dsn => protocol+hostspec/database (old format)
+ if ( strpos( $dsn, '+' ) !== false )
+ {
+ list( $proto, $dsn ) = explode( '+', $dsn, 2 );
+ }
+ if ( strpos( $dsn, '/' ) !== false )
+ {
+ list( $proto_opts, $dsn ) = explode( '/', $dsn, 2 );
+ }
+ else
+ {
+ $proto_opts = $dsn;
+ $dsn = null;
+ }
+ }
+
+ // process the different protocol options
+ $parsed['protocol'] = ( !empty( $proto ) ) ? $proto : 'tcp';
+ $proto_opts = rawurldecode( $proto_opts );
+ if ( $parsed['protocol'] == 'tcp' )
+ {
+ if ( strpos( $proto_opts, ':' ) !== false )
+ {
+ list( $parsed['hostspec'], $parsed['port'] ) = explode( ':', $proto_opts );
+ }
+ else
+ {
+ $parsed['hostspec'] = $proto_opts;
+ }
+ }
+ elseif ( $parsed['protocol'] == 'unix' )
+ {
+ $parsed['socket'] = $proto_opts;
+ }
+
+ // Get dabase if any
+ // $dsn => database
+ if ( $dsn )
+ {
+ if ( ( $pos = strpos( $dsn, '?' ) ) === false )
+ {
+ // /database
+ $parsed['database'] = rawurldecode( $dsn );
+ }
+ else
+ {
+ // /database?param1=value1¶m2=value2
+ $parsed['database'] = rawurldecode( substr( $dsn, 0, $pos ) );
+ $dsn = substr( $dsn, $pos + 1 );
+ if ( strpos( $dsn, '&') !== false )
+ {
+ $opts = explode( '&', $dsn );
+ }
+ else
+ { // database?param1=value1
+ $opts = array( $dsn );
+ }
+ foreach ( $opts as $opt )
+ {
+ list( $key, $value ) = explode( '=', $opt );
+ if ( !isset( $parsed[$key] ) )
+ {
+ // don't allow params overwrite
+ $parsed[$key] = rawurldecode( $value );
+ }
+ }
+ }
+ }
+ return $parsed;
+ }
+}
+?>
Added: incubator/shindig/trunk/php/external/PHPUnit/Util/Printer.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/external/PHPUnit/Util/Printer.php?rev=681982&view=auto
==============================================================================
--- incubator/shindig/trunk/php/external/PHPUnit/Util/Printer.php (added)
+++ incubator/shindig/trunk/php/external/PHPUnit/Util/Printer.php Sat Aug 2 07:11:35 2008
@@ -0,0 +1,149 @@
+<?php
+/**
+ * PHPUnit
+ *
+ * Copyright (c) 2002-2008, Sebastian Bergmann <sb...@sebastian-bergmann.de>.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * * Neither the name of Sebastian Bergmann nor the names of his
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * 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.
+ *
+ * @category Testing
+ * @package PHPUnit
+ * @author Sebastian Bergmann <sb...@sebastian-bergmann.de>
+ * @copyright 2002-2008 Sebastian Bergmann <sb...@sebastian-bergmann.de>
+ * @license http://www.opensource.org/licenses/bsd-license.php BSD License
+ * @version SVN: $Id: Printer.php 2141 2008-01-17 10:49:39Z sb $
+ * @link http://www.phpunit.de/
+ * @since File available since Release 2.0.0
+ */
+
+require_once 'PHPUnit/Util/Filter.php';
+
+PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT');
+
+/**
+ * Utility class that can print to STDOUT or write to a file.
+ *
+ * @category Testing
+ * @package PHPUnit
+ * @author Sebastian Bergmann <sb...@sebastian-bergmann.de>
+ * @copyright 2002-2008 Sebastian Bergmann <sb...@sebastian-bergmann.de>
+ * @license http://www.opensource.org/licenses/bsd-license.php BSD License
+ * @version Release: 3.2.9
+ * @link http://www.phpunit.de/
+ * @since Class available since Release 2.0.0
+ * @abstract
+ */
+abstract class PHPUnit_Util_Printer
+{
+ /**
+ * @var resource
+ * @access protected
+ */
+ protected $out;
+
+ /**
+ * @var string
+ * @access protected
+ */
+ protected $outTarget;
+
+ /**
+ * @var boolean
+ * @access protected
+ */
+ protected $printsHTML = FALSE;
+
+ /**
+ * Constructor.
+ *
+ * @param mixed $out
+ * @throws InvalidArgumentException
+ * @access public
+ */
+ public function __construct($out = NULL)
+ {
+ if ($out !== NULL) {
+ if (is_string($out)) {
+ if (strpos($out, 'socket://') === 0) {
+ $out = explode(':', str_replace('socket://', '', $out));
+
+ if (sizeof($out) != 2) {
+ throw new InvalidArgumentException;
+ }
+
+ $this->out = fsockopen($out[0], $out[1]);
+ } else {
+ $this->out = fopen($out, 'wt');
+ }
+
+ $this->outTarget = $out;
+ } else {
+ $this->out = $out;
+ }
+ }
+ }
+
+ /**
+ * Flush buffer, optionally tidy up HTML, and close output.
+ *
+ * @access public
+ */
+ public function flush()
+ {
+ if ($this->out !== NULL) {
+ fclose($this->out);
+ }
+
+ if ($this->printsHTML === TRUE && $this->outTarget !== NULL && extension_loaded('tidy')) {
+ file_put_contents(
+ $this->outTarget, tidy_repair_file($this->outTarget)
+ );
+ }
+ }
+
+ /**
+ * @param string $buffer
+ * @access public
+ */
+ public function write($buffer)
+ {
+ if ($this->out !== NULL) {
+ fwrite($this->out, $buffer);
+ } else {
+ if (php_sapi_name() != 'cli') {
+ $buffer = htmlentities($buffer);
+ }
+
+ print $buffer;
+ }
+ }
+}
+?>
Added: incubator/shindig/trunk/php/external/PHPUnit/Util/Report.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/external/PHPUnit/Util/Report.php?rev=681982&view=auto
==============================================================================
--- incubator/shindig/trunk/php/external/PHPUnit/Util/Report.php (added)
+++ incubator/shindig/trunk/php/external/PHPUnit/Util/Report.php Sat Aug 2 07:11:35 2008
@@ -0,0 +1,346 @@
+<?php
+/**
+ * PHPUnit
+ *
+ * Copyright (c) 2002-2008, Sebastian Bergmann <sb...@sebastian-bergmann.de>.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * * Neither the name of Sebastian Bergmann nor the names of his
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * 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.
+ *
+ * @category Testing
+ * @package PHPUnit
+ * @author Sebastian Bergmann <sb...@sebastian-bergmann.de>
+ * @copyright 2002-2008 Sebastian Bergmann <sb...@sebastian-bergmann.de>
+ * @license http://www.opensource.org/licenses/bsd-license.php BSD License
+ * @version SVN: $Id: Report.php 1985 2007-12-26 18:11:55Z sb $
+ * @link http://www.phpunit.de/
+ * @since File available since Release 3.0.0
+ */
+
+require_once 'PHPUnit/Framework.php';
+require_once 'PHPUnit/Util/Filter.php';
+require_once 'PHPUnit/Util/CodeCoverage.php';
+require_once 'PHPUnit/Util/Report/Node/Directory.php';
+require_once 'PHPUnit/Util/Report/Node/File.php';
+
+PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT');
+
+/**
+ *
+ *
+ * @category Testing
+ * @package PHPUnit
+ * @author Sebastian Bergmann <sb...@sebastian-bergmann.de>
+ * @copyright 2002-2008 Sebastian Bergmann <sb...@sebastian-bergmann.de>
+ * @license http://www.opensource.org/licenses/bsd-license.php BSD License
+ * @version Release: 3.2.9
+ * @link http://www.phpunit.de/
+ * @since Class available since Release 3.0.0
+ * @abstract
+ */
+abstract class PHPUnit_Util_Report
+{
+ public static $templatePath;
+
+ /**
+ * Renders the report.
+ *
+ * @param PHPUnit_Framework_TestResult $result
+ * @param string $target
+ * @param string $charset
+ * @param boolean $yui
+ * @param boolean $highlight
+ * @param integer $lowUpperBound
+ * @param integer $highLowerBound
+ * @access public
+ * @static
+ */
+ public static function render(PHPUnit_Framework_TestResult $result, $target, $charset = 'ISO-8859-1', $yui = TRUE, $highlight = FALSE, $lowUpperBound = 35, $highLowerBound = 70)
+ {
+ self::$templatePath = sprintf(
+ '%s%sReport%sTemplate%s',
+
+ dirname(__FILE__),
+ DIRECTORY_SEPARATOR,
+ DIRECTORY_SEPARATOR,
+ DIRECTORY_SEPARATOR
+ );
+
+ $codeCoverageInformation = $result->getCodeCoverageInformation();
+ $files = PHPUnit_Util_CodeCoverage::getSummary($codeCoverageInformation);
+ $commonPath = self::reducePaths($files);
+ $items = self::buildDirectoryStructure($files);
+
+ $root = new PHPUnit_Util_Report_Node_Directory($commonPath, NULL);
+
+ self::addItems($root, $items, $files, $yui, $highlight);
+ self::copyFiles($target);
+
+ $root->render(
+ $target,
+ $result->topTestSuite()->getName(),
+ $charset,
+ $highlight,
+ $lowUpperBound,
+ $highLowerBound
+ );
+ }
+
+ /**
+ * @param PHPUnit_Util_Report_Node_Directory $root
+ * @param array $items
+ * @param array $files
+ * @param boolean $yui
+ * @param boolean $highlight
+ * @access protected
+ * @static
+ */
+ protected static function addItems(PHPUnit_Util_Report_Node_Directory $root, array $items, array $files, $yui, $highlight)
+ {
+ foreach ($items as $key => $value) {
+ if (substr($key, -2) == '/f') {
+ try {
+ $file = $root->addFile(
+ substr($key, 0, -2), $value, $yui, $highlight
+ );
+ }
+
+ catch (RuntimeException $e) {
+ continue;
+ }
+ } else {
+ $child = $root->addDirectory($key);
+ self::addItems($child, $value, $files, $yui, $highlight);
+ }
+ }
+ }
+
+ /**
+ * Builds an array representation of the directory structure.
+ *
+ * For instance,
+ *
+ * <code>
+ * Array
+ * (
+ * [Money.php] => Array
+ * (
+ * ...
+ * )
+ *
+ * [MoneyBag.php] => Array
+ * (
+ * ...
+ * )
+ * )
+ * </code>
+ *
+ * is transformed into
+ *
+ * <code>
+ * Array
+ * (
+ * [.] => Array
+ * (
+ * [Money.php] => Array
+ * (
+ * ...
+ * )
+ *
+ * [MoneyBag.php] => Array
+ * (
+ * ...
+ * )
+ * )
+ * )
+ * </code>
+ *
+ * @param array $files
+ * @return array
+ * @access protected
+ * @static
+ */
+ protected static function buildDirectoryStructure($files)
+ {
+ $result = array();
+
+ foreach ($files as $path => $file) {
+ $path = explode('/', $path);
+ $pointer = &$result;
+ $max = count($path);
+
+ for ($i = 0; $i < $max; $i++) {
+ if ($i == ($max - 1)) {
+ $type = '/f';
+ } else {
+ $type = '';
+ }
+
+ $pointer = &$pointer[$path[$i] . $type];
+ }
+
+ $pointer = $file;
+ }
+
+ return $result;
+ }
+
+ /**
+ * Reduces the paths by cutting the longest common start path.
+ *
+ * For instance,
+ *
+ * <code>
+ * Array
+ * (
+ * [/home/sb/PHPUnit/Samples/Money/Money.php] => Array
+ * (
+ * ...
+ * )
+ *
+ * [/home/sb/PHPUnit/Samples/Money/MoneyBag.php] => Array
+ * (
+ * ...
+ * )
+ * )
+ * </code>
+ *
+ * is reduced to
+ *
+ * <code>
+ * Array
+ * (
+ * [Money.php] => Array
+ * (
+ * ...
+ * )
+ *
+ * [MoneyBag.php] => Array
+ * (
+ * ...
+ * )
+ * )
+ * </code>
+ *
+ * @param array $files
+ * @return string
+ * @access protected
+ * @static
+ */
+ protected static function reducePaths(&$files)
+ {
+ if (empty($files)) {
+ return '.';
+ }
+
+ $commonPath = '';
+ $paths = array_keys($files);
+
+ if (count($files) == 1) {
+ $commonPath = dirname($paths[0]);
+ $files[basename($paths[0])] = $files[$paths[0]];
+
+ unset($files[$paths[0]]);
+
+ return $commonPath;
+ }
+
+ $max = count($paths);
+
+ for ($i = 0; $i < $max; $i++) {
+ $paths[$i] = explode(DIRECTORY_SEPARATOR, $paths[$i]);
+
+ if (empty($paths[$i][0])) {
+ $paths[$i][0] = DIRECTORY_SEPARATOR;
+ }
+ }
+
+ $done = FALSE;
+
+ $max = count($paths);
+
+ while (!$done) {
+ for ($i = 0; $i < $max - 1; $i++) {
+ if (!isset($paths[$i][0]) ||
+ !isset($paths[$i+1][0]) ||
+ $paths[$i][0] != $paths[$i+1][0]) {
+ $done = TRUE;
+ break;
+ }
+ }
+
+ if (!$done) {
+ $commonPath .= $paths[0][0] . (($paths[0][0] != DIRECTORY_SEPARATOR) ? DIRECTORY_SEPARATOR : '');
+
+ for ($i = 0; $i < $max; $i++) {
+ array_shift($paths[$i]);
+ }
+ }
+ }
+
+ $original = array_keys($files);
+ $max = count($original);
+
+ for ($i = 0; $i < $max; $i++) {
+ $files[join('/', $paths[$i])] = $files[$original[$i]];
+ unset($files[$original[$i]]);
+ }
+
+ ksort($files);
+
+ return $commonPath;
+ }
+
+ /**
+ * @param string $target
+ * @access protected
+ * @static
+ */
+ protected static function copyFiles($target)
+ {
+ $files = array(
+ 'butter.png',
+ 'chameleon.png',
+ 'close12_1.gif',
+ 'container.css',
+ 'container-min.js',
+ 'glass.png',
+ 'scarlet_red.png',
+ 'snow.png',
+ 'style.css',
+ 'yahoo-dom-event.js'
+ );
+
+ foreach ($files as $file) {
+ copy(self::$templatePath . $file, $target . $file);
+ }
+ }
+}
+?>
Added: incubator/shindig/trunk/php/external/PHPUnit/Util/Report/Node.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/external/PHPUnit/Util/Report/Node.php?rev=681982&view=auto
==============================================================================
--- incubator/shindig/trunk/php/external/PHPUnit/Util/Report/Node.php (added)
+++ incubator/shindig/trunk/php/external/PHPUnit/Util/Report/Node.php Sat Aug 2 07:11:35 2008
@@ -0,0 +1,486 @@
+<?php
+/**
+ * PHPUnit
+ *
+ * Copyright (c) 2002-2008, Sebastian Bergmann <sb...@sebastian-bergmann.de>.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * * Neither the name of Sebastian Bergmann nor the names of his
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * 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.
+ *
+ * @category Testing
+ * @package PHPUnit
+ * @author Sebastian Bergmann <sb...@sebastian-bergmann.de>
+ * @copyright 2002-2008 Sebastian Bergmann <sb...@sebastian-bergmann.de>
+ * @license http://www.opensource.org/licenses/bsd-license.php BSD License
+ * @version SVN: $Id: Node.php 2048 2008-01-08 15:53:36Z sb $
+ * @link http://www.phpunit.de/
+ * @since File available since Release 3.2.0
+ */
+
+require_once 'PHPUnit/Framework.php';
+require_once 'PHPUnit/Util/Filter.php';
+require_once 'PHPUnit/Util/Filesystem.php';
+require_once 'PHPUnit/Util/Test.php';
+
+PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT');
+
+/**
+ * Base class for nodes in the code coverage information tree.
+ *
+ * @category Testing
+ * @package PHPUnit
+ * @author Sebastian Bergmann <sb...@sebastian-bergmann.de>
+ * @copyright 2002-2008 Sebastian Bergmann <sb...@sebastian-bergmann.de>
+ * @license http://www.opensource.org/licenses/bsd-license.php BSD License
+ * @version Release: 3.2.9
+ * @link http://www.phpunit.de/
+ * @since Class available since Release 3.2.0
+ */
+abstract class PHPUnit_Util_Report_Node
+{
+ /**
+ * @var array
+ * @access protected
+ */
+ protected $cache = array();
+
+ /**
+ * @var string
+ * @access protected
+ */
+ protected $name;
+
+ /**
+ * @var PHPUnit_Util_Report_Node
+ * @access protected
+ */
+ protected $parent;
+
+ /**
+ * Constructor.
+ *
+ * @param string $name
+ * @param PHPUnit_Util_Report_Node $parent
+ * @access public
+ */
+ public function __construct($name, PHPUnit_Util_Report_Node $parent = NULL)
+ {
+ $this->name = $name;
+ $this->parent = $parent;
+ }
+
+ /**
+ * Returns the percentage of classes of which at least one method
+ * has been called at least once..
+ *
+ * @return integer
+ * @access public
+ */
+ public function getCalledClassesPercent()
+ {
+ return $this->calculatePercent(
+ $this->getNumCalledClasses(),
+ $this->getNumClasses()
+ );
+ }
+
+ /**
+ * Returns the percentage of methods that has been called at least once.
+ *
+ * @return integer
+ * @access public
+ */
+ public function getCalledMethodsPercent()
+ {
+ return $this->calculatePercent(
+ $this->getNumCalledMethods(),
+ $this->getNumMethods()
+ );
+ }
+
+ /**
+ * Returns the percentage of executed lines.
+ *
+ * @return integer
+ * @access public
+ */
+ public function getLineExecutedPercent()
+ {
+ return $this->calculatePercent(
+ $this->getNumExecutedLines(),
+ $this->getNumExecutableLines()
+ );
+ }
+
+ /**
+ * Returns this node's ID.
+ *
+ * @return string
+ * @access public
+ */
+ public function getId() {
+ if (!isset($this->cache['id'])) {
+ if ($this->parent === NULL) {
+ $this->cache['id'] = 'index';
+ } else {
+ $parentId = $this->parent->getId();
+
+ if ($parentId == 'index') {
+ $this->cache['id'] = $this->getName();
+ } else {
+ $this->cache['id'] = $parentId . '_' . $this->getName();
+ }
+ }
+ }
+
+ return $this->cache['id'];
+ }
+
+ /**
+ * Returns this node's name.
+ *
+ * @param boolean $includeParent
+ * @return string
+ * @access public
+ */
+ public function getName($includeParent = FALSE, $includeCommonPath = FALSE)
+ {
+ if ($includeParent && $this->parent !== NULL) {
+ if (!isset($this->cache['nameIncludingParent'])) {
+ $parent = $this->parent->getName(TRUE);
+ $this->cache['nameIncludingParent'] = !empty($parent) ? $parent . '/' . $this->name : $this->name;
+ }
+
+ return $this->cache['nameIncludingParent'];
+ } else {
+ if ($this->parent !== NULL) {
+ return $this->name;
+ } else {
+ return $includeCommonPath ? $this->name : '';
+ }
+ }
+ }
+
+ /**
+ * Returns the link to this node.
+ *
+ * @param boolean $full
+ * @return string
+ * @access public
+ */
+ public function getLink($full) {
+ if (substr($this->name, -1) == DIRECTORY_SEPARATOR) {
+ $name = substr($this->name, 0, -1);
+ } else {
+ $name = $this->name;
+ }
+
+ $cleanId = PHPUnit_Util_Filesystem::getSafeFilename($this->getId());
+
+ if ($full) {
+ if ($this->parent !== NULL) {
+ $parent = $this->parent->getLink(TRUE) . DIRECTORY_SEPARATOR;
+ } else {
+ $parent = '';
+ }
+
+ return sprintf(
+ '%s<a href="%s.html">%s</a>',
+ $parent,
+ $cleanId,
+ $name
+ );
+ } else {
+ return sprintf(
+ '<a href="%s.html">%s</a>',
+ $cleanId,
+ $name
+ );
+ }
+ }
+
+ /**
+ * Returns this node's path.
+ *
+ * @return string
+ * @access public
+ */
+ public function getPath() {
+ if (!isset($this->cache['path'])) {
+ if ($this->parent === NULL) {
+ $this->cache['path'] = $this->getName(FALSE, TRUE);
+ } else {
+ if (substr($this->parent->getPath(), -1) == DIRECTORY_SEPARATOR) {
+ $this->cache['path'] = $this->parent->getPath() .
+ $this->getName(FALSE, TRUE);
+ } else {
+ $this->cache['path'] = $this->parent->getPath() .
+ DIRECTORY_SEPARATOR .
+ $this->getName(FALSE, TRUE);
+
+ if ($this->parent->getPath() === '' &&
+ realpath($this->cache['path']) === FALSE &&
+ realpath($this->getName(FALSE, TRUE)) !== FALSE) {
+ $this->cache['path'] = $this->getName(FALSE, TRUE);
+ }
+ }
+ }
+ }
+
+ return $this->cache['path'];
+ }
+
+ /**
+ * Calculates a percentage value.
+ *
+ * @param integer $a
+ * @param integer $b
+ * @return float ($a / $b) * 100
+ * @access protected
+ */
+ protected function calculatePercent($a, $b)
+ {
+ if ($b > 0) {
+ $percent = ($a / $b) * 100;
+ } else {
+ $percent = 100;
+ }
+
+ return sprintf(
+ '%01.2F',
+ $percent
+ );
+ }
+
+ protected function doRenderItemObject(PHPUnit_Util_Report_Node $item, $lowUpperBound, $highLowerBound, $link = NULL)
+ {
+ return $this->doRenderItem(
+ array(
+ 'name' => $link != NULL ? $link : $item->getLink(FALSE),
+ 'numClasses' => $item->getNumClasses(),
+ 'numCalledClasses' => $item->getNumCalledClasses(),
+ 'calledClassesPercent' => $item->getCalledClassesPercent(),
+ 'numMethods' => $item->getNumMethods(),
+ 'numCalledMethods' => $item->getNumCalledMethods(),
+ 'calledMethodsPercent' => $item->getCalledMethodsPercent(),
+ 'numExecutableLines' => $item->getNumExecutableLines(),
+ 'numExecutedLines' => $item->getNumExecutedLines(),
+ 'executedLinesPercent' => $item->getLineExecutedPercent()
+ ),
+ $lowUpperBound,
+ $highLowerBound
+ );
+ }
+
+ protected function doRenderItem(array $data, $lowUpperBound, $highLowerBound, $template = 'item.html')
+ {
+ $itemTemplate = new PHPUnit_Util_Template(
+ PHPUnit_Util_Report::$templatePath . $template
+ );
+
+ list($classesColor, $classesLevel) = $this->getColorLevel(
+ $data['calledClassesPercent'], $lowUpperBound, $highLowerBound
+ );
+
+ list($methodsColor, $methodsLevel) = $this->getColorLevel(
+ $data['calledMethodsPercent'], $lowUpperBound, $highLowerBound
+ );
+
+ list($linesColor, $linesLevel) = $this->getColorLevel(
+ $data['executedLinesPercent'], $lowUpperBound, $highLowerBound
+ );
+
+ $itemTemplate->setVar(
+ array(
+ 'name' => $data['name'],
+ 'classes_color' => $classesColor,
+ 'classes_level' => $classesLevel,
+ 'classes_called_width' => floor($data['calledClassesPercent']),
+ 'classes_called_percent' => $data['calledClassesPercent'],
+ 'classes_not_called_width' => 100 - floor($data['calledClassesPercent']),
+ 'num_classes' => $data['numClasses'],
+ 'num_called_classes' => $data['numCalledClasses'],
+ 'methods_color' => $methodsColor,
+ 'methods_level' => $methodsLevel,
+ 'methods_called_width' => floor($data['calledMethodsPercent']),
+ 'methods_called_percent' => $data['calledMethodsPercent'],
+ 'methods_not_called_width' => 100 - floor($data['calledMethodsPercent']),
+ 'num_methods' => $data['numMethods'],
+ 'num_called_methods' => $data['numCalledMethods'],
+ 'lines_color' => $linesColor,
+ 'lines_level' => $linesLevel,
+ 'lines_executed_width' => floor($data['executedLinesPercent']),
+ 'lines_executed_percent' => $data['executedLinesPercent'],
+ 'lines_not_executed_width' => 100 - floor($data['executedLinesPercent']),
+ 'num_executable_lines' => $data['numExecutableLines'],
+ 'num_executed_lines' => $data['numExecutedLines']
+ )
+ );
+
+ return $itemTemplate->render();
+ }
+
+ protected function getColorLevel($percent, $lowUpperBound, $highLowerBound)
+ {
+ $floorPercent = floor($percent);
+
+ if ($floorPercent < $lowUpperBound) {
+ $color = 'scarlet_red';
+ $level = 'Lo';
+ }
+
+ else if ($floorPercent >= $lowUpperBound &&
+ $floorPercent < $highLowerBound) {
+ $color = 'butter';
+ $level = 'Med';
+ }
+
+ else {
+ $color = 'chameleon';
+ $level = 'Hi';
+ }
+
+ return array($color, $level);
+ }
+
+ protected function renderTotalItem($lowUpperBound, $highLowerBound, $directory = TRUE)
+ {
+ if ($directory && empty($this->directories) && count($this->files) == 1) {
+ return '';
+ }
+
+ return $this->doRenderItemObject($this, $lowUpperBound, $highLowerBound, 'Total') .
+ " <tr>\n" .
+ ' <td class="tableHead" colspan="10"> </td>' . "\n" .
+ " </tr>\n";
+ }
+
+ /**
+ * @param PHPUnit_Util_Template $template
+ * @param string $title
+ * @param string $charset
+ * @access public
+ */
+ protected function setTemplateVars(PHPUnit_Util_Template $template, $title, $charset)
+ {
+ $template->setVar(
+ array(
+ 'title' => $title,
+ 'charset' => $charset,
+ 'link' => $this->getLink(TRUE),
+ 'num_executable_lines' => $this->getNumExecutableLines(),
+ 'num_executed_lines' => $this->getNumExecutedLines(),
+ 'lines_executed_percent' => $this->getLineExecutedPercent(),
+ 'date' => $template->getDate(),
+ 'phpunit_version' => PHPUnit_Runner_Version::id(),
+ 'xdebug_version' => phpversion('xdebug')
+ )
+ );
+ }
+
+ /**
+ * Returns the classes of this node.
+ *
+ * @return array
+ * @access public
+ * @abstract
+ */
+ abstract public function getClasses();
+
+ /**
+ * Returns the number of executable lines.
+ *
+ * @return integer
+ * @access public
+ * @abstract
+ */
+ abstract public function getNumExecutableLines();
+
+ /**
+ * Returns the number of executed lines.
+ *
+ * @return integer
+ * @access public
+ * @abstract
+ */
+ abstract public function getNumExecutedLines();
+
+ /**
+ * Returns the number of classes.
+ *
+ * @return integer
+ * @access public
+ * @abstract
+ */
+ abstract public function getNumClasses();
+
+ /**
+ * Returns the number of classes of which at least one method
+ * has been called at least once.
+ *
+ * @return integer
+ * @access public
+ * @abstract
+ */
+ abstract public function getNumCalledClasses();
+
+ /**
+ * Returns the number of methods.
+ *
+ * @return integer
+ * @access public
+ * @abstract
+ */
+ abstract public function getNumMethods();
+
+ /**
+ * Returns the number of methods that has been called at least once.
+ *
+ * @return integer
+ * @access public
+ * @abstract
+ */
+ abstract public function getNumCalledMethods();
+
+ /**
+ * Renders this node.
+ *
+ * @param string $target
+ * @param string $title
+ * @param string $charset
+ * @param boolean $highlight
+ * @param integer $lowUpperBound
+ * @param integer $highLowerBound
+ * @access public
+ * @abstract
+ */
+ abstract public function render($target, $title, $charset = 'ISO-8859-1', $highlight = FALSE, $lowUpperBound = 35, $highLowerBound = 70);
+}
+?>
Added: incubator/shindig/trunk/php/external/PHPUnit/Util/Report/Node/Directory.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/external/PHPUnit/Util/Report/Node/Directory.php?rev=681982&view=auto
==============================================================================
--- incubator/shindig/trunk/php/external/PHPUnit/Util/Report/Node/Directory.php (added)
+++ incubator/shindig/trunk/php/external/PHPUnit/Util/Report/Node/Directory.php Sat Aug 2 07:11:35 2008
@@ -0,0 +1,429 @@
+<?php
+/**
+ * PHPUnit
+ *
+ * Copyright (c) 2002-2008, Sebastian Bergmann <sb...@sebastian-bergmann.de>.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * * Neither the name of Sebastian Bergmann nor the names of his
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * 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.
+ *
+ * @category Testing
+ * @package PHPUnit
+ * @author Sebastian Bergmann <sb...@sebastian-bergmann.de>
+ * @copyright 2002-2008 Sebastian Bergmann <sb...@sebastian-bergmann.de>
+ * @license http://www.opensource.org/licenses/bsd-license.php BSD License
+ * @version SVN: $Id: Directory.php 1985 2007-12-26 18:11:55Z sb $
+ * @link http://www.phpunit.de/
+ * @since File available since Release 3.2.0
+ */
+
+require_once 'PHPUnit/Util/Filter.php';
+require_once 'PHPUnit/Util/Filesystem.php';
+require_once 'PHPUnit/Util/Template.php';
+require_once 'PHPUnit/Util/Report/Node.php';
+require_once 'PHPUnit/Util/Report/Node/File.php';
+
+PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT');
+
+/**
+ * Represents a directory in the code coverage information tree.
+ *
+ * @category Testing
+ * @package PHPUnit
+ * @author Sebastian Bergmann <sb...@sebastian-bergmann.de>
+ * @copyright 2002-2008 Sebastian Bergmann <sb...@sebastian-bergmann.de>
+ * @license http://www.opensource.org/licenses/bsd-license.php BSD License
+ * @version Release: 3.2.9
+ * @link http://www.phpunit.de/
+ * @since Class available since Release 3.2.0
+ */
+class PHPUnit_Util_Report_Node_Directory extends PHPUnit_Util_Report_Node
+{
+ /**
+ * @var PHPUnit_Util_Report_Node[]
+ * @access protected
+ */
+ protected $children = array();
+
+ /**
+ * @var PHPUnit_Util_Report_Node_Directory[]
+ * @access protected
+ */
+ protected $directories = array();
+
+ /**
+ * @var PHPUnit_Util_Report_Node_File[]
+ * @access protected
+ */
+ protected $files = array();
+
+ /**
+ * @var array
+ * @access protected
+ */
+ protected $classes;
+
+ /**
+ * @var integer
+ * @access protected
+ */
+ protected $numExecutableLines = -1;
+
+ /**
+ * @var integer
+ * @access protected
+ */
+ protected $numExecutedLines = -1;
+
+ /**
+ * @var integer
+ * @access protected
+ */
+ protected $numClasses = -1;
+
+ /**
+ * @var integer
+ * @access protected
+ */
+ protected $numCalledClasses = -1;
+
+ /**
+ * @var integer
+ * @access protected
+ */
+ protected $numMethods = -1;
+
+ /**
+ * @var integer
+ * @access protected
+ */
+ protected $numCalledMethods = -1;
+
+ /**
+ * Adds a new directory.
+ *
+ * @return PHPUnit_Util_Report_Node_Directory
+ * @access public
+ */
+ public function addDirectory($name)
+ {
+ $directory = new PHPUnit_Util_Report_Node_Directory($name, $this);
+
+ $this->children[] = $directory;
+ $this->directories[] = &$this->children[count($this->children) - 1];
+
+ return $directory;
+ }
+
+ /**
+ * Adds a new file.
+ *
+ * @param string $name
+ * @param array $lines
+ * @param boolean $yui
+ * @param boolean $highlight
+ * @return PHPUnit_Util_Report_Node_File
+ * @throws RuntimeException
+ * @access public
+ */
+ public function addFile($name, array $lines, $yui, $highlight)
+ {
+ $file = new PHPUnit_Util_Report_Node_File(
+ $name, $this, $lines, $yui, $highlight
+ );
+
+ $this->children[] = $file;
+ $this->files[] = &$this->children[count($this->children) - 1];
+
+ $this->numExecutableLines = -1;
+ $this->numExecutedLines = -1;
+
+ return $file;
+ }
+
+ /**
+ * Returns the directories in this directory.
+ *
+ * @return
+ * @access public
+ */
+ public function getDirectories()
+ {
+ return $this->directories;
+ }
+
+ /**
+ * Returns the files in this directory.
+ *
+ * @return
+ * @access public
+ */
+ public function getFiles()
+ {
+ return $this->files;
+ }
+
+ /**
+ * Returns the classes of this node.
+ *
+ * @return array
+ * @access public
+ */
+ public function getClasses()
+ {
+ if ($this->classes === NULL) {
+ $this->classes = array();
+
+ foreach ($this->children as $child) {
+ $this->classes = array_merge($this->classes, $child->getClasses());
+ }
+ }
+
+ return $this->classes;
+ }
+
+ /**
+ * Returns the number of executable lines.
+ *
+ * @return integer
+ * @access public
+ */
+ public function getNumExecutableLines()
+ {
+ if ($this->numExecutableLines == -1) {
+ $this->numExecutableLines = 0;
+
+ foreach ($this->children as $child) {
+ $this->numExecutableLines += $child->getNumExecutableLines();
+ }
+ }
+
+ return $this->numExecutableLines;
+ }
+
+ /**
+ * Returns the number of executed lines.
+ *
+ * @return integer
+ * @access public
+ */
+ public function getNumExecutedLines()
+ {
+ if ($this->numExecutedLines == -1) {
+ $this->numExecutedLines = 0;
+
+ foreach ($this->children as $child) {
+ $this->numExecutedLines += $child->getNumExecutedLines();
+ }
+ }
+
+ return $this->numExecutedLines;
+ }
+
+ /**
+ * Returns the number of classes.
+ *
+ * @return integer
+ * @access public
+ */
+ public function getNumClasses()
+ {
+ if ($this->numClasses == -1) {
+ $this->numClasses = 0;
+
+ foreach ($this->children as $child) {
+ $this->numClasses += $child->getNumClasses();
+ }
+ }
+
+ return $this->numClasses;
+ }
+
+ /**
+ * Returns the number of classes of which at least one method
+ * has been called at least once.
+ *
+ * @return integer
+ * @access public
+ */
+ public function getNumCalledClasses()
+ {
+ if ($this->numCalledClasses == -1) {
+ $this->numCalledClasses = 0;
+
+ foreach ($this->children as $child) {
+ $this->numCalledClasses += $child->getNumCalledClasses();
+ }
+ }
+
+ return $this->numCalledClasses;
+ }
+
+ /**
+ * Returns the number of methods.
+ *
+ * @return integer
+ * @access public
+ */
+ public function getNumMethods()
+ {
+ if ($this->numMethods == -1) {
+ $this->numMethods = 0;
+
+ foreach ($this->children as $child) {
+ $this->numMethods += $child->getNumMethods();
+ }
+ }
+
+ return $this->numMethods;
+ }
+
+ /**
+ * Returns the number of methods that has been called at least once.
+ *
+ * @return integer
+ * @access public
+ */
+ public function getNumCalledMethods()
+ {
+ if ($this->numCalledMethods == -1) {
+ $this->numCalledMethods = 0;
+
+ foreach ($this->children as $child) {
+ $this->numCalledMethods += $child->getNumCalledMethods();
+ }
+ }
+
+ return $this->numCalledMethods;
+ }
+
+ /**
+ * Renders this node.
+ *
+ * @param string $target
+ * @param string $title
+ * @param string $charset
+ * @param boolean $highlight
+ * @param integer $lowUpperBound
+ * @param integer $highLowerBound
+ * @access public
+ */
+ public function render($target, $title, $charset = 'ISO-8859-1', $highlight = FALSE, $lowUpperBound = 35, $highLowerBound = 70)
+ {
+ $this->doRender(
+ $target, $title, $charset, $highlight, $lowUpperBound, $highLowerBound
+ );
+
+ foreach ($this->children as $child) {
+ $child->render(
+ $target, $title, $charset, $highlight, $lowUpperBound, $highLowerBound
+ );
+ }
+ }
+
+ /**
+ * @param string $target
+ * @param string $title
+ * @param string $charset
+ * @param boolean $highlight
+ * @param integer $lowUpperBound
+ * @param integer $highLowerBound
+ * @access protected
+ */
+ protected function doRender($target, $title, $charset, $highlight, $lowUpperBound, $highLowerBound)
+ {
+ $cleanId = PHPUnit_Util_Filesystem::getSafeFilename($this->getId());
+ $file = $target . $cleanId . '.html';
+
+ $template = new PHPUnit_Util_Template(
+ PHPUnit_Util_Report::$templatePath . 'directory.html'
+ );
+
+ $this->setTemplateVars($template, $title, $charset);
+
+ $totalClassesPercent = $this->getCalledClassesPercent();
+
+ list($totalClassesColor, $totalClassesLevel) = $this->getColorLevel(
+ $totalClassesPercent, $lowUpperBound, $highLowerBound
+ );
+
+ $totalMethodsPercent = $this->getCalledMethodsPercent();
+
+ list($totalMethodsColor, $totalMethodsLevel) = $this->getColorLevel(
+ $totalMethodsPercent, $lowUpperBound, $highLowerBound
+ );
+
+ $totalLinesPercent = $this->getLineExecutedPercent();
+
+ list($totalLinesColor, $totalLinesLevel) = $this->getColorLevel(
+ $totalLinesPercent, $lowUpperBound, $highLowerBound
+ );
+
+ $template->setVar(
+ array(
+ 'total_item' => $this->renderTotalItem($lowUpperBound, $highLowerBound),
+ 'items' => $this->renderItems($lowUpperBound, $highLowerBound),
+ 'low_upper_bound' => $lowUpperBound,
+ 'high_lower_bound' => $highLowerBound
+ )
+ );
+
+ $template->renderTo($file);
+ }
+
+ /**
+ * @return string
+ * @access protected
+ */
+ protected function renderItems($lowUpperBound, $highLowerBound)
+ {
+ $items = $this->doRenderItems($this->directories, $lowUpperBound, $highLowerBound);
+ $items .= $this->doRenderItems($this->files, $lowUpperBound, $highLowerBound);
+
+ return $items;
+ }
+
+ /**
+ * @param array $items
+ * @return string
+ * @access protected
+ */
+ protected function doRenderItems(array $items, $lowUpperBound, $highLowerBound)
+ {
+ $result = '';
+
+ foreach ($items as $item) {
+ $result .= $this->doRenderItemObject($item, $lowUpperBound, $highLowerBound);
+ }
+
+ return $result;
+ }
+}
+?>