Index: .htaccess =================================================================== --- .htaccess (revision 658515) +++ .htaccess (working copy) @@ -1,4 +1,5 @@ - RewriteEngine On - RewriteRule (.*) index.php [L] + RewriteEngine On + RewriteCond %{REQUEST_URI} ^test/([.]*)$ + RewriteRule (.*) index.php [L] Index: test/socialdata/index.php =================================================================== --- test/socialdata/index.php (revision 0) +++ test/socialdata/index.php (revision 0) @@ -0,0 +1,43 @@ + 2 ){ + foreach ($dir as $file){ + if($file != '..' && $file != '.'){ + if(is_dir($file)){ + readDirR($dirName.'/'.$file, $names); + } + $clase = str_replace('.php','',$file); + $names[] = array('path' => $dirName.'/'.$file,'name' => $clase); + } + } + } + +} + +$clases = array(); +readDirR('.', $clases); +$suite = new PHPUnit_Framework_TestSuite(); + +foreach($clases as $clase){ + if(file_exists($clase['path'])){ + @require_once $clase['path']; + if(class_exists($clase['name'])){ + $suite->addTestSuite($clase['name']); + } + } +} + +$result = new PHPUnit_TextUI_TestRunner(); +echo 'TestCases

Test Cases

'; 
+	$result->doRun($suite);
+echo'
' +?> \ No newline at end of file Property changes on: test/socialdata/index.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Extensions/RepeatedTest.php =================================================================== --- test/PHPUnit/Extensions/RepeatedTest.php (revision 0) +++ test/PHPUnit/Extensions/RepeatedTest.php (revision 0) @@ -0,0 +1,160 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: RepeatedTest.php 1985 2007-12-26 18:11:55Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit/Framework.php'; +require_once 'PHPUnit/Extensions/TestDecorator.php'; +require_once 'PHPUnit/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * A Decorator that runs a test repeatedly. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class PHPUnit_Extensions_RepeatedTest extends PHPUnit_Extensions_TestDecorator +{ + /** + * @var mixed + * @access protected + */ + protected $filter = FALSE; + + /** + * @var array + * @access protected + */ + protected $groups = array(); + + /** + * @var array + * @access protected + */ + protected $excludeGroups = array(); + + /** + * @var integer + * @access protected + */ + protected $timesRepeat = 1; + + /** + * Constructor. + * + * @param PHPUnit_Framework_Test $test + * @param integer $timesRepeat + * @param mixed $filter + * @param array $groups + * @param array $excludeGroups + * @throws InvalidArgumentException + * @access public + */ + public function __construct(PHPUnit_Framework_Test $test, $timesRepeat = 1, $filter = FALSE, array $groups = array(), array $excludeGroups = array()) + { + parent::__construct($test); + + if (is_integer($timesRepeat) && + $timesRepeat >= 0) { + $this->timesRepeat = $timesRepeat; + } else { + throw new InvalidArgumentException( + 'Argument 2 must be a positive integer.' + ); + } + + $this->filter = $filter; + $this->groups = $groups; + $this->excludeGroups = $excludeGroups; + } + + /** + * Counts the number of test cases that + * will be run by this test. + * + * @return integer + * @access public + */ + public function count() + { + return $this->timesRepeat * count($this->test); + } + + /** + * Runs the decorated test and collects the + * result in a TestResult. + * + * @param PHPUnit_Framework_TestResult $result + * @return PHPUnit_Framework_TestResult + * @throws InvalidArgumentException + * @access public + */ + public function run(PHPUnit_Framework_TestResult $result = NULL) + { + if ($result === NULL) { + $result = $this->createResult(); + } + + for ($i = 0; $i < $this->timesRepeat && !$result->shouldStop(); $i++) { + if ($this->test instanceof PHPUnit_Framework_TestSuite) { + $this->test->run( + $result, $this->filter, $this->groups, $this->excludeGroups + ); + } else { + $this->test->run($result); + } + } + + return $result; + } +} +?> Property changes on: test/PHPUnit/Extensions/RepeatedTest.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Extensions/ExceptionTestCase.php =================================================================== --- test/PHPUnit/Extensions/ExceptionTestCase.php (revision 0) +++ test/PHPUnit/Extensions/ExceptionTestCase.php (revision 0) @@ -0,0 +1,73 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: ExceptionTestCase.php 2152 2008-01-17 11:17:12Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +trigger_error( + "Class PHPUnit_Extensions_ExceptionTestCase is deprecated. ". + "It will be removed in PHPUnit 3.3. ". + "The functionality has been merged into PHPUnit_Framework_TestCase." +); + +/** + * A TestCase that expects a specified Exception to be thrown. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 class PHPUnit_Extensions_ExceptionTestCase extends PHPUnit_Framework_TestCase +{ +} +?> Property changes on: test/PHPUnit/Extensions/ExceptionTestCase.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Extensions/OutputTestCase.php =================================================================== --- test/PHPUnit/Extensions/OutputTestCase.php (revision 0) +++ test/PHPUnit/Extensions/OutputTestCase.php (revision 0) @@ -0,0 +1,207 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: OutputTestCase.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'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * A TestCase that expects a specified output. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 class PHPUnit_Extensions_OutputTestCase extends PHPUnit_Framework_TestCase +{ + /** + * @var string + * @access protected + */ + protected $expectedRegex = NULL; + + /** + * @var string + * @access protected + */ + protected $expectedString = NULL; + + /** + * @var string + * @access protected + */ + protected $output = ''; + + /** + * @var mixed + * @access protected + */ + protected $outputCallback = FALSE; + + /** + * @return bool + * @access public + */ + public function setOutputCallback($callback) + { + if (is_callable($callback)) { + $this->outputCallback = $callback; + $set = TRUE; + } else { + $set = FALSE; + } + + return $set; + } + + /** + * @return string + * @access public + */ + public function normalizeOutput($buffer) + { + return str_replace("\r", '', $buffer); + } + + /** + * @return string + * @access public + */ + public function getActualOutput() + { + return $this->output; + } + + /** + * @return string + * @access public + */ + public function expectedRegex() + { + return $this->expectedRegex; + } + + /** + * @param string $expectedRegex + * @access public + */ + public function expectOutputRegex($expectedRegex) + { + if ($this->expectedString !== NULL) { + throw new RuntimeException; + } + + if (is_string($expectedRegex) || is_null($expectedRegex)) { + $this->expectedRegex = $expectedRegex; + } + } + + /** + * @return string + * @access public + */ + public function expectedString() + { + return $this->expectedOutput; + } + + /** + * @param string $expectedString + * @access public + */ + public function expectOutputString($expectedString) + { + if ($this->expectedRegex !== NULL) { + throw new RuntimeException; + } + + if (is_string($expectedString) || is_null($expectedString)) { + $this->expectedString = $expectedString; + } + } + + /** + * @access protected + */ + protected function runTest() + { + ob_start(); + + try { + parent::runTest(); + } + + catch (Exception $e) { + ob_end_clean(); + throw $e; + } + + if ($this->outputCallback === FALSE) { + $this->output = ob_get_contents(); + } else { + $this->output = call_user_func_array($this->outputCallback, array(ob_get_contents())); + } + + ob_end_clean(); + + if ($this->expectedRegex !== NULL) { + $this->assertRegExp($this->expectedRegex, $this->output); + $this->expectedRegex = NULL; + } + + else if ($this->expectedString !== NULL) { + $this->assertEquals($this->expectedString, $this->output); + $this->expectedString = NULL; + } + } +} +?> Property changes on: test/PHPUnit/Extensions/OutputTestCase.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Extensions/PerformanceTestCase.php =================================================================== --- test/PHPUnit/Extensions/PerformanceTestCase.php (revision 0) +++ test/PHPUnit/Extensions/PerformanceTestCase.php (revision 0) @@ -0,0 +1,122 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: PerformanceTestCase.php 1985 2007-12-26 18:11:55Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 2.1.0 + */ + +require_once 'PHPUnit/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; +require_once 'PHPUnit/Util/Timer.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * A TestCase that expects a TestCase to be executed + * meeting a given time limit. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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.1.0 + */ +abstract class PHPUnit_Extensions_PerformanceTestCase extends PHPUnit_Framework_TestCase +{ + /** + * @var integer + * @access protected + */ + protected $maxRunningTime = 0; + + /** + * @access protected + */ + protected function runTest() + { + PHPUnit_Util_Timer::start(); + parent::runTest(); + $time = PHPUnit_Util_Timer::stop(); + + if ($this->maxRunningTime != 0 && + $time > $this->maxRunningTime) { + $this->fail( + sprintf( + 'expected running time: <= %s but was: %s', + + $this->maxRunningTime, + $time + ) + ); + } + } + + /** + * @param integer $maxRunningTime + * @throws InvalidArgumentException + * @access public + * @since Method available since Release 2.3.0 + */ + public function setMaxRunningTime($maxRunningTime) + { + if (is_integer($maxRunningTime) && + $maxRunningTime >= 0) { + $this->maxRunningTime = $maxRunningTime; + } else { + throw new InvalidArgumentException; + } + } + + /** + * @return integer + * @access public + * @since Method available since Release 2.3.0 + */ + public function getMaxRunningTime() + { + return $this->maxRunningTime; + } +} +?> Property changes on: test/PHPUnit/Extensions/PerformanceTestCase.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Extensions/SeleniumTestCase.php =================================================================== --- test/PHPUnit/Extensions/SeleniumTestCase.php (revision 0) +++ test/PHPUnit/Extensions/SeleniumTestCase.php (revision 0) @@ -0,0 +1,1739 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: SeleniumTestCase.php 2111 2008-01-15 09:55:15Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit/Framework.php'; +require_once 'PHPUnit/Util/Log/Database.php'; +require_once 'PHPUnit/Util/Filter.php'; +require_once 'PHPUnit/Util/Test.php'; +require_once 'PHPUnit/Util/XML.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * TestCase class that uses Selenium to provide + * the functionality required for web testing. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 class PHPUnit_Extensions_SeleniumTestCase extends PHPUnit_Framework_TestCase +{ + /** + * @var array + * @access public + * @static + */ + public static $browsers = array(); + + /** + * @var string + * @access protected + */ + protected $browser; + + /** + * @var string + * @access protected + */ + protected $browserName; + + /** + * @var string + * @access protected + */ + protected $browserUrl; + + /** + * @var string + * @access protected + */ + protected $host = 'localhost'; + + /** + * @var integer + * @access protected + */ + protected $port = 4444; + + /** + * @var integer + * @access protected + */ + protected $timeout = 30000; + + /** + * @var array + * @access protected + */ + protected static $sessionId = array(); + + /** + * @var integer + * @access protected + */ + protected $sleep = 0; + + /** + * @var boolean + * @access protected + */ + protected $autoStop = TRUE; + + /** + * @var boolean + * @access protected + */ + protected $collectCodeCoverageInformation = FALSE; + + /** + * @var string + * @access protected + */ + protected $coverageScriptUrl = ''; + + /** + * @var string + * @access protected + */ + protected $testId; + + /** + * @var boolean + * @access protected + */ + protected $inDefaultAssertions = FALSE; + + /** + * @param string $name + * @param array $browser + * @throws InvalidArgumentException + * @access public + */ + public function __construct($name = NULL, array $data = array(), array $browser = array()) + { + parent::__construct($name, $data); + + if (isset($browser['name'])) { + if (!is_string($browser['name'])) { + throw new InvalidArgumentException; + } + } else { + $browser['name'] = ''; + } + + if (isset($browser['browser'])) { + if (!is_string($browser['browser'])) { + throw new InvalidArgumentException; + } + } else { + $browser['browser'] = ''; + } + + if (isset($browser['host'])) { + if (!is_string($browser['host'])) { + throw new InvalidArgumentException; + } + } else { + $browser['host'] = 'localhost'; + } + + if (isset($browser['port'])) { + if (!is_int($browser['port'])) { + throw new InvalidArgumentException; + } + } else { + $browser['port'] = 4444; + } + + if (isset($browser['timeout'])) { + if (!is_int($browser['timeout'])) { + throw new InvalidArgumentException; + } + } else { + $browser['timeout'] = 30000; + } + + $this->browserName = $browser['name']; + $this->browser = $browser['browser']; + $this->host = $browser['host']; + $this->port = $browser['port']; + $this->timeout = $browser['timeout']; + } + + /** + * @param string $className + * @return PHPUnit_Framework_TestSuite + * @access public + */ + public static function suite($className) + { + $suite = new PHPUnit_Framework_TestSuite; + $suite->setName($className); + + $class = new ReflectionClass($className); + $classGroups = PHPUnit_Util_Test::getGroups($class); + $staticProperties = $class->getStaticProperties(); + + // Create tests from Selenese/HTML files. + if (isset($staticProperties['seleneseDirectory']) && + is_dir($staticProperties['seleneseDirectory'])) { + $files = new PHPUnit_Util_FilterIterator( + new RecursiveIteratorIterator( + new RecursiveDirectoryIterator( + $staticProperties['seleneseDirectory'] + ) + ), + '.htm' + ); + + // Create tests from Selenese/HTML files for multiple browsers. + if (!empty($staticProperties['browsers'])) { + foreach ($staticProperties['browsers'] as $browser) { + $browserSuite = new PHPUnit_Framework_TestSuite; + $browserSuite->setName($className . ': ' . $browser['name']); + + foreach ($files as $file) { + $browserSuite->addTest( + new $className((string)$file, array(), $browser) + ); + } + + $suite->addTest($browserSuite, $classGroups); + } + } + + // Create tests from Selenese/HTML files for single browser. + else { + foreach ($files as $file) { + $suite->addTest(new $className((string)$file), $classGroups); + } + } + } + + // Create tests from test methods for multiple browsers. + if (!empty($staticProperties['browsers'])) { + foreach ($staticProperties['browsers'] as $browser) { + $browserSuite = new PHPUnit_Framework_TestSuite; + $browserSuite->setName($className . ': ' . $browser['name']); + + foreach ($class->getMethods() as $method) { + if (PHPUnit_Framework_TestSuite::isPublicTestMethod($method)) { + $name = $method->getName(); + $data = PHPUnit_Util_Test::getProvidedData($className, $name); + $groups = PHPUnit_Util_Test::getGroups($method, $classGroups); + + // Test method with @dataProvider. + if (is_array($data) || $data instanceof Iterator) { + $dataSuite = new PHPUnit_Framework_TestSuite( + $className . '::' . $name + ); + + foreach ($data as $_data) { + $dataSuite->addTest( + new $className($name, $_data, $browser), + $groups + ); + } + + $browserSuite->addTest($dataSuite); + } + + // Test method without @dataProvider. + else { + $browserSuite->addTest( + new $className($name, array(), $browser), $groups + ); + } + } + } + + $suite->addTest($browserSuite); + } + } + + // Create tests from test methods for single browser. + else { + foreach ($class->getMethods() as $method) { + if (PHPUnit_Framework_TestSuite::isPublicTestMethod($method)) { + $name = $method->getName(); + $data = PHPUnit_Util_Test::getProvidedData($className, $name); + $groups = PHPUnit_Util_Test::getGroups($method, $classGroups); + + // Test method with @dataProvider. + if (is_array($data) || $data instanceof Iterator) { + $dataSuite = new PHPUnit_Framework_TestSuite( + $className . '::' . $name + ); + + foreach ($data as $_data) { + $dataSuite->addTest( + new $className($name, $_data), + $groups + ); + } + + $suite->addTest($dataSuite); + } + + // Test method without @dataProvider. + else { + $suite->addTest( + new $className($name), $groups + ); + } + } + } + } + + return $suite; + } + + /** + * Runs the test case and collects the results in a TestResult object. + * If no TestResult object is passed a new one will be created. + * + * @param PHPUnit_Framework_TestResult $result + * @return PHPUnit_Framework_TestResult + * @throws InvalidArgumentException + * @access public + */ + public function run(PHPUnit_Framework_TestResult $result = NULL) + { + if ($result === NULL) { + $result = $this->createResult(); + } + + $this->collectCodeCoverageInformation = $result->getCollectCodeCoverageInformation(); + + $result->run($this); + + if ($this->collectCodeCoverageInformation) { + $result->appendCodeCoverageInformation( + $this, $this->getCodeCoverage() + ); + } + + return $result; + } + + /** + * @access protected + */ + protected function runTest() + { + $this->start(); + + if (!is_file($this->name)) { + parent::runTest(); + } else { + $this->runSelenese($this->name); + } + + if ($this->autoStop) { + try { + $this->stop(); + } + + catch (RuntimeException $e) { + } + } + } + + /** + * If you want to override tearDown() make sure to either call stop() or + * parent::tearDown(). Otherwise the Selenium RC session will not be + * closed upon test failure. + * + * @access protected + */ + protected function tearDown() + { + if ($this->autoStop) { + try { + $this->stop(); + } + + catch (RuntimeException $e) { + } + } + } + + /** + * Returns a string representation of the test case. + * + * @return string + * @access public + */ + public function toString() + { + $buffer = parent::toString(); + + if (!empty($this->browserName)) { + $buffer .= ' with browser ' . $this->browserName; + } + + return $buffer; + } + + /** + * @return string + * @access public + */ + public function start() + { + if (!isset(self::$sessionId[$this->host][$this->port][$this->browser])) { + self::$sessionId[$this->host][$this->port][$this->browser] = $this->getString( + 'getNewBrowserSession', + array($this->browser, $this->browserUrl) + ); + + $this->doCommand('setTimeout', array($this->timeout)); + } + + + $this->testId = md5(uniqid(rand(), TRUE)); + + return self::$sessionId[$this->host][$this->port][$this->browser]; + } + + /** + * @access public + */ + public function stop() + { + if (!isset(self::$sessionId[$this->host][$this->port][$this->browser])) { + return; + } + + $this->doCommand('testComplete'); + + unset(self::$sessionId[$this->host][$this->port][$this->browser]); + } + + /** + * @param boolean $autoStop + * @throws InvalidArgumentException + * @access public + */ + public function setAutoStop($autoStop) + { + if (!is_bool($autoStop)) { + throw new InvalidArgumentException; + } + + $this->autoStop = $autoStop; + } + + /** + * @param string $browser + * @throws InvalidArgumentException + * @access public + */ + public function setBrowser($browser) + { + if (!is_string($browser)) { + throw new InvalidArgumentException; + } + + $this->browser = $browser; + } + + /** + * @param string $browserUrl + * @throws InvalidArgumentException + * @access public + */ + public function setBrowserUrl($browserUrl) + { + if (!is_string($browserUrl)) { + throw new InvalidArgumentException; + } + + $this->browserUrl = $browserUrl; + } + + /** + * @param string $host + * @throws InvalidArgumentException + * @access public + */ + public function setHost($host) + { + if (!is_string($host)) { + throw new InvalidArgumentException; + } + + $this->host = $host; + } + + /** + * @param integer $port + * @throws InvalidArgumentException + * @access public + */ + public function setPort($port) + { + if (!is_int($port)) { + throw new InvalidArgumentException; + } + + $this->port = $port; + } + + /** + * @param integer $timeout + * @throws InvalidArgumentException + * @access public + */ + public function setTimeout($timeout) + { + if (!is_int($timeout)) { + throw new InvalidArgumentException; + } + + $this->timeout = $timeout; + } + + /** + * @param integer $seconds + * @throws InvalidArgumentException + * @access public + */ + public function setSleep($seconds) + { + if (!is_int($seconds)) { + throw new InvalidArgumentException; + } + + $this->sleep = $seconds; + } + + /** + * Runs a test from a Selenese (HTML) specification. + * + * @param string $filename + * @access public + */ + public function runSelenese($filename) + { + $document = PHPUnit_Util_XML::load($filename, TRUE); + $xpath = new DOMXPath($document); + $rows = $xpath->query('body/table/tbody/tr'); + + foreach ($rows as $row) + { + $action = NULL; + $arguments = array(); + $columns = $xpath->query('td', $row); + + foreach ($columns as $column) + { + if ($action === NULL) { + $action = $column->nodeValue; + } else { + $arguments[] = $column->nodeValue; + } + } + + $this->__call($action, $arguments); + } + } + + /** + * This method implements the Selenium RC protocol. + * + * @param string $command + * @param array $arguments + * @return mixed + * @access public + * @method unknown addLocationStrategy() + * @method unknown addSelection() + * @method unknown allowNativeXpath() + * @method unknown altKeyDown() + * @method unknown altKeyUp() + * @method unknown answerOnNextPrompt() + * @method unknown assignId() + * @method unknown captureScreenshot() + * @method unknown check() + * @method unknown chooseCancelOnNextConfirmation() + * @method unknown click() + * @method unknown clickAndWait() + * @method unknown clickAt() + * @method unknown close() + * @method unknown controlKeyDown() + * @method unknown controlKeyUp() + * @method unknown createCookie() + * @method unknown deleteCookie() + * @method unknown doubleClick() + * @method unknown doubleClickAt() + * @method unknown dragAndDrop() + * @method unknown dragAndDropToObject() + * @method unknown dragDrop() + * @method unknown fireEvent() + * @method string getAlert() + * @method array getAllButtons() + * @method array getAllFields() + * @method array getAllLinks() + * @method array getAllWindowIds() + * @method array getAllWindowNames() + * @method array getAllWindowTitles() + * @method string getAttribute() + * @method array getAttributeFromAllWindows() + * @method string getBodyText() + * @method string getConfirmation() + * @method string getCookie() + * @method integer getCursorPosition() + * @method integer getElementHeight() + * @method integer getElementIndex() + * @method integer getElementPositionLeft() + * @method integer getElementPositionTop() + * @method integer getElementWidth() + * @method string getEval() + * @method string getExpression() + * @method string getHtmlSource() + * @method string getLocation() + * @method string getLogMessages() + * @method integer getMouseSpeed() + * @method string getPrompt() + * @method array getSelectOptions() + * @method string getSelectedId() + * @method array getSelectedIds() + * @method string getSelectedIndex() + * @method array getSelectedIndexes() + * @method string getSelectedLabel() + * @method array getSelectedLabels() + * @method string getSelectedValue() + * @method array getSelectedValues() + * @method unknown getSpeed() + * @method string getTable() + * @method string getText() + * @method string getTitle() + * @method string getValue() + * @method boolean getWhetherThisFrameMatchFrameExpression() + * @method boolean getWhetherThisWindowMatchWindowExpression() + * @method integer getXpathCount() + * @method unknown goBack() + * @method unknown highlight() + * @method boolean isAlertPresent() + * @method boolean isChecked() + * @method boolean isConfirmationPresent() + * @method boolean isEditable() + * @method boolean isElementPresent() + * @method boolean isOrdered() + * @method boolean isPromptPresent() + * @method boolean isSomethingSelected() + * @method boolean isTextPresent() + * @method boolean isVisible() + * @method unknown keyDown() + * @method unknown keyPress() + * @method unknown keyUp() + * @method unknown metaKeyDown() + * @method unknown metaKeyUp() + * @method unknown mouseDown() + * @method unknown mouseDownAt() + * @method unknown mouseMove() + * @method unknown mouseMoveAt() + * @method unknown mouseOut() + * @method unknown mouseOver() + * @method unknown mouseUp() + * @method unknown mouseUpAt() + * @method unknown open() + * @method unknown openWindow() + * @method unknown refresh() + * @method unknown removeAllSelections() + * @method unknown removeSelection() + * @method unknown select() + * @method unknown selectFrame() + * @method unknown selectWindow() + * @method unknown setContext() + * @method unknown setCursorPosition() + * @method unknown setMouseSpeed() + * @method unknown setSpeed() + * @method unknown shiftKeyDown() + * @method unknown shiftKeyUp() + * @method unknown submit() + * @method unknown type() + * @method unknown typeKeys() + * @method unknown uncheck() + * @method unknown waitForCondition() + * @method unknown waitForPageToLoad() + * @method unknown waitForPopUp() + * @method unknown windowFocus() + * @method unknown windowMaximize() + */ + public function __call($command, $arguments) + { + switch ($command) { + case 'addLocationStrategy': + case 'addSelection': + case 'allowNativeXpath': + case 'altKeyDown': + case 'altKeyUp': + case 'answerOnNextPrompt': + case 'assignId': + case 'captureScreenshot': + case 'check': + case 'chooseCancelOnNextConfirmation': + case 'click': + case 'clickAt': + case 'close': + case 'controlKeyDown': + case 'controlKeyUp': + case 'createCookie': + case 'deleteCookie': + case 'doubleClick': + case 'doubleClickAt': + case 'dragAndDrop': + case 'dragAndDropToObject': + case 'dragDrop': + case 'fireEvent': + case 'goBack': + case 'highlight': + case 'keyDown': + case 'keyPress': + case 'keyUp': + case 'metaKeyDown': + case 'metaKeyUp': + case 'mouseDown': + case 'mouseDownAt': + case 'mouseMove': + case 'mouseMoveAt': + case 'mouseOut': + case 'mouseOver': + case 'mouseUp': + case 'mouseUpAt': + case 'open': + case 'openWindow': + case 'refresh': + case 'removeAllSelections': + case 'removeSelection': + case 'select': + case 'selectFrame': + case 'selectWindow': + case 'setContext': + case 'setCursorPosition': + case 'setMouseSpeed': + case 'setSpeed': + case 'shiftKeyDown': + case 'shiftKeyUp': + case 'submit': + case 'type': + case 'typeKeys': + case 'uncheck': + case 'windowFocus': + case 'windowMaximize': { + // Pre-Command Actions + switch ($command) { + case 'open': + case 'openWindow': { + if ($this->collectCodeCoverageInformation) { + $this->deleteCookie('PHPUNIT_SELENIUM_TEST_ID', '/'); + + $this->createCookie( + 'PHPUNIT_SELENIUM_TEST_ID=' . $this->testId, + 'path=/' + ); + } + } + break; + } + + $this->doCommand($command, $arguments); + + // Post-Command Actions + switch ($command) { + case 'addLocationStrategy': + case 'allowNativeXpath': + case 'assignId': + case 'captureScreenshot': { + // intentionally empty + } + break; + + default: { + if ($this->sleep > 0) { + sleep($this->sleep); + } + + $this->runDefaultAssertions($command); + } + } + } + break; + + case 'getWhetherThisFrameMatchFrameExpression': + case 'getWhetherThisWindowMatchWindowExpression': + case 'isAlertPresent': + case 'isChecked': + case 'isConfirmationPresent': + case 'isEditable': + case 'isElementPresent': + case 'isOrdered': + case 'isPromptPresent': + case 'isSomethingSelected': + case 'isTextPresent': + case 'isVisible': { + return $this->getBoolean($command, $arguments); + } + break; + + case 'getCursorPosition': + case 'getElementHeight': + case 'getElementIndex': + case 'getElementPositionLeft': + case 'getElementPositionTop': + case 'getElementWidth': + case 'getMouseSpeed': + case 'getSpeed': + case 'getXpathCount': { + return $this->getNumber($command, $arguments); + } + break; + + case 'getAlert': + case 'getAttribute': + case 'getBodyText': + case 'getConfirmation': + case 'getCookie': + case 'getEval': + case 'getExpression': + case 'getHtmlSource': + case 'getLocation': + case 'getLogMessages': + case 'getPrompt': + case 'getSelectedId': + case 'getSelectedIndex': + case 'getSelectedLabel': + case 'getSelectedValue': + case 'getTable': + case 'getText': + case 'getTitle': + case 'getValue': { + return $this->getString($command, $arguments); + } + break; + + case 'getAllButtons': + case 'getAllFields': + case 'getAllLinks': + case 'getAllWindowIds': + case 'getAllWindowNames': + case 'getAllWindowTitles': + case 'getAttributeFromAllWindows': + case 'getSelectedIds': + case 'getSelectedIndexes': + case 'getSelectedLabels': + case 'getSelectedValues': + case 'getSelectOptions': { + return $this->getStringArray($command, $arguments); + } + break; + + case 'clickAndWait': { + $this->doCommand('click', $arguments); + $this->doCommand('waitForPageToLoad', array($this->timeout)); + + if ($this->sleep > 0) { + sleep($this->sleep); + } + + $this->runDefaultAssertions($command); + } + break; + + case 'waitForCondition': + case 'waitForPopUp': { + if (count($arguments) == 1) { + $arguments[] = $this->timeout; + } + + $this->doCommand($command, $arguments); + $this->runDefaultAssertions($command); + } + break; + + case 'waitForPageToLoad': { + if (empty($arguments)) { + $arguments[] = $this->timeout; + } + + $this->doCommand($command, $arguments); + $this->runDefaultAssertions($command); + } + break; + + default: { + $this->stop(); + + throw new BadMethodCallException( + "Method $command not defined." + ); + } + } + } + + /** + * Asserts that an alert is present. + * + * @param string $message + * @access public + */ + public function assertAlertPresent($message = 'No alert present.') + { + $this->assertTrue($this->isAlertPresent(), $message); + } + + /** + * Asserts that no alert is present. + * + * @param string $message + * @access public + */ + public function assertNoAlertPresent($message = 'Alert present.') + { + $this->assertFalse($this->isAlertPresent(), $message); + } + + /** + * Asserts that an option is checked. + * + * @param string $locator + * @param string $message + * @access public + */ + public function assertChecked($locator, $message = '') + { + if ($message == '') { + $message = sprintf( + '"%s" not checked.', + $locator + ); + } + + $this->assertTrue($this->isChecked($locator), $message); + } + + /** + * Asserts that an option is not checked. + * + * @param string $locator + * @param string $message + * @access public + */ + public function assertNotChecked($locator, $message = '') + { + if ($message == '') { + $message = sprintf( + '"%s" checked.', + $locator + ); + } + + $this->assertFalse($this->isChecked($locator), $message); + } + + /** + * Assert that a confirmation is present. + * + * @param string $message + * @access public + */ + public function assertConfirmationPresent($message = 'No confirmation present.') + { + $this->assertTrue($this->isConfirmationPresent(), $message); + } + + /** + * Assert that no confirmation is present. + * + * @param string $message + * @access public + */ + public function assertNoConfirmationPresent($message = 'Confirmation present.') + { + $this->assertFalse($this->isConfirmationPresent(), $message); + } + + /** + * Asserts that an input field is editable. + * + * @param string $locator + * @param string $message + * @access public + */ + public function assertEditable($locator, $message = '') + { + if ($message == '') { + $message = sprintf( + '"%s" not editable.', + $locator + ); + } + + $this->assertTrue($this->isEditable($locator), $message); + } + + /** + * Asserts that an input field is not editable. + * + * @param string $locator + * @param string $message + * @access public + */ + public function assertNotEditable($locator, $message = '') + { + if ($message == '') { + $message = sprintf( + '"%s" editable.', + $locator + ); + } + + $this->assertFalse($this->isEditable($locator), $message); + } + + /** + * Asserts that an element's value is equal to a given string. + * + * @param string $locator + * @param string $text + * @param string $message + * @access public + */ + public function assertElementValueEquals($locator, $text, $message = '') + { + $this->assertEquals($text, $this->getValue($locator), $message); + } + + /** + * Asserts that an element's value is not equal to a given string. + * + * @param string $locator + * @param string $text + * @param string $message + * @access public + */ + public function assertElementValueNotEquals($locator, $text, $message = '') + { + $this->assertNotEquals($text, $this->getValue($locator), $message); + } + + /** + * Asserts that an element contains a given string. + * + * @param string $locator + * @param string $text + * @param string $message + * @access public + */ + public function assertElementContainsText($locator, $text, $message = '') + { + $this->assertContains($text, $this->getValue($locator), $message); + } + + /** + * Asserts that an element does not contain a given string. + * + * @param string $locator + * @param string $text + * @param string $message + * @access public + */ + public function assertElementNotContainsText($locator, $text, $message = '') + { + $this->assertNotContains($text, $this->getValue($locator), $message); + } + + /** + * Asserts than an element is present. + * + * @param string $locator + * @param string $message + * @access public + */ + public function assertElementPresent($locator, $message = '') + { + if ($message == '') { + $message = sprintf( + 'Element "%s" not present.', + $locator + ); + } + + $this->assertTrue($this->isElementPresent($locator), $message); + } + + /** + * Asserts than an element is not present. + * + * @param string $locator + * @param string $message + * @access public + */ + public function assertElementNotPresent($locator, $message = '') + { + if ($message == '') { + $message = sprintf( + 'Element "%s" present.', + $locator + ); + } + + $this->assertFalse($this->isElementPresent($locator), $message); + } + + /** + * Asserts that the location is equal to a specified one. + * + * @param string $location + * @param string $message + * @access public + */ + public function assertLocationEquals($location, $message = '') + { + $this->assertEquals($location, $this->getLocation(), $message); + } + + /** + * Asserts that the location is not equal to a specified one. + * + * @param string $location + * @param string $message + * @access public + */ + public function assertLocationNotEquals($location, $message = '') + { + $this->assertNotEquals($location, $this->getLocation(), $message); + } + + /** + * Asserts than a prompt is present. + * + * @param string $message + * @access public + */ + public function assertPromptPresent($message = 'No prompt present.') + { + $this->assertTrue($this->isPromptPresent(), $message); + } + + /** + * Asserts than no prompt is present. + * + * @param string $message + * @access public + */ + public function assertNoPromptPresent($message = 'Prompt present.') + { + $this->assertFalse($this->isPromptPresent(), $message); + } + + /** + * Asserts that a select element has a specific option. + * + * @param string $selectLocator + * @param string $option + * @param string $message + * @access public + * @since Method available since Release 3.2.0 + */ + public function assertSelectHasOption($selectLocator, $option, $message = '') + { + $this->assertContains($option, $this->getSelectOptions($selectLocator), $message); + } + + /** + * Asserts that a select element does not have a specific option. + * + * @param string $selectLocator + * @param string $option + * @param string $message + * @access public + * @since Method available since Release 3.2.0 + */ + public function assertSelectNotHasOption($selectLocator, $option, $message = '') + { + $this->assertNotContains($option, $this->getSelectOptions($selectLocator), $message); + } + + /** + * Asserts that a specific label is selected. + * + * @param string $selectLocator + * @param string $value + * @param string $message + * @access public + * @since Method available since Release 3.2.0 + */ + public function assertSelected($selectLocator, $option, $message = '') + { + if ($message == '') { + $message = sprintf( + 'Label "%s" not selected in "%s".', + $option, + $selectLocator + ); + } + + $this->assertEquals( + $option, + $this->getSelectedLabel($selectLocator), + $message + ); + } + + /** + * Asserts that a specific label is not selected. + * + * @param string $selectLocator + * @param string $value + * @param string $message + * @access public + * @since Method available since Release 3.2.0 + */ + public function assertNotSelected($selectLocator, $option, $message = '') + { + if ($message == '') { + $message = sprintf( + 'Label "%s" selected in "%s".', + $option, + $selectLocator + ); + } + + $this->assertNotEquals( + $option, + $this->getSelectedLabel($selectLocator), + $message + ); + } + + /** + * Asserts that a specific value is selected. + * + * @param string $selectLocator + * @param string $value + * @param string $message + * @access public + */ + public function assertIsSelected($selectLocator, $value, $message = '') + { + if ($message == '') { + $message = sprintf( + 'Value "%s" not selected in "%s".', + $value, + $selectLocator + ); + } + + $this->assertEquals( + $value, $this->getSelectedValue($selectLocator), + $message + ); + } + + /** + * Asserts that a specific value is not selected. + * + * @param string $selectLocator + * @param string $value + * @param string $message + * @access public + */ + public function assertIsNotSelected($selectLocator, $value, $message = '') + { + if ($message == '') { + $message = sprintf( + 'Value "%s" selected in "%s".', + $value, + $selectLocator + ); + } + + $this->assertNotEquals( + $value, + $this->getSelectedValue($selectLocator), + $message + ); + } + + /** + * Asserts that something is selected. + * + * @param string $selectLocator + * @param string $message + * @access public + */ + public function assertSomethingSelected($selectLocator, $message = '') + { + if ($message == '') { + $message = sprintf( + 'Nothing selected from "%s".', + $selectLocator + ); + } + + $this->assertTrue($this->isSomethingSelected($selectLocator), $message); + } + + /** + * Asserts that nothing is selected. + * + * @param string $selectLocator + * @param string $message + * @access public + */ + public function assertNothingSelected($selectLocator, $message = '') + { + if ($message == '') { + $message = sprintf( + 'Something selected from "%s".', + $selectLocator + ); + } + + $this->assertFalse($this->isSomethingSelected($selectLocator), $message); + } + + /** + * Asserts that a given text is present. + * + * @param string $pattern + * @param string $message + * @access public + */ + public function assertTextPresent($pattern, $message = '') + { + if ($message == '') { + $message = sprintf( + '"%s" not present.', + $pattern + ); + } + + $this->assertTrue($this->isTextPresent($pattern), $message); + } + + /** + * Asserts that a given text is not present. + * + * @param string $pattern + * @param string $message + * @access public + */ + public function assertTextNotPresent($pattern, $message = '') + { + if ($message == '') { + $message = sprintf( + '"%s" present.', + $pattern + ); + } + + $this->assertFalse($this->isTextPresent($pattern), $message); + } + + /** + * Asserts that the title is equal to a given string. + * + * @param string $title + * @param string $message + * @access public + */ + public function assertTitleEquals($title, $message = '') + { + $this->assertEquals($title, $this->getTitle(), $message); + } + + /** + * Asserts that the title is not equal to a given string. + * + * @param string $title + * @param string $message + * @access public + */ + public function assertTitleNotEquals($title, $message = '') + { + $this->assertNotEquals($title, $this->getTitle(), $message); + } + + /** + * Asserts that something is visible. + * + * @param string $locator + * @param string $message + * @access public + */ + public function assertVisible($locator, $message = '') + { + if ($message == '') { + $message = sprintf( + '"%s" not visible.', + $locator + ); + } + + $this->assertTrue($this->isVisible($locator), $message); + } + + /** + * Asserts that something is not visible. + * + * @param string $locator + * @param string $message + * @access public + */ + public function assertNotVisible($locator, $message = '') + { + if ($message == '') { + $message = sprintf( + '"%s" visible.', + $locator + ); + } + + $this->assertFalse($this->isVisible($locator), $message); + } + + /** + * Template Method that is called after Selenium actions. + * + * @param string $action + * @access protected + * @since Method available since Release 3.1.0 + */ + protected function defaultAssertions($action) + { + } + + /** + * Send a command to the Selenium RC server. + * + * @param string $command + * @param array $arguments + * @return string + * @access protected + * @author Shin Ohno + * @author Bjoern Schotte + * @since Method available since Release 3.1.0 + */ + protected function doCommand($command, array $arguments = array()) + { + $url = sprintf( + 'http://%s:%s/selenium-server/driver/?cmd=%s', + $this->host, + $this->port, + urlencode($command) + ); + + for ($i = 0; $i < count($arguments); $i++) { + $argNum = strval($i + 1); + $url .= sprintf('&%s=%s', $argNum, urlencode(trim($arguments[$i]))); + } + + if (isset(self::$sessionId[$this->host][$this->port][$this->browser])) { + $url .= sprintf('&%s=%s', 'sessionId', self::$sessionId[$this->host][$this->port][$this->browser]); + } + + if (!$handle = @fopen($url, 'r')) { + throw new RuntimeException( + 'Could not connect to the Selenium RC server.' + ); + } + + stream_set_blocking($handle, 1); + stream_set_timeout($handle, 0, $this->timeout); + + $info = stream_get_meta_data($handle); + $response = ''; + + while ((!feof($handle)) && (!$info['timed_out'])) { + $response .= fgets($handle, 4096); + $info = stream_get_meta_data($handle); + } + + fclose($handle); + + if (!preg_match('/^OK/', $response)) { + $this->stop(); + + throw new RuntimeException( + 'The response from the Selenium RC server is invalid: ' . $response + ); + } + + return $response; + } + + /** + * Send a command to the Selenium RC server and treat the result + * as a boolean. + * + * @param string $command + * @param array $arguments + * @return boolean + * @access protected + * @author Shin Ohno + * @author Bjoern Schotte + * @since Method available since Release 3.1.0 + */ + protected function getBoolean($command, array $arguments) + { + $result = $this->getString($command, $arguments); + + switch ($result) { + case 'true': return TRUE; + + case 'false': return FALSE; + + default: { + $this->stop(); + + throw new RuntimeException( + 'Result is neither "true" nor "false": ' . PHPUnit_Util_Type::toString($result, TRUE) + ); + } + } + } + + /** + * Send a command to the Selenium RC server and treat the result + * as a number. + * + * @param string $command + * @param array $arguments + * @return numeric + * @access protected + * @author Shin Ohno + * @author Bjoern Schotte + * @since Method available since Release 3.1.0 + */ + protected function getNumber($command, array $arguments) + { + $result = $this->getString($command, $arguments); + + if (!is_numeric($result)) { + $this->stop(); + + throw new RuntimeException( + 'Result is not numeric: ' . PHPUnit_Util_Type::toString($result, TRUE) + ); + } + + return $result; + } + + /** + * Send a command to the Selenium RC server and treat the result + * as a string. + * + * @param string $command + * @param array $arguments + * @return string + * @access protected + * @author Shin Ohno + * @author Bjoern Schotte + * @since Method available since Release 3.1.0 + */ + protected function getString($command, array $arguments) + { + try { + $result = $this->doCommand($command, $arguments); + } + + catch (RuntimeException $e) { + $this->stop(); + + throw $e; + } + + return (strlen($result) > 3) ? substr($result, 3) : ''; + } + + /** + * Send a command to the Selenium RC server and treat the result + * as an array of strings. + * + * @param string $command + * @param array $arguments + * @return array + * @access protected + * @author Shin Ohno + * @author Bjoern Schotte + * @since Method available since Release 3.1.0 + */ + protected function getStringArray($command, array $arguments) + { + $csv = $this->getString($command, $arguments); + $token = ''; + $tokens = array(); + $letters = preg_split('//', $csv, -1, PREG_SPLIT_NO_EMPTY); + $count = count($letters); + + for ($i = 0; $i < $count; $i++) { + $letter = $letters[$i]; + + switch($letter) { + case '\\': { + $letter = $letters[++$i]; + $token .= $letter; + } + break; + + case ',': { + $tokens[] = $token; + $token = ''; + } + break; + + default: { + $token .= $letter; + } + } + } + + $tokens[] = $token; + + return $tokens; + } + + /** + * @return array + * @access protected + * @since Method available since Release 3.2.0 + */ + protected function getCodeCoverage() + { + if (!empty($this->coverageScriptUrl)) { + $url = sprintf( + '%s?PHPUNIT_SELENIUM_TEST_ID=%s', + $this->coverageScriptUrl, + $this->testId + ); + + return $this->matchLocalAndRemotePaths( + eval('return ' . file_get_contents($url) . ';') + ); + } else { + return array(); + } + } + + /** + * @param array $coverage + * @return array + * @access protected + * @author Mattis Stordalen Flister + * @since Method available since Release 3.2.9 + */ + protected function matchLocalAndRemotePaths(array &$coverage) { + $coverageWithLocalPaths = array(); + + foreach($coverage as $originalRemotePath => $value) { + $remotePath = $originalRemotePath; + $separator = $this->findDirectorySeparator($remotePath); + + while (!($localpath = PHPUnit_Util_Filesystem::fileExistsInIncludePath($remotePath)) && + strpos($remotePath, $separator) !== FALSE) { + $remotePath = substr($remotePath, strpos($remotePath, $separator) + 1); + } + + if ($localpath && md5_file($localpath) == $value['md5']) { + $coverageWithLocalPaths[$localpath] = $value; + unset($coverageWithLocalPaths[$localpath]['md5']); + } + } + + return $coverageWithLocalPaths; + } + + /** + * @param string $path + * @return string + * @access protected + * @author Mattis Stordalen Flister + * @since Method available since Release 3.2.9 + */ + protected function findDirectorySeparator($path) { + if (strpos($path, '/') !== FALSE) { + return '/'; + } + + return '\\'; + } + + /** + * @param string $path + * @return array + * @access protected + * @author Mattis Stordalen Flister + * @since Method available since Release 3.2.9 + */ + protected function explodeDirectories($path) { + return explode($this->findDirectorySeparator($path), dirname($path)); + } + + /** + * @param string $action + * @access private + * @since Method available since Release 3.2.0 + */ + private function runDefaultAssertions($action) + { + if (!$this->inDefaultAssertions) { + $this->inDefaultAssertions = TRUE; + $this->defaultAssertions($action); + $this->inDefaultAssertions = FALSE; + } + } +} +?> Property changes on: test/PHPUnit/Extensions/SeleniumTestCase.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Extensions/Database/AbstractTester.php =================================================================== --- test/PHPUnit/Extensions/Database/AbstractTester.php (revision 0) +++ test/PHPUnit/Extensions/Database/AbstractTester.php (revision 0) @@ -0,0 +1,206 @@ +. + * 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 Mike Lively + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id:AbstractDatabaseTester.php 1254 2008-09-02 04:36:15Z mlively $ + * @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/Extensions/Database/ITester.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Can be used as a foundation for new DatabaseTesters. + * + * @category Testing + * @package PHPUnit + * @author Mike Lively + * @copyright 2008 Mike Lively + * @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_Extensions_Database_AbstractTester implements PHPUnit_Extensions_Database_ITester +{ + + /** + * @var PHPUnit_Extensions_Database_Operation_IDatabaseOperation + */ + protected $setUpOperation; + + /** + * @var PHPUnit_Extensions_Database_Operation_IDatabaseOperation + */ + protected $tearDownOperation; + + /** + * @var PHPUnit_Extensions_Database_DataSet_IDataSet + */ + protected $dataSet; + + /** + * @var string + */ + protected $schema; + + /** + * Creates a new database tester. + * + * @param PHPUnit_Extensions_Database_DB_IDatabaseConnection $databaseConnection + */ + public function __construct() + { + $this->setUpOperation = PHPUnit_Extensions_Database_Operation_Factory::CLEAN_INSERT(); + $this->tearDownOperation = PHPUnit_Extensions_Database_Operation_Factory::NONE(); + } + + /** + * Closes the specified connection. + * + * @param PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection + */ + public function closeConnection(PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection) + { + $connection->close(); + } + + /** + * Returns the test dataset. + * + * @return PHPUnit_Extensions_Database_DataSet_IDataSet + */ + public function getDataSet() + { + return $this->dataSet; + } + + /** + * TestCases must call this method inside setUp(). + */ + public function onSetUp() + { + $this->getSetUpOperation()->execute($this->getConnection(), $this->getDataSet()); + } + + /** + * TestCases must call this method inside tearDown(). + */ + public function onTearDown() + { + $this->getTearDownOperation()->execute($this->getConnection(), $this->getDataSet()); + } + + /** + * Sets the test dataset to use. + * + * @param PHPUnit_Extensions_Database_DataSet_IDataSet $dataSet + */ + public function setDataSet(PHPUnit_Extensions_Database_DataSet_IDataSet $dataSet) + { + $this->dataSet = $dataSet; + } + + /** + * Sets the schema value. + * + * @param string $schema + */ + public function setSchema($schema) + { + $this->schema = $schema; + } + + /** + * Sets the DatabaseOperation to call when starting the test. + * + * @param PHPUnit_Extensions_Database_Operation_DatabaseOperation $setUpOperation + */ + public function setSetUpOperation(PHPUnit_Extensions_Database_Operation_IDatabaseOperation $setUpOperation) + { + $this->setUpOperation = $setUpOperation; + } + + /** + * Sets the DatabaseOperation to call when ending the test. + * + * @param PHPUnit_Extensions_Database_Operation_DatabaseOperation $tearDownOperation + */ + public function setTearDownOperation(PHPUnit_Extensions_Database_Operation_IDatabaseOperation $tearDownOperation) + { + $this->tearDownOperation = $tearDownOperation; + } + + /** + * Returns the schema value + * + * @return string + */ + protected function getSchema() + { + return $this->schema; + } + + /** + * Returns the database operation that will be called when starting the test. + * + * @return PHPUnit_Extensions_Database_Operation_DatabaseOperation + */ + protected function getSetUpOperation() + { + return $this->setUpOperation; + } + + /** + * Returns the database operation that will be called when ending the test. + * + * @return PHPUnit_Extensions_Database_Operation_DatabaseOperation + */ + protected function getTearDownOperation() + { + return $this->tearDownOperation; + } +} +?> Property changes on: test/PHPUnit/Extensions/Database/AbstractTester.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Extensions/Database/Operation/Null.php =================================================================== --- test/PHPUnit/Extensions/Database/Operation/Null.php (revision 0) +++ test/PHPUnit/Extensions/Database/Operation/Null.php (revision 0) @@ -0,0 +1,74 @@ +. + * 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 Mike Lively + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: Null.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/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; + +require_once 'PHPUnit/Extensions/Database/Operation/IDatabaseOperation.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * This class represents a null database operation. + * + * @category Testing + * @package PHPUnit + * @author Mike Lively + * @copyright 2002-2008 Sebastian Bergmann + * @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_Extensions_Database_Operation_Null implements PHPUnit_Extensions_Database_Operation_IDatabaseOperation +{ + + public function execute(PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection, PHPUnit_Extensions_Database_DataSet_IDataSet $dataSet) + { + /* do nothing */ + } +} +?> Property changes on: test/PHPUnit/Extensions/Database/Operation/Null.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Extensions/Database/Operation/DeleteAll.php =================================================================== --- test/PHPUnit/Extensions/Database/Operation/DeleteAll.php (revision 0) +++ test/PHPUnit/Extensions/Database/Operation/DeleteAll.php (revision 0) @@ -0,0 +1,87 @@ +. + * 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 Mike Lively + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: DeleteAll.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/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; + +require_once 'PHPUnit/Extensions/Database/Operation/IDatabaseOperation.php'; +require_once 'PHPUnit/Extensions/Database/Operation/Exception.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Deletes all rows from all tables in a dataset. + * + * @category Testing + * @package PHPUnit + * @author Mike Lively + * @copyright 2008 Mike Lively + * @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_Extensions_Database_Operation_DeleteAll implements PHPUnit_Extensions_Database_Operation_IDatabaseOperation +{ + + public function execute(PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection, PHPUnit_Extensions_Database_DataSet_IDataSet $dataSet) + { + foreach ($dataSet as $table) { + /* @var $table PHPUnit_Extensions_Database_DataSet_ITable */ + + $query = " + DELETE FROM {$connection->quoteSchemaObject($table->getTableMetaData()->getTableName())} + "; + + try { + $connection->getConnection()->query($query); + } catch (PDOException $e) { + throw new PHPUnit_Extensions_Database_Operation_Exception('DELETE_ALL', $query, array(), $table, $e->getMessage()); + } + } + } +} +?> Property changes on: test/PHPUnit/Extensions/Database/Operation/DeleteAll.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Extensions/Database/Operation/Replace.php =================================================================== --- test/PHPUnit/Extensions/Database/Operation/Replace.php (revision 0) +++ test/PHPUnit/Extensions/Database/Operation/Replace.php (revision 0) @@ -0,0 +1,148 @@ +. + * 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 Mike Lively + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: Replace.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/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; + +require_once 'PHPUnit/Extensions/Database/Operation/RowBased.php'; +require_once 'PHPUnit/Extensions/Database/Operation/Insert.php'; +require_once 'PHPUnit/Extensions/Database/Operation/Update.php'; +require_once 'PHPUnit/Extensions/Database/Operation/Exception.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Updates the rows in a given dataset using primary key columns. + * + * @category Testing + * @package PHPUnit + * @author Mike Lively + * @copyright 2008 Mike Lively + * @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_Extensions_Database_Operation_Replace extends PHPUnit_Extensions_Database_Operation_RowBased +{ + + protected $operationName = 'REPLACE'; + + protected function buildOperationQuery(PHPUnit_Extensions_Database_DataSet_ITableMetaData $databaseTableMetaData, PHPUnit_Extensions_Database_DataSet_ITable $table, PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection) + { + $keys = $databaseTableMetaData->getPrimaryKeys(); + + $whereStatement = 'WHERE ' . implode(' AND ', $this->buildPreparedColumnArray($keys, $connection)); + + $query = " + SELECT COUNT(*) + FROM {$connection->quoteSchemaObject($table->getTableMetaData()->getTableName())} + {$whereStatement} + "; + + return $query; + } + + protected function buildOperationArguments(PHPUnit_Extensions_Database_DataSet_ITableMetaData $databaseTableMetaData, PHPUnit_Extensions_Database_DataSet_ITable $table, $row) + { + $args = array(); + + foreach ($databaseTableMetaData->getPrimaryKeys() as $columnName) { + $args[] = $table->getValue($row, $columnName); + } + + return $args; + } + + /** + * @param PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection + * @param PHPUnit_Extensions_Database_DataSet_IDataSet $dataSet + */ + public function execute(PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection, PHPUnit_Extensions_Database_DataSet_IDataSet $dataSet) + { + $insertOperation = new PHPUnit_Extensions_Database_Operation_Insert(); + $updateOperation = new PHPUnit_Extensions_Database_Operation_Update(); + + $databaseDataSet = $connection->createDataSet(); + + foreach ($dataSet as $table) { + /* @var $table PHPUnit_Extensions_Database_DataSet_ITable */ + $databaseTableMetaData = $databaseDataSet->getTableMetaData($table->getTableMetaData()->getTableName()); + + $insertQuery = $insertOperation->buildOperationQuery($databaseTableMetaData, $table, $connection); + $updateQuery = $updateOperation->buildOperationQuery($databaseTableMetaData, $table, $connection); + $selectQuery = $this->buildOperationQuery($databaseTableMetaData, $table, $connection); + + $insertStatement = $connection->getConnection()->prepare($insertQuery); + $updateStatement = $connection->getConnection()->prepare($updateQuery); + $selectStatement = $connection->getConnection()->prepare($selectQuery); + + for ($i = 0; $i < $table->getRowCount(); $i++) { + $selectArgs = $this->buildOperationArguments($databaseTableMetaData, $table, $i); + $query = $selectQuery; + $args = $selectArgs; + try { + $selectStatement->execute($selectArgs); + + if ($selectStatement->fetchColumn(0) > 0) { + $updateArgs = $updateOperation->buildOperationArguments($databaseTableMetaData, $table, $i); + $query = $updateQuery; + $args = $updateArgs; + $updateStatement->execute($updateArgs); + } else { + $insertArgs = $insertOperation->buildOperationArguments($databaseTableMetaData, $table, $i); + $query = $insertQuery; + $args = $insertArgs; + $insertStatement->execute($insertArgs); + } + } catch (Exception $e) { + throw new PHPUnit_Extensions_Database_Operation_Exception($this->operationName, $query, $args, $table, $e->getMessage()); + } + } + } + } +} +?> Property changes on: test/PHPUnit/Extensions/Database/Operation/Replace.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Extensions/Database/Operation/Exception.php =================================================================== --- test/PHPUnit/Extensions/Database/Operation/Exception.php (revision 0) +++ test/PHPUnit/Extensions/Database/Operation/Exception.php (revision 0) @@ -0,0 +1,137 @@ +. + * 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 Mike Lively + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: Exception.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/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Thrown for exceptions encountered with database operations. Provides + * information regarding which operations failed and the query (if any) it + * failed on. + * + * @category Testing + * @package PHPUnit + * @author Mike Lively + * @copyright 2008 Mike Lively + * @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_Extensions_Database_Operation_Exception extends RuntimeException +{ + + /** + * @var string + */ + protected $operation; + + /** + * @var string + */ + protected $preparedQuery; + + /** + * @var array + */ + protected $preparedArgs; + + /** + * @var PHPUnit_Extensions_Database_DataSet_ITable + */ + protected $table; + + /** + * @var string + */ + protected $error; + + /** + * Creates a new dbunit operation exception + * + * @param string $operation + * @param string $current_query + * @param PHPUnit_Extensions_Database_DataSet_ITable $current_table + * @param string $error + */ + public function __construct($operation, $current_query, $current_args, $current_table, $error) + { + parent::__construct("{$operation} operation failed on query: {$current_query} using args: " . print_r($current_args, true) . " [{$error}]"); + $this->operation = $operation; + $this->preparedQuery = $current_query; + $this->preparedArgs = $current_args; + $this->table = $current_table; + $this->error = $error; + } + + public function getOperation() + { + return $this->operation; + } + + public function getQuery() + { + return $this->preparedQuery; + } + + public function getTable() + { + return $this->table; + } + + public function getArgs() + { + return $this->preparedArgs; + } + + public function getError() + { + return $this->error; + } +} +?> Property changes on: test/PHPUnit/Extensions/Database/Operation/Exception.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Extensions/Database/Operation/IDatabaseOperation.php =================================================================== --- test/PHPUnit/Extensions/Database/Operation/IDatabaseOperation.php (revision 0) +++ test/PHPUnit/Extensions/Database/Operation/IDatabaseOperation.php (revision 0) @@ -0,0 +1,78 @@ +. + * 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 Mike Lively + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: IDatabaseOperation.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/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Provides a basic interface and functionality for executing database + * operations against a connection using a specific dataSet. + * + * @category Testing + * @package PHPUnit + * @author Mike Lively + * @copyright 2008 Mike Lively + * @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 + */ +interface PHPUnit_Extensions_Database_Operation_IDatabaseOperation +{ + + /** + * Executes the database operation against the given $connection for the + * given $dataSet. + * + * @param PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection + * @param PHPUnit_Extensions_Database_DataSet_IDataSet $dataSet + * @throws PHPUnit_Extensions_Database_Operation_Exception + */ + public function execute(PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection, PHPUnit_Extensions_Database_DataSet_IDataSet $dataSet); +} +?> Property changes on: test/PHPUnit/Extensions/Database/Operation/IDatabaseOperation.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Extensions/Database/Operation/Composite.php =================================================================== --- test/PHPUnit/Extensions/Database/Operation/Composite.php (revision 0) +++ test/PHPUnit/Extensions/Database/Operation/Composite.php (revision 0) @@ -0,0 +1,106 @@ +. + * 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 Mike Lively + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: Composite.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/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; + +require_once 'PHPUnit/Extensions/Database/Operation/IDatabaseOperation.php'; +require_once 'PHPUnit/Extensions/Database/Operation/Exception.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * This class facilitates combining database operations. To create a composite + * operation pass an array of classes that implement + * PHPUnit_Extensions_Database_Operation_IDatabaseOperation and they will be + * executed in that order against all data sets. + * + * @category Testing + * @package PHPUnit + * @author Mike Lively + * @copyright 2008 Mike Lively + * @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_Extensions_Database_Operation_Composite implements PHPUnit_Extensions_Database_Operation_IDatabaseOperation +{ + + /** + * @var array + */ + protected $operations = array(); + + /** + * Creates a composite operation. + * + * @param array $operations + */ + public function __construct(Array $operations) + { + foreach ($operations as $operation) { + if ($operation instanceof PHPUnit_Extensions_Database_Operation_IDatabaseOperation) { + $this->operations[] = $operation; + } else { + throw new InvalidArgumentException("Only database operation instances can be passed to a composite database operation."); + } + } + } + + public function execute(PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection, PHPUnit_Extensions_Database_DataSet_IDataSet $dataSet) + { + try { + foreach ($this->operations as $operation) { + /* @var $operation PHPUnit_Extensions_Database_Operation_IDatabaseOperation */ + $operation->execute($connection, $dataSet); + } + } catch (PHPUnit_Extensions_Database_Operation_Exception $e) { + throw new PHPUnit_Extensions_Database_Operation_Exception("COMPOSITE[{$e->getOperation()}]", $e->getQuery(), $e->getArgs(), $e->getTable(), $e->getError()); + } + } +} +?> Property changes on: test/PHPUnit/Extensions/Database/Operation/Composite.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Extensions/Database/Operation/Delete.php =================================================================== --- test/PHPUnit/Extensions/Database/Operation/Delete.php (revision 0) +++ test/PHPUnit/Extensions/Database/Operation/Delete.php (revision 0) @@ -0,0 +1,96 @@ +. + * 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 Mike Lively + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: Delete.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/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; + +require_once 'PHPUnit/Extensions/Database/Operation/IDatabaseOperation.php'; +require_once 'PHPUnit/Extensions/Database/Operation/Exception.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Deletes the rows in a given dataset using primary key columns. + * + * @category Testing + * @package PHPUnit + * @author Mike Lively + * @copyright 2008 Mike Lively + * @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_Extensions_Database_Operation_Delete extends PHPUnit_Extensions_Database_Operation_RowBased +{ + + protected $operationName = 'DELETE'; + + protected function buildOperationQuery(PHPUnit_Extensions_Database_DataSet_ITableMetaData $databaseTableMetaData, PHPUnit_Extensions_Database_DataSet_ITable $table, PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection) + { + $keys = $databaseTableMetaData->getPrimaryKeys(); + + $whereStatement = 'WHERE ' . implode(' AND ', $this->buildPreparedColumnArray($keys, $connection)); + + $query = " + DELETE FROM {$connection->quoteSchemaObject($table->getTableMetaData()->getTableName())} + {$whereStatement} + "; + + return $query; + } + + protected function buildOperationArguments(PHPUnit_Extensions_Database_DataSet_ITableMetaData $databaseTableMetaData, PHPUnit_Extensions_Database_DataSet_ITable $table, $row) + { + $args = array(); + foreach ($databaseTableMetaData->getPrimaryKeys() as $columnName) { + $args[] = $table->getValue($row, $columnName); + } + + return $args; + } +} +?> Property changes on: test/PHPUnit/Extensions/Database/Operation/Delete.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Extensions/Database/Operation/Update.php =================================================================== --- test/PHPUnit/Extensions/Database/Operation/Update.php (revision 0) +++ test/PHPUnit/Extensions/Database/Operation/Update.php (revision 0) @@ -0,0 +1,103 @@ +. + * 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 Mike Lively + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: Update.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/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; + +require_once 'PHPUnit/Extensions/Database/Operation/RowBased.php'; +require_once 'PHPUnit/Extensions/Database/Operation/Exception.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Updates the rows in a given dataset using primary key columns. + * + * @category Testing + * @package PHPUnit + * @author Mike Lively + * @copyright 2008 Mike Lively + * @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_Extensions_Database_Operation_Update extends PHPUnit_Extensions_Database_Operation_RowBased +{ + + protected $operationName = 'UPDATE'; + + protected function buildOperationQuery(PHPUnit_Extensions_Database_DataSet_ITableMetaData $databaseTableMetaData, PHPUnit_Extensions_Database_DataSet_ITable $table, PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection) + { + $keys = $databaseTableMetaData->getPrimaryKeys(); + $columns = $table->getTableMetaData()->getColumns(); + + $whereStatement = 'WHERE ' . implode(' AND ', $this->buildPreparedColumnArray($keys, $connection)); + $setStatement = 'SET ' . implode(', ', $this->buildPreparedColumnArray($columns, $connection)); + + $query = " + UPDATE {$connection->quoteSchemaObject($table->getTableMetaData()->getTableName())} + {$setStatement} + {$whereStatement} + "; + + return $query; + } + + protected function buildOperationArguments(PHPUnit_Extensions_Database_DataSet_ITableMetaData $databaseTableMetaData, PHPUnit_Extensions_Database_DataSet_ITable $table, $row) + { + $args = array(); + foreach ($table->getTableMetaData()->getColumns() as $columnName) { + $args[] = $table->getValue($row, $columnName); + } + + foreach ($databaseTableMetaData->getPrimaryKeys() as $columnName) { + $args[] = $table->getValue($row, $columnName); + } + + return $args; + } +} +?> Property changes on: test/PHPUnit/Extensions/Database/Operation/Update.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Extensions/Database/Operation/Insert.php =================================================================== --- test/PHPUnit/Extensions/Database/Operation/Insert.php (revision 0) +++ test/PHPUnit/Extensions/Database/Operation/Insert.php (revision 0) @@ -0,0 +1,103 @@ +. + * 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 Mike Lively + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: Insert.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/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; + +require_once 'PHPUnit/Extensions/Database/Operation/RowBased.php'; +require_once 'PHPUnit/Extensions/Database/Operation/Exception.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * This class provides functionality for inserting rows from a dataset into a database. + * + * @category Testing + * @package PHPUnit + * @author Mike Lively + * @copyright 2008 Mike Lively + * @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_Extensions_Database_Operation_Insert extends PHPUnit_Extensions_Database_Operation_RowBased +{ + + protected $operationName = 'INSERT'; + + protected function buildOperationQuery(PHPUnit_Extensions_Database_DataSet_ITableMetaData $databaseTableMetaData, PHPUnit_Extensions_Database_DataSet_ITable $table, PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection) + { + $placeHolders = implode(', ', array_fill(0, count($table->getTableMetaData()->getColumns()), '?')); + + $columns = ''; + foreach ($table->getTableMetaData()->getColumns() as $column) + { + $columns .= $connection->quoteSchemaObject($column).', '; + } + + $columns = substr($columns, 0, -2); + + $query = " + INSERT INTO {$connection->quoteSchemaObject($table->getTableMetaData()->getTableName())} + ({$columns}) + VALUES + ({$placeHolders}) + "; + + return $query; + } + + protected function buildOperationArguments(PHPUnit_Extensions_Database_DataSet_ITableMetaData $databaseTableMetaData, PHPUnit_Extensions_Database_DataSet_ITable $table, $row) + { + $args = array(); + foreach ($table->getTableMetaData()->getColumns() as $columnName) { + $args[] = $table->getValue($row, $columnName); + } + return $args; + } +} +?> Property changes on: test/PHPUnit/Extensions/Database/Operation/Insert.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Extensions/Database/Operation/Truncate.php =================================================================== --- test/PHPUnit/Extensions/Database/Operation/Truncate.php (revision 0) +++ test/PHPUnit/Extensions/Database/Operation/Truncate.php (revision 0) @@ -0,0 +1,86 @@ +. + * 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 Mike Lively + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: Truncate.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/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; + +require_once 'PHPUnit/Extensions/Database/Operation/IDatabaseOperation.php'; +require_once 'PHPUnit/Extensions/Database/Operation/Exception.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Executes a truncate against all tables in a dataset. + * + * @category Testing + * @package PHPUnit + * @author Mike Lively + * @copyright 2008 Mike Lively + * @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_Extensions_Database_Operation_Truncate implements PHPUnit_Extensions_Database_Operation_IDatabaseOperation +{ + + public function execute(PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection, PHPUnit_Extensions_Database_DataSet_IDataSet $dataSet) + { + foreach ($dataSet as $table) { + /* @var $table PHPUnit_Extensions_Database_DataSet_ITable */ + $query = " + DELETE FROM {$connection->quoteSchemaObject($table->getTableMetaData()->getTableName())} + "; + + try { + $connection->getConnection()->query($query); + } catch (PDOException $e) { + throw new PHPUnit_Extensions_Database_Operation_Exception('TRUNCATE', $query, array(), $table, $e->getMessage()); + } + } + } +} +?> Property changes on: test/PHPUnit/Extensions/Database/Operation/Truncate.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Extensions/Database/Operation/RowBased.php =================================================================== --- test/PHPUnit/Extensions/Database/Operation/RowBased.php (revision 0) +++ test/PHPUnit/Extensions/Database/Operation/RowBased.php (revision 0) @@ -0,0 +1,113 @@ +. + * 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 Mike Lively + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: RowBased.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/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; + +require_once 'PHPUnit/Extensions/Database/Operation/IDatabaseOperation.php'; +require_once 'PHPUnit/Extensions/Database/Operation/Exception.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Provides basic functionality for row based operations. + * + * To create a row based operation you must create two functions. The first + * one, buildOperationQuery(), must return a query that will be used to create + * a prepared statement. The second one, buildOperationArguments(), should + * return an array containing arguments for each row. + * + * @category Testing + * @package PHPUnit + * @author Mike Lively + * @copyright 2008 Mike Lively + * @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_Extensions_Database_Operation_RowBased implements PHPUnit_Extensions_Database_Operation_IDatabaseOperation +{ + + protected $operationName; + + protected abstract function buildOperationQuery(PHPUnit_Extensions_Database_DataSet_ITableMetaData $databaseTableMetaData, PHPUnit_Extensions_Database_DataSet_ITable $table, PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection); + + protected abstract function buildOperationArguments(PHPUnit_Extensions_Database_DataSet_ITableMetaData $databaseTableMetaData, PHPUnit_Extensions_Database_DataSet_ITable $table, $row); + + /** + * @param PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection + * @param PHPUnit_Extensions_Database_DataSet_IDataSet $dataSet + */ + public function execute(PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection, PHPUnit_Extensions_Database_DataSet_IDataSet $dataSet) + { + $databaseDataSet = $connection->createDataSet(); + foreach ($dataSet as $table) { + /* @var $table PHPUnit_Extensions_Database_DataSet_ITable */ + $databaseTableMetaData = $databaseDataSet->getTableMetaData($table->getTableMetaData()->getTableName()); + $query = $this->buildOperationQuery($databaseTableMetaData, $table, $connection); + $statement = $connection->getConnection()->prepare($query); + for ($i = 0; $i < $table->getRowCount(); $i++) { + $args = $this->buildOperationArguments($databaseTableMetaData, $table, $i); + try { + $statement->execute($args); + } catch (Exception $e) { + throw new PHPUnit_Extensions_Database_Operation_Exception($this->operationName, $query, $args, $table, $e->getMessage()); + } + } + } + } + + protected function buildPreparedColumnArray($columns, PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection) + { + $columnArray = array(); + foreach ($columns as $columnName) { + $columnArray[] = "{$connection->quoteSchemaObject($columnName)} = ?"; + } + return $columnArray; + } +} +?> Property changes on: test/PHPUnit/Extensions/Database/Operation/RowBased.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Extensions/Database/Operation/Factory.php =================================================================== --- test/PHPUnit/Extensions/Database/Operation/Factory.php (revision 0) +++ test/PHPUnit/Extensions/Database/Operation/Factory.php (revision 0) @@ -0,0 +1,148 @@ +. + * 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 Mike Lively + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: Factory.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/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; + +require_once 'PHPUnit/Extensions/Database/Operation/IDatabaseOperation.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +require_once 'PHPUnit/Extensions/Database/Operation/Null.php'; +require_once 'PHPUnit/Extensions/Database/Operation/Composite.php'; +require_once 'PHPUnit/Extensions/Database/Operation/Insert.php'; +require_once 'PHPUnit/Extensions/Database/Operation/Truncate.php'; +require_once 'PHPUnit/Extensions/Database/Operation/DeleteAll.php'; +require_once 'PHPUnit/Extensions/Database/Operation/Delete.php'; + +/** + * A class factory to easily return database operations. + * + * @category Testing + * @package PHPUnit + * @author Mike Lively + * @copyright 2008 Mike Lively + * @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_Extensions_Database_Operation_Factory +{ + + /** + * Returns a null database operation + * + * @return PHPUnit_Extensions_Database_Operation_IDatabaseOperation + */ + public static function NONE() + { + return new PHPUnit_Extensions_Database_Operation_Null(); + } + + /** + * Returns a clean insert database operation. It will remove all contents + * from the table prior to re-inserting rows. + * + * @return PHPUnit_Extensions_Database_Operation_IDatabaseOperation + */ + public static function CLEAN_INSERT() + { + return new PHPUnit_Extensions_Database_Operation_Composite(array(new PHPUnit_Extensions_Database_Operation_Truncate(), new PHPUnit_Extensions_Database_Operation_Insert())); + } + + /** + * Returns an insert database operation. + * + * @return PHPUnit_Extensions_Database_Operation_IDatabaseOperation + */ + public static function INSERT() + { + return new PHPUnit_Extensions_Database_Operation_Insert(); + } + + /** + * Returns a truncate database operation. + * + * @return PHPUnit_Extensions_Database_Operation_IDatabaseOperation + */ + public static function TRUNCATE() + { + return new PHPUnit_Extensions_Database_Operation_Truncate(); + } + + /** + * Returns a delete database operation. + * + * @return PHPUnit_Extensions_Database_Operation_IDatabaseOperation + */ + public static function DELETE() + { + return new PHPUnit_Extensions_Database_Operation_Delete(); + } + + /** + * Returns a delete_all database operation. + * + * @return PHPUnit_Extensions_Database_Operation_IDatabaseOperation + */ + public static function DELETE_ALL() + { + return new PHPUnit_Extensions_Database_Operation_DeleteAll(); + } + + /** + * Returns an update database operation. + * + * @return PHPUnit_Extensions_Database_Operation_IDatabaseOperation + */ + public static function UPDATE() + { + return new PHPUnit_Extensions_Database_Operation_Update(); + } + +} +?> Property changes on: test/PHPUnit/Extensions/Database/Operation/Factory.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Extensions/Database/DefaultTester.php =================================================================== --- test/PHPUnit/Extensions/Database/DefaultTester.php (revision 0) +++ test/PHPUnit/Extensions/Database/DefaultTester.php (revision 0) @@ -0,0 +1,95 @@ +. + * 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 Mike Lively + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id:DefaultDatabaseTester.php 1254 2008-09-02 04:36:15Z mlively $ + * @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/Extensions/Database/AbstractTester.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * This is the default implementation of the database tester. It receives its + * connection object from the constructor. + * + * @category Testing + * @package PHPUnit + * @author Mike Lively + * @copyright 2008 Mike Lively + * @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_Extensions_Database_DefaultTester extends PHPUnit_Extensions_Database_AbstractTester +{ + + /** + * @var PHPUnit_Extensions_Database_DB_IDatabaseConnection + */ + protected $connection; + + /** + * Creates a new default database tester using the given connection. + * + * @param PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection + */ + public function __construct(PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection) + { + $this->connection = $connection; + } + + /** + * Returns the test database connection. + * + * @return PHPUnit_Extensions_Database_DB_IDatabaseConnection + */ + public function getConnection() + { + return $this->connection; + } +} +?> Property changes on: test/PHPUnit/Extensions/Database/DefaultTester.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Extensions/Database/TestCase.php =================================================================== --- test/PHPUnit/Extensions/Database/TestCase.php (revision 0) +++ test/PHPUnit/Extensions/Database/TestCase.php (revision 0) @@ -0,0 +1,248 @@ +. + * 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 Mike Lively + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: TestCase.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/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; + +require_once 'PHPUnit/Extensions/Database/DefaultTester.php'; +require_once 'PHPUnit/Extensions/Database/DB/DefaultDatabaseConnection.php'; +require_once 'PHPUnit/Extensions/Database/Operation/Factory.php'; +require_once 'PHPUnit/Extensions/Database/Constraint/TableIsEqual.php'; +require_once 'PHPUnit/Extensions/Database/Constraint/DataSetIsEqual.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * A TestCase extension that provides functionality for testing and asserting + * against a real database. + * + * @category Testing + * @package PHPUnit + * @author Mike Lively + * @copyright 2008 Mike Lively + * @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_Extensions_Database_TestCase extends PHPUnit_Framework_TestCase +{ + + /** + * @var PHPUnit_Extensions_Database_ITester + */ + protected $databaseTester; + + /** + * Closes the specified connection. + * + * @param PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection + */ + protected function closeConnection(PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection) + { + $this->getDatabaseTester()->closeConnection($connection); + } + + /** + * Returns the test database connection. + * + * @return PHPUnit_Extensions_Database_DB_IDatabaseConnection + */ + protected abstract function getConnection(); + + /** + * Gets the IDatabaseTester for this testCase. If the IDatabaseTester is + * not set yet, this method calls newDatabaseTester() to obtain a new + * instance. + * + * @return PHPUnit_Extensions_Database_ITester + */ + protected function getDatabaseTester() + { + if (empty($this->databaseTester)) { + $this->databaseTester = $this->newDatabaseTester(); + } + + return $this->databaseTester; + } + + /** + * Returns the test dataset. + * + * @return PHPUnit_Extensions_Database_DataSet_IDataSet + */ + protected abstract function getDataSet(); + + /** + * Returns the database operation executed in test setup. + * + * @return PHPUnit_Extensions_Database_Operation_DatabaseOperation + */ + protected function getSetUpOperation() + { + return PHPUnit_Extensions_Database_Operation_Factory::CLEAN_INSERT(); + } + + /** + * Returns the database operation executed in test cleanup. + * + * @return PHPUnit_Extensions_Database_Operation_DatabaseOperation + */ + protected function getTearDownOperation() + { + return PHPUnit_Extensions_Database_Operation_Factory::NONE(); + } + + /** + * Creates a IDatabaseTester for this testCase. + * + * @return PHPUnit_Extensions_Database_ITester + */ + protected function newDatabaseTester() + { + return new PHPUnit_Extensions_Database_DefaultTester($this->getConnection()); + } + + /** + * Creates a new DefaultDatabaseConnection using the given PDO connection + * and database schema name. + * + * @param PDO $connection + * @param string $schema + * @return PHPUnit_Extensions_Database_DB_DefaultDatabaseConnection + */ + protected function createDefaultDBConnection(PDO $connection, $schema) + { + return new PHPUnit_Extensions_Database_DB_DefaultDatabaseConnection($connection, $schema); + } + + /** + * Creates a new FlatXmlDataSet with the given $xmlFile. (absolute path.) + * + * @param string $xmlFile + * @return PHPUnit_Extensions_Database_DataSet_FlatXmlDataSet + */ + protected function createFlatXMLDataSet($xmlFile) + { + require_once 'PHPUnit/Extensions/Database/DataSet/FlatXmlDataSet.php'; + return new PHPUnit_Extensions_Database_DataSet_FlatXmlDataSet($xmlFile); + } + + /** + * Creates a new XMLDataSet with the given $xmlFile. (absolute path.) + * + * @param string $xmlFile + * @return PHPUnit_Extensions_Database_DataSet_XmlDataSet + */ + protected function createXMLDataSet($xmlFile) + { + require_once 'PHPUnit/Extensions/Database/DataSet/XmlDataSet.php'; + return new PHPUnit_Extensions_Database_DataSet_XmlDataSet($xmlFile); + } + + /** + * Returns an operation factory instance that can be used to instantiate + * new operations. + * + * @return PHPUnit_Extensions_Database_Operation_Factory + */ + protected function getOperations() + { + require_once 'PHPUnit/Extensions/Database/Operation/Factory.php'; + return new PHPUnit_Extensions_Database_Operation_Factory(); + } + + /** + * Performs operation returned by getSetUpOperation(). + */ + protected function setUp() + { + parent::setUp(); + + $this->getDatabaseTester()->setSetUpOperation($this->getSetUpOperation()); + $this->getDatabaseTester()->setDataSet($this->getDataSet()); + $this->getDatabaseTester()->onSetUp(); + } + + /** + * Performs operation returned by getSetUpOperation(). + */ + protected function tearDown() + { + $this->getDatabaseTester()->setTearDownOperation($this->getTearDownOperation()); + $this->getDatabaseTester()->setDataSet($this->getDataSet()); + $this->getDatabaseTester()->onTearDown(); + } + + /** + * Asserts that two given tables are equal. + * + * @param PHPUnit_Extensions_Database_DataSet_ITable $expected + * @param PHPUnit_Extensions_Database_DataSet_ITable $actual + * @param string $message + */ + public static function assertTablesEqual(PHPUnit_Extensions_Database_DataSet_ITable $expected, PHPUnit_Extensions_Database_DataSet_ITable $actual, $message = '') + { + $constraint = new PHPUnit_Extensions_Database_Constraint_TableIsEqual($expected); + + self::assertThat($actual, $constraint, $message); + } + + /** + * Asserts that two given datasets are equal. + * + * @param PHPUnit_Extensions_Database_DataSet_ITable $expected + * @param PHPUnit_Extensions_Database_DataSet_ITable $actual + * @param string $message + */ + public static function assertDataSetsEqual(PHPUnit_Extensions_Database_DataSet_IDataSet $expected, PHPUnit_Extensions_Database_DataSet_IDataSet $actual, $message = '') + { + $constraint = new PHPUnit_Extensions_Database_Constraint_DataSetIsEqual($expected); + + self::assertThat($actual, $constraint, $message); + } +} +?> Property changes on: test/PHPUnit/Extensions/Database/TestCase.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Extensions/Database/Constraint/DataSetIsEqual.php =================================================================== --- test/PHPUnit/Extensions/Database/Constraint/DataSetIsEqual.php (revision 0) +++ test/PHPUnit/Extensions/Database/Constraint/DataSetIsEqual.php (revision 0) @@ -0,0 +1,148 @@ +. + * 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 Mike Lively + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: DataSetIsEqual.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/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; +require_once 'PHPUnit/Framework/Constraint.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Asserts whether or not two dbunit datasets are equal. + * + * @category Testing + * @package PHPUnit + * @author Mike Lively + * @copyright 2008 Mike Lively + * @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_Extensions_Database_Constraint_DataSetIsEqual extends PHPUnit_Framework_Constraint +{ + + /** + * @var PHPUnit_Extensions_Database_DataSet_IDataSet + */ + protected $value; + + /** + * @var string + */ + protected $failure_reason; + + /** + * Creates a new constraint. + * + * @param PHPUnit_Extensions_Database_DataSet_IDataSet $value + */ + public function __construct(PHPUnit_Extensions_Database_DataSet_IDataSet $value) + { + $this->value = $value; + } + + /** + * Determines whether or not the given dataset matches the dataset used to + * create this constraint. + * + * @param PHPUnit_Extensions_Database_DataSet_IDataSet $other + * @return bool + */ + public function evaluate($other) + { + if ($other instanceof PHPUnit_Extensions_Database_DataSet_IDataSet) { + try { + $this->value->assertEquals($other); + return TRUE; + } catch (Exception $e) { + $this->failure_reason = $e->getMessage(); + return FALSE; + } + } else { + throw new InvalidArgumentException("PHPUnit_Extensions_Database_DataSet_IDataSet expected"); + } + } + + /** + * @param mixed $other The value passed to evaluate() which failed the + * constraint check. + * @param string $description A string with extra description of what was + * going on while the evaluation failed. + * @param boolean $not Flag to indicate negation. + * @throws PHPUnit_Framework_ExpectationFailedException + */ + protected function failureDescription($other, $description, $not) + { + $failureDescription = sprintf('Failed asserting that %s %s Reason: %s', + $other->__toString(), + $this->toString(), + $this->failure_reason); + + if ($not) { + $failureDescription = self::negate($failureDescription); + } + + if (!empty($description)) { + $failureDescription = $description . "\n" . $failureDescription; + } + + return $failureDescription; + } + + /** + * Returns a string representation of the constraint. + * + * @return string + * @access public + */ + public function toString() + { + return sprintf('is equal to %s', + $this->value->__toString()); + } +} +?> Property changes on: test/PHPUnit/Extensions/Database/Constraint/DataSetIsEqual.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Extensions/Database/Constraint/TableIsEqual.php =================================================================== --- test/PHPUnit/Extensions/Database/Constraint/TableIsEqual.php (revision 0) +++ test/PHPUnit/Extensions/Database/Constraint/TableIsEqual.php (revision 0) @@ -0,0 +1,150 @@ +. + * 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 Mike Lively + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: TableIsEqual.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/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; +require_once 'PHPUnit/Framework/Constraint.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Asserts whether or not two dbunit tables are equal. + * + * @category Testing + * @package PHPUnit + * @author Mike Lively + * @copyright 2008 Mike Lively + * @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_Extensions_Database_Constraint_TableIsEqual extends PHPUnit_Framework_Constraint +{ + + /** + * @var PHPUnit_Extensions_Database_DataSet_ITable + */ + protected $value; + + /** + * @var string + */ + protected $failure_reason; + + /** + * Creates a new constraint. + * + * @param PHPUnit_Extensions_Database_DataSet_ITable $value + */ + public function __construct(PHPUnit_Extensions_Database_DataSet_ITable $value) + { + $this->value = $value; + } + + /** + * Determines whether or not the given table matches the table used to + * create this constraint. + * + * @param PHPUnit_Extensions_Database_DataSet_ITable $other + * @return bool + */ + public function evaluate($other) + { + if ($other instanceof PHPUnit_Extensions_Database_DataSet_ITable) { + try { + $this->value->assertEquals($other); + return TRUE; + } catch (Exception $e) { + $this->failure_reason = $e->getMessage(); + return FALSE; + } + } else { + throw new InvalidArgumentException("PHPUnit_Extensions_Database_DataSet_ITable expected"); + } + } + + /** + * @param mixed $other The value passed to evaluate() which failed the + * constraint check. + * @param string $description A string with extra description of what was + * going on while the evaluation failed. + * @param boolean $not Flag to indicate negation. + * @throws PHPUnit_Framework_ExpectationFailedException + */ + protected function failureDescription($other, $description, $not) + { + $failureDescription = sprintf('Failed asserting that %s %s Reason: %s', + $other->__toString(), + $this->toString(), + $this->failure_reason + ); + + if ($not) { + $failureDescription = self::negate($failureDescription); + } + + if (!empty($description)) { + $failureDescription = $description . "\n" . $failureDescription; + } + + return $failureDescription; + } + + /** + * Returns a string representation of the constraint. + * + * @return string + * @access public + */ + public function toString() + { + return sprintf('is equal to %s', + + PHPUnit_Util_Type::toString($this->value)); + } +} +?> Property changes on: test/PHPUnit/Extensions/Database/Constraint/TableIsEqual.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Extensions/Database/DataSet/AbstractXmlDataSet.php =================================================================== --- test/PHPUnit/Extensions/Database/DataSet/AbstractXmlDataSet.php (revision 0) +++ test/PHPUnit/Extensions/Database/DataSet/AbstractXmlDataSet.php (revision 0) @@ -0,0 +1,150 @@ +. + * 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 Mike Lively + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: AbstractXmlDataSet.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/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; + +require_once 'PHPUnit/Extensions/Database/DataSet/AbstractDataSet.php'; +require_once 'PHPUnit/Extensions/Database/DataSet/DefaultTableIterator.php'; +require_once 'PHPUnit/Extensions/Database/DataSet/DefaultTableMetaData.php'; +require_once 'PHPUnit/Extensions/Database/DataSet/DefaultTable.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * The default implementation of a data set. + * + * @category Testing + * @package PHPUnit + * @author Mike Lively + * @copyright 2008 Mike Lively + * @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_Extensions_Database_DataSet_AbstractXmlDataSet extends PHPUnit_Extensions_Database_DataSet_AbstractDataSet +{ + + /** + * @var array + */ + protected $tables; + + /** + * @var SimpleXmlElement + */ + protected $xmlFileContents; + + /** + * Creates a new dataset using the given tables. + * + * @param array $tables + */ + public function __construct($xmlFile) + { + if (!is_file($xmlFile)) { + throw new InvalidArgumentException("Could not find xml file: {$xmlFile}"); + } + $this->xmlFileContents = @simplexml_load_file($xmlFile); + + if ($this->xmlFileContents === FALSE) { + throw new InvalidArgumentException("File is not valid xml: {$xmlFile}"); + } + + $tableColumns = array(); + $tableValues = array(); + + $this->getTableInfo($tableColumns, $tableValues); + $this->createTables($tableColumns, $tableValues); + } + + /** + * Reads the simple xml object and creates the appropriate tables and meta + * data for this dataset. + */ + protected abstract function getTableInfo(Array &$tableColumns, Array &$tableValues); + + protected function createTables(Array &$tableColumns, Array &$tableValues) + { + foreach ($tableValues as $tableName => $values) { + $table = $this->getOrCreateTable($tableName, $tableColumns[$tableName]); + foreach ($values as $value) { + $table->addRow($value); + } + } + } + + /** + * Returns the table with the matching name. If the table does not exist + * an empty one is created. + * + * @param string $tableName + * @return PHPUnit_Extensions_Database_DataSet_ITable + */ + protected function getOrCreateTable($tableName, $tableColumns) + { + if (empty($this->tables[$tableName])) { + $tableMetaData = new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData($tableName, $tableColumns); + $this->tables[$tableName] = new PHPUnit_Extensions_Database_DataSet_DefaultTable($tableMetaData); + } + + return $this->tables[$tableName]; + } + + /** + * Creates an iterator over the tables in the data set. If $reverse is + * true a reverse iterator will be returned. + * + * @param bool $reverse + * @return PHPUnit_Extensions_Database_DataSet_ITableIterator + */ + protected function createIterator($reverse = false) + { + return new PHPUnit_Extensions_Database_DataSet_DefaultTableIterator($this->tables, $reverse); + } +} +?> Property changes on: test/PHPUnit/Extensions/Database/DataSet/AbstractXmlDataSet.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Extensions/Database/DataSet/DefaultDataSet.php =================================================================== --- test/PHPUnit/Extensions/Database/DataSet/DefaultDataSet.php (revision 0) +++ test/PHPUnit/Extensions/Database/DataSet/DefaultDataSet.php (revision 0) @@ -0,0 +1,109 @@ +. + * 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 Mike Lively + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: DefaultDataSet.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/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; + +require_once 'PHPUnit/Extensions/Database/DataSet/AbstractDataSet.php'; +require_once 'PHPUnit/Extensions/Database/DataSet/DefaultTableIterator.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * The default implementation of a data set. + * + * @category Testing + * @package PHPUnit + * @author Mike Lively + * @copyright 2008 Mike Lively + * @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_Extensions_Database_DataSet_DefaultDataSet extends PHPUnit_Extensions_Database_DataSet_AbstractDataSet +{ + + /** + * An array of ITable objects. + * + * @var array + */ + protected $tables; + + /** + * Creates a new dataset using the given tables. + * + * @param array $tables + */ + public function __construct(Array $tables = array()) + { + $this->tables = $tables; + } + + /** + * Adds a table to the dataset. + * + * @param PHPUnit_Extensions_Database_DataSet_ITable $table + */ + public function addTable(PHPUnit_Extensions_Database_DataSet_ITable $table) + { + $this->tables[] = $table; + } + + /** + * Creates an iterator over the tables in the data set. If $reverse is + * true a reverse iterator will be returned. + * + * @param bool $reverse + * @return PHPUnit_Extensions_Database_DataSet_ITableIterator + */ + protected function createIterator($reverse = false) + { + return new PHPUnit_Extensions_Database_DataSet_DefaultTableIterator($this->tables, $reverse); + } +} +?> Property changes on: test/PHPUnit/Extensions/Database/DataSet/DefaultDataSet.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Extensions/Database/DataSet/DataSetFilter.php =================================================================== --- test/PHPUnit/Extensions/Database/DataSet/DataSetFilter.php (revision 0) +++ test/PHPUnit/Extensions/Database/DataSet/DataSetFilter.php (revision 0) @@ -0,0 +1,144 @@ +. + * 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 Mike Lively + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: DataSetFilter.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/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; + +require_once 'PHPUnit/Extensions/Database/DataSet/AbstractDataSet.php'; +require_once 'PHPUnit/Extensions/Database/DataSet/TableFilter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * A dataset decorator that allows filtering out tables and table columns from + * results. + * + * @category Testing + * @package PHPUnit + * @author Mike Lively + * @copyright 2008 Mike Lively + * @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_Extensions_Database_DataSet_DataSetFilter extends PHPUnit_Extensions_Database_DataSet_AbstractDataSet +{ + + /** + * The dataset being decorated. + * @var PHPUnit_Extensions_Database_DataSet_IDataSet + */ + protected $originalDataSet; + + /** + * The tables to exclude from the data set. + * @var Array + */ + protected $excludeTables; + + /** + * The columns to exclude from the data set. + * @var Array + */ + protected $excludeColumns; + + /** + * Creates a new filtered data set. + * + * The $exclude tables should be an associative array using table names as + * the key and an array of column names to exclude for the value. If you + * would like to exclude a full table set the value of the table's entry + * to the special string '*'. + * + * @param PHPUnit_Extensions_Database_DataSet_IDataSet $originalDataSet + * @param Array $excludeTables + */ + public function __construct(PHPUnit_Extensions_Database_DataSet_IDataSet $originalDataSet, Array $excludeTables) + { + $this->originalDataSet = $originalDataSet; + $this->excludeTables = $excludeTables; + + foreach ($this->excludeTables as $tableName => $values) { + if (is_array($values)) { + $this->excludeColumns[$tableName] = $values; + } elseif ($values == '*') { + $this->excludeTables[] = $tableName; + } else { + $this->excludeColumns[$tableName] = (array)$values; + } + } + } + + /** + * Creates an iterator over the tables in the data set. If $reverse is + * true a reverse iterator will be returned. + * + * @param bool $reverse + * @return PHPUnit_Extensions_Database_DataSet_ITableIterator + */ + protected function createIterator($reverse = false) + { + $original_tables = $this->originalDataSet->getIterator($reverse); + $new_tables = array(); + + foreach ($original_tables as $table) { + /* @var $table PHPUnit_Extensions_Database_DataSet_ITable */ + $tableName = $table->getTableMetaData()->getTableName(); + + if (in_array($tableName, $this->excludeTables)) { + continue; + } elseif (array_key_exists($tableName, $this->excludeColumns)) { + $new_tables[] = new PHPUnit_Extensions_Database_DataSet_TableFilter($table, $this->excludeColumns[$tableName]); + } else { + $new_tables[] = $table; + } + } + + return new PHPUnit_Extensions_Database_DataSet_DefaultTableIterator($new_tables); + } +} +?> Property changes on: test/PHPUnit/Extensions/Database/DataSet/DataSetFilter.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Extensions/Database/DataSet/DefaultTable.php =================================================================== --- test/PHPUnit/Extensions/Database/DataSet/DefaultTable.php (revision 0) +++ test/PHPUnit/Extensions/Database/DataSet/DefaultTable.php (revision 0) @@ -0,0 +1,124 @@ +. + * 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 Mike Lively + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: DefaultTable.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/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; + +require_once 'PHPUnit/Extensions/Database/DataSet/AbstractTable.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Provides default table functionality. + * + * @category Testing + * @package PHPUnit + * @author Mike Lively + * @copyright 2008 Mike Lively + * @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_Extensions_Database_DataSet_DefaultTable extends PHPUnit_Extensions_Database_DataSet_AbstractTable +{ + + /** + * Creates a new table object using the given $tableMetaData + * + * @param PHPUnit_Extensions_Database_DataSet_ITableMetaData $tableMetaData + */ + public function __construct(PHPUnit_Extensions_Database_DataSet_ITableMetaData $tableMetaData) + { + $this->setTableMetaData($tableMetaData); + $this->data = array(); + } + + /** + * Adds a row to the table with optional values. + * + * @param array $values + */ + public function addRow($values = array()) + { + $columnNames = $this->getTableMetaData()->getColumns(); + $this->data[] = array_merge(array_fill_keys($columnNames, null), $values); + } + + /** + * Adds the rows in the passed table to the current table. + * + * @param PHPUnit_Extensions_Database_DataSet_ITable $table + */ + public function addTableRows(PHPUnit_Extensions_Database_DataSet_ITable $table) + { + $tableColumns = $this->getTableMetaData()->getColumns(); + for ($i = 0; $i < $table->getRowCount(); $i++) { + $newRow = array(); + foreach ($tableColumns as $columnName) { + $newRow[$columnName] = $table->getValue($i, $columnName); + } + $this->addRow($newRow); + } + } + + /** + * Sets the specified column of the specied row to the specified value. + * + * @param int $row + * @param string $column + * @param mixed $value + */ + public function setValue($row, $column, $value) + { + if (isset($this->data[$row])) { + $this->data[$row][$column] = $value; + } else { + throw new InvalidArgumentException("The row given does not exist."); + } + } +} +?> Property changes on: test/PHPUnit/Extensions/Database/DataSet/DefaultTable.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Extensions/Database/DataSet/DefaultTableMetaData.php =================================================================== --- test/PHPUnit/Extensions/Database/DataSet/DefaultTableMetaData.php (revision 0) +++ test/PHPUnit/Extensions/Database/DataSet/DefaultTableMetaData.php (revision 0) @@ -0,0 +1,91 @@ +. + * 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 Mike Lively + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: DefaultTableMetaData.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/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; + +require_once 'PHPUnit/Extensions/Database/DataSet/AbstractTableMetaData.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * The default implementation of table meta data + * + * @category Testing + * @package PHPUnit + * @author Mike Lively + * @copyright 2008 Mike Lively + * @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_Extensions_Database_DataSet_DefaultTableMetaData extends PHPUnit_Extensions_Database_DataSet_AbstractTableMetaData +{ + + /** + * Creates a new default table meta data object. + * + * @param string $tableName + * @param array $columns + * @param array $primaryKeys + */ + public function __construct($tableName, Array $columns, Array $primaryKeys = array()) + { + $this->tableName = $tableName; + $this->columns = $columns; + $this->primaryKeys = array(); + + foreach ($primaryKeys as $columnName) { + if (!in_array($columnName, $this->columns)) { + throw new InvalidArgumentException("Primary key column passed that is not in the column list."); + } else { + $this->primaryKeys[] = $columnName; + } + } + } +} +?> Property changes on: test/PHPUnit/Extensions/Database/DataSet/DefaultTableMetaData.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Extensions/Database/DataSet/TableFilter.php =================================================================== --- test/PHPUnit/Extensions/Database/DataSet/TableFilter.php (revision 0) +++ test/PHPUnit/Extensions/Database/DataSet/TableFilter.php (revision 0) @@ -0,0 +1,107 @@ +. + * 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 Mike Lively + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: TableFilter.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/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; + +require_once 'PHPUnit/Extensions/Database/DataSet/AbstractTable.php'; +require_once 'PHPUnit/Extensions/Database/DataSet/TableMetaDataFilter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * A table decorator that allows filtering out table columns from results. + * + * @category Testing + * @package PHPUnit + * @author Mike Lively + * @copyright 2008 Mike Lively + * @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_Extensions_Database_DataSet_TableFilter extends PHPUnit_Extensions_Database_DataSet_AbstractTable +{ + + /** + * The table meta data being decorated. + * @var PHPUnit_Extensions_Database_DataSet_ITable + */ + protected $originalTable; + + public function __construct(PHPUnit_Extensions_Database_DataSet_ITable $originalTable, Array $excludeColumns) + { + $this->originalTable = $originalTable; + $this->setTableMetaData(new PHPUnit_Extensions_Database_DataSet_TableMetaDataFilter($originalTable->getTableMetaData(), $excludeColumns)); + } + + /** + * Returns the number of rows in this table. + * + * @return int + */ + public function getRowCount() + { + return $this->originalTable->getRowCount(); + } + + /** + * Returns the value for the given column on the given row. + * + * @param int $row + * @param int $column + */ + public function getValue($row, $column) + { + if (in_array($column, $this->getTableMetaData()->getColumns())) { + return $this->originalTable->getValue($row, $column); + } else { + throw new InvalidArgumentException("The given row ({$row}) and column ({$column}) do not exist in table {$this->getTableMetaData()->getTableName()}"); + } + } +} +?> Property changes on: test/PHPUnit/Extensions/Database/DataSet/TableFilter.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Extensions/Database/DataSet/TableMetaDataFilter.php =================================================================== --- test/PHPUnit/Extensions/Database/DataSet/TableMetaDataFilter.php (revision 0) +++ test/PHPUnit/Extensions/Database/DataSet/TableMetaDataFilter.php (revision 0) @@ -0,0 +1,125 @@ +. + * 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 Mike Lively + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: TableMetaDataFilter.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/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; + +require_once 'PHPUnit/Extensions/Database/DataSet/AbstractTableMetaData.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * A TableMetaData decorator that allows filtering out columns from another + * metaData object. + * + * @category Testing + * @package PHPUnit + * @author Mike Lively + * @copyright 2008 Mike Lively + * @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_Extensions_Database_DataSet_TableMetaDataFilter extends PHPUnit_Extensions_Database_DataSet_AbstractTableMetaData +{ + + /** + * The table meta data being decorated. + * @var PHPUnit_Extensions_Database_DataSet_ITableMetaData + */ + protected $originalMetaData; + + /** + * The columns to exclude from the meta data. + * @var Array + */ + protected $excludeColumns; + + /** + * Creates a new filtered table meta data object filtering out + * $excludeColumns. + * + * @param PHPUnit_Extensions_Database_DataSet_ITableMetaData $originalMetaData + * @param array $excludeColumns + */ + public function __construct(PHPUnit_Extensions_Database_DataSet_ITableMetaData $originalMetaData, Array $excludeColumns) + { + $this->originalMetaData = $originalMetaData; + $this->excludeColumns = $excludeColumns; + } + + /** + * Returns the names of the columns in the table. + * + * @return array + */ + public function getColumns() + { + return array_values(array_diff($this->originalMetaData->getColumns(), $this->excludeColumns)); + } + + /** + * Returns the names of the primary key columns in the table. + * + * @return array + */ + public function getPrimaryKeys() + { + return $this->originalMetaData->getPrimaryKeys(); + } + + /** + * Returns the name of the table. + * + * @return string + */ + public function getTableName() + { + return $this->originalMetaData->getTableName(); + } +} +?> Property changes on: test/PHPUnit/Extensions/Database/DataSet/TableMetaDataFilter.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Extensions/Database/DataSet/IDataSet.php =================================================================== --- test/PHPUnit/Extensions/Database/DataSet/IDataSet.php (revision 0) +++ test/PHPUnit/Extensions/Database/DataSet/IDataSet.php (revision 0) @@ -0,0 +1,104 @@ +. + * 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 Mike Lively + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: IDataSet.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/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Provides a basic interface for creating and reading data from data sets. + * + * @category Testing + * @package PHPUnit + * @author Mike Lively + * @copyright 2008 Mike Lively + * @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 + */ +interface PHPUnit_Extensions_Database_DataSet_IDataSet extends IteratorAggregate +{ + + /** + * Returns an array of table names contained in the dataset. + * + * @return array + */ + public function getTableNames(); + + /** + * Returns a table meta data object for the given table. + * + * @param string $tableName + * @return PHPUnit_Extensions_Database_DataSet_ITableMetaData + */ + public function getTableMetaData($tableName); + + /** + * Returns a table object for the given table. + * + * @param string $tableName + * @return PHPUnit_Extensions_Database_DataSet_ITable + */ + public function getTable($tableName); + + /** + * Returns a reverse iterator for all table objects in the given dataset. + * + * @return PHPUnit_Extensions_Database_DataSet_ITableIterator + */ + public function getReverseIterator(); + + /** + * Asserts that the given data set matches this data set. + * + * @param PHPUnit_Extensions_Database_DataSet_IDataSet $other + */ + public function assertEquals(PHPUnit_Extensions_Database_DataSet_IDataSet $other); +} +?> Property changes on: test/PHPUnit/Extensions/Database/DataSet/IDataSet.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Extensions/Database/DataSet/ITable.php =================================================================== --- test/PHPUnit/Extensions/Database/DataSet/ITable.php (revision 0) +++ test/PHPUnit/Extensions/Database/DataSet/ITable.php (revision 0) @@ -0,0 +1,96 @@ +. + * 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 Mike Lively + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: ITable.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/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Provides a basic interface for creating and reading data from data sets. + * + * @category Testing + * @package PHPUnit + * @author Mike Lively + * @copyright 2008 Mike Lively + * @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 + */ +interface PHPUnit_Extensions_Database_DataSet_ITable +{ + + /** + * Returns the table's meta data. + * + * @return PHPUnit_Extensions_Database_DataSet_ITableMetaData + */ + public function getTableMetaData(); + + /** + * Returns the number of rows in this table. + * + * @return int + */ + public function getRowCount(); + + /** + * Returns the value for the given column on the given row. + * + * @param int $row + * @param int $column + */ + public function getValue($row, $column); + + /** + * Asserts that the given table matches this table. + * + * @param PHPUnit_Extensions_Database_DataSet_ITable $other + */ + public function assertEquals(PHPUnit_Extensions_Database_DataSet_ITable $other); +} +?> Property changes on: test/PHPUnit/Extensions/Database/DataSet/ITable.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Extensions/Database/DataSet/ITableMetaData.php =================================================================== --- test/PHPUnit/Extensions/Database/DataSet/ITableMetaData.php (revision 0) +++ test/PHPUnit/Extensions/Database/DataSet/ITableMetaData.php (revision 0) @@ -0,0 +1,95 @@ +. + * 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 Mike Lively + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: ITableMetaData.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/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Provides a basic interface for returning table meta data. + * + * @category Testing + * @package PHPUnit + * @author Mike Lively + * @copyright 2008 Mike Lively + * @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 + */ +interface PHPUnit_Extensions_Database_DataSet_ITableMetaData +{ + + /** + * Returns the names of the columns in the table. + * + * @return array + */ + public function getColumns(); + + /** + * Returns the names of the primary key columns in the table. + * + * @return array + */ + public function getPrimaryKeys(); + + /** + * Returns the name of the table. + * + * @return string + */ + public function getTableName(); + + /** + * Asserts that the given tableMetaData matches this tableMetaData. + * + * @param PHPUnit_Extensions_Database_DataSet_ITableMetaData $other + */ + public function assertEquals(PHPUnit_Extensions_Database_DataSet_ITableMetaData $other); +} +?> Property changes on: test/PHPUnit/Extensions/Database/DataSet/ITableMetaData.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Extensions/Database/DataSet/XmlDataSet.php =================================================================== --- test/PHPUnit/Extensions/Database/DataSet/XmlDataSet.php (revision 0) +++ test/PHPUnit/Extensions/Database/DataSet/XmlDataSet.php (revision 0) @@ -0,0 +1,129 @@ +. + * 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 Mike Lively + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: XmlDataSet.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/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; + +require_once 'PHPUnit/Extensions/Database/DataSet/AbstractXmlDataSet.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * The default implementation of a data set. + * + * @category Testing + * @package PHPUnit + * @author Mike Lively + * @copyright 2008 Mike Lively + * @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_Extensions_Database_DataSet_XmlDataSet extends PHPUnit_Extensions_Database_DataSet_AbstractXmlDataSet +{ + + protected function getTableInfo(Array &$tableColumns, Array &$tableValues) + { + if ($this->xmlFileContents->getName() != 'dataset') { + throw new Exception("The root element of a flat xml file must be called "); + } + + foreach ($this->xmlFileContents->xpath('/dataset/table') as $tableElement) { + if (empty($tableElement['name'])) { + throw new Exception("Table elements must include a name attribute specifying the table name."); + } + + $tableName = (string)$tableElement['name']; + + if (!isset($tableColumns[$tableName])) { + $tableColumns[$tableName] = array(); + } + + if (!isset($tableValues[$tableName])) { + $tableValues[$tableName] = array(); + } + + $tableInstanceColumns = array(); + + foreach ($tableElement->xpath('./column') as $columnElement) { + $columnName = (string)$columnElement; + if (empty($columnName)) { + throw new Exception("column elements cannot be empty"); + } + + if (!in_array($columnName, $tableColumns[$tableName])) { + $tableColumns[$tableName][] = $columnName; + } + + $tableInstanceColumns[] = $columnName; + } + + foreach ($tableElement->xpath('./row') as $rowElement) { + $rowValues = array(); + $index = 0; + foreach ($rowElement->children() as $columnValue) { + switch ($columnValue->getName()) { + case 'value': + $rowValues[$tableInstanceColumns[$index]] = (string)$columnValue; + $index++; + break; + case 'null': + $rowValues[$tableInstanceColumns[$index]] = null; + $index++; + break; + default: + throw new Exception("Unknown child in the a row element."); + } + } + + $tableValues[$tableName][] = $rowValues; + } + } + } + +} +?> Property changes on: test/PHPUnit/Extensions/Database/DataSet/XmlDataSet.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Extensions/Database/DataSet/DefaultTableIterator.php =================================================================== --- test/PHPUnit/Extensions/Database/DataSet/DefaultTableIterator.php (revision 0) +++ test/PHPUnit/Extensions/Database/DataSet/DefaultTableIterator.php (revision 0) @@ -0,0 +1,173 @@ +. + * 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 Mike Lively + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: DefaultTableIterator.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/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; + +require_once 'PHPUnit/Extensions/Database/DataSet/ITableIterator.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * The default table iterator + * + * @category Testing + * @package PHPUnit + * @author Mike Lively + * @copyright 2008 Mike Lively + * @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_Extensions_Database_DataSet_DefaultTableIterator implements PHPUnit_Extensions_Database_DataSet_ITableIterator +{ + + /** + * An array of tables in the iterator. + * + * @var Array + */ + protected $tables; + + /** + * If this property is true then the tables will be iterated in reverse + * order. + * + * @var bool + */ + protected $reverse; + + /** + * Creates a new default table iterator object. + * + * @param array $tables + * @param bool $reverse + */ + public function __construct(Array $tables, $reverse = false) + { + $this->tables = $tables; + $this->reverse = $reverse; + + $this->rewind(); + } + + /** + * Returns the current table. + * + * @return PHPUnit_Extensions_Database_DataSet_ITable + */ + public function getTable() + { + $this->current(); + } + + /** + * Returns the current table's meta data. + * + * @return PHPUnit_Extensions_Database_DataSet_ITableMetaData + */ + public function getTableMetaData() + { + $this->current()->getTableMetaData(); + } + + /** + * Returns the current table. + * + * @return PHPUnit_Extensions_Database_DataSet_ITable + */ + public function current() + { + return current($this->tables); + } + + /** + * Returns the name of the current table. + * + * @return string + */ + public function key() + { + return $this->current()->getTableMetaData()->getTableName(); + } + + /** + * advances to the next element. + * + */ + public function next() + { + if ($this->reverse) { + prev($this->tables); + } else { + next($this->tables); + } + } + + /** + * Rewinds to the first element + */ + public function rewind() + { + if ($this->reverse) { + end($this->tables); + } else { + reset($this->tables); + } + } + + /** + * Returns true if the current index is valid + * + * @return bool + */ + public function valid() + { + return ($this->current() !== false); + } +} +?> Property changes on: test/PHPUnit/Extensions/Database/DataSet/DefaultTableIterator.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Extensions/Database/DataSet/AbstractDataSet.php =================================================================== --- test/PHPUnit/Extensions/Database/DataSet/AbstractDataSet.php (revision 0) +++ test/PHPUnit/Extensions/Database/DataSet/AbstractDataSet.php (revision 0) @@ -0,0 +1,178 @@ +. + * 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 Mike Lively + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: AbstractDataSet.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/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; + +require_once 'PHPUnit/Extensions/Database/DataSet/IDataSet.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Implements the basic functionality of data sets. + * + * @category Testing + * @package PHPUnit + * @author Mike Lively + * @copyright 2008 Mike Lively + * @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_Extensions_Database_DataSet_AbstractDataSet implements PHPUnit_Extensions_Database_DataSet_IDataSet +{ + + /** + * Creates an iterator over the tables in the data set. If $reverse is + * true a reverse iterator will be returned. + * + * @param bool $reverse + * @return PHPUnit_Extensions_Database_DataSet_ITableIterator + */ + protected abstract function createIterator($reverse = false); + + /** + * Returns an array of table names contained in the dataset. + * + * @return array + */ + public function getTableNames() + { + $tableNames = array(); + + foreach ($this->getIterator() as $table) { + /* @var $table PHPUnit_Extensions_Database_DataSet_ITable */ + $tableNames[] = $table->getTableMetaData()->getTableName(); + } + + return $tableNames; + } + + /** + * Returns a table meta data object for the given table. + * + * @param string $tableName + * @return PHPUnit_Extensions_Database_DataSet_ITableMetaData + */ + public function getTableMetaData($tableName) + { + return $this->getTable($tableName)->getTableMetaData(); + } + + /** + * Returns a table object for the given table. + * + * @param string $tableName + * @return PHPUnit_Extensions_Database_DataSet_ITable + */ + public function getTable($tableName) + { + foreach ($this->getIterator() as $table) { + /* @var $table PHPUnit_Extensions_Database_DataSet_ITable */ + if ($table->getTableMetaData()->getTableName() == $tableName) { + return $table; + } + } + } + + /** + * Returns an iterator for all table objects in the given dataset. + * + * @return PHPUnit_Extensions_Database_DataSet_ITableIterator + */ + public function getIterator() + { + return $this->createIterator(); + } + + /** + * Returns a reverse iterator for all table objects in the given dataset. + * + * @return PHPUnit_Extensions_Database_DataSet_ITableIterator + */ + public function getReverseIterator() + { + return $this->createIterator(true); + } + + /** + * Asserts that the given data set matches this data set. + * + * @param PHPUnit_Extensions_Database_DataSet_IDataSet $other + */ + public function assertEquals(PHPUnit_Extensions_Database_DataSet_IDataSet $other) + { + $thisTableNames = $this->getTableNames(); + $otherTableNames = $other->getTableNames(); + + sort($thisTableNames); + sort($otherTableNames); + + if ($thisTableNames != $otherTableNames) { + throw new Exception("Expected following tables: " . implode(', ', $thisTableNames) . "; has columns: " . implode(', ', $otherTableNames)); + } + + foreach ($thisTableNames as $tableName) { + $this->getTable($tableName)->assertEquals($other->getTable($tableName)); + } + + return TRUE; + } + + public function __toString() + { + $iterator = $this->getIterator(); + + $dataSetString = ''; + foreach ($iterator as $table) { + $dataSetString .= $table->__toString(); + } + + return $dataSetString; + } +} +?> Property changes on: test/PHPUnit/Extensions/Database/DataSet/AbstractDataSet.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Extensions/Database/DataSet/ITableIterator.php =================================================================== --- test/PHPUnit/Extensions/Database/DataSet/ITableIterator.php (revision 0) +++ test/PHPUnit/Extensions/Database/DataSet/ITableIterator.php (revision 0) @@ -0,0 +1,81 @@ +. + * 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 Mike Lively + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: ITableIterator.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/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Provides a basic interface for creating and reading data from data sets. + * + * @category Testing + * @package PHPUnit + * @author Mike Lively + * @copyright 2008 Mike Lively + * @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 + */ +interface PHPUnit_Extensions_Database_DataSet_ITableIterator extends Iterator +{ + + /** + * Returns the current table. + * + * @return PHPUnit_Extensions_Database_DataSet_ITable + */ + public function getTable(); + + /** + * Returns the current table's meta data. + * + * @return PHPUnit_Extensions_Database_DataSet_ITableMetaData + */ + public function getTableMetaData(); +} +?> Property changes on: test/PHPUnit/Extensions/Database/DataSet/ITableIterator.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Extensions/Database/DataSet/AbstractTable.php =================================================================== --- test/PHPUnit/Extensions/Database/DataSet/AbstractTable.php (revision 0) +++ test/PHPUnit/Extensions/Database/DataSet/AbstractTable.php (revision 0) @@ -0,0 +1,198 @@ +. + * 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 Mike Lively + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: AbstractTable.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/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; + +require_once 'PHPUnit/Extensions/Database/DataSet/ITable.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Provides a basic functionality for dbunit tables + * + * @category Testing + * @package PHPUnit + * @author Mike Lively + * @copyright 2008 Mike Lively + * @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_Extensions_Database_DataSet_AbstractTable implements PHPUnit_Extensions_Database_DataSet_ITable +{ + + /** + * @var PHPUnit_Extensions_Database_DataSet_ITableMetaData + */ + protected $tableMetaData; + + /** + * A 2-dimensional array containing the data for this table. + * + * @var array + */ + protected $data; + + /** + * Sets the metadata for this table. + * + * @param PHPUnit_Extensions_Database_DataSet_ITableMetaData $tableMetaData + */ + protected function setTableMetaData(PHPUnit_Extensions_Database_DataSet_ITableMetaData $tableMetaData) + { + $this->tableMetaData = $tableMetaData; + } + + /** + * Returns the table's meta data. + * + * @return PHPUnit_Extensions_Database_DataSet_ITableMetaData + */ + public function getTableMetaData() + { + return $this->tableMetaData; + } + + /** + * Returns the number of rows in this table. + * + * @return int + */ + public function getRowCount() + { + return count($this->data); + } + + /** + * Returns the value for the given column on the given row. + * + * @param int $row + * @param int $column + * @todo reorganize this function to throw the exception first. + */ + public function getValue($row, $column) + { + if (isset($this->data[$row][$column])) { + return (string)$this->data[$row][$column]; + } else { + if (!in_array($column, $this->getTableMetaData()->getColumns()) || $this->getRowCount() <= $row) { + throw new InvalidArgumentException("The given row ({$row}) and column ({$column}) do not exist in table {$this->getTableMetaData()->getTableName()}"); + } else { + return null; + } + } + } + + /** + * Asserts that the given table matches this table. + * + * @param PHPUnit_Extensions_Database_DataSet_ITable $other + */ + public function assertEquals(PHPUnit_Extensions_Database_DataSet_ITable $other) + { + $thisMetaData = $this->getTableMetaData(); + $otherMetaData = $other->getTableMetaData(); + + $thisMetaData->assertEquals($otherMetaData); + + if ($this->getRowCount() != $other->getRowCount()) { + throw new Exception("Expected row count of {$this->getRowCount()}, has a row count of {$other->getRowCount()}"); + } + + $columns = $thisMetaData->getColumns(); + for ($i = 0; $i < $this->getRowCount(); $i++) { + foreach ($columns as $columnName) { + if ($this->getValue($i, $columnName) != $other->getValue($i, $columnName)) { + throw new Exception("Expected value of {$this->getValue($i, $columnName)} for row {$i} column {$columnName}, has a value of {$other->getValue($i, $columnName)}"); + } + } + } + + return TRUE; + } + + public function __toString() + { + $columns = $this->getTableMetaData()->getColumns(); + + $lineSeperator = str_repeat('+----------------------', count($columns)) . "+\n"; + $lineLength = strlen($lineSeperator) - 1; + + $tableString = $lineSeperator; + $tableString .= '| ' . str_pad($this->getTableMetaData()->getTableName(), $lineLength - 4, ' ', STR_PAD_RIGHT) . " |\n"; + $tableString .= $lineSeperator; + $tableString .= $this->rowToString($columns); + $tableString .= $lineSeperator; + + for ($i = 0; $i < $this->getRowCount(); $i++) { + $values = array(); + foreach ($columns as $columnName) { + $values[] = $this->getValue($i, $columnName); + } + + $tableString .= $this->rowToString($values); + $tableString .= $lineSeperator; + } + + return "\n" . $tableString . "\n"; + } + + protected function rowToString(Array $row) + { + $rowString = ''; + foreach ($row as $value) { + if (is_null($value)) { + $value = 'NULL'; + } + $rowString .= '| ' . str_pad(substr($value, 0, 20), 20, ' ', STR_PAD_BOTH) . ' '; + } + + return $rowString . "|\n"; + } +} +?> Property changes on: test/PHPUnit/Extensions/Database/DataSet/AbstractTable.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Extensions/Database/DataSet/AbstractTableMetaData.php =================================================================== --- test/PHPUnit/Extensions/Database/DataSet/AbstractTableMetaData.php (revision 0) +++ test/PHPUnit/Extensions/Database/DataSet/AbstractTableMetaData.php (revision 0) @@ -0,0 +1,136 @@ +. + * 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 Mike Lively + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: AbstractTableMetaData.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/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; + +require_once 'PHPUnit/Extensions/Database/DataSet/ITableMetaData.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Provides basic functionality for table meta data. + * + * @category Testing + * @package PHPUnit + * @author Mike Lively + * @copyright 2008 Mike Lively + * @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_Extensions_Database_DataSet_AbstractTableMetaData implements PHPUnit_Extensions_Database_DataSet_ITableMetaData +{ + + /** + * The names of all columns in the table. + * + * @var Array + */ + protected $columns; + + /** + * The names of all the primary keys in the table. + * + * @var Array + */ + protected $primaryKeys; + + /** + * @var string + */ + protected $tableName; + + /** + * Returns the names of the columns in the table. + * + * @return array + */ + public function getColumns() + { + return $this->columns; + } + + /** + * Returns the names of the primary key columns in the table. + * + * @return array + */ + public function getPrimaryKeys() + { + return $this->primaryKeys; + } + + /** + * Returns the name of the table. + * + * @return string + */ + public function getTableName() + { + return $this->tableName; + } + + /** + * Asserts that the given tableMetaData matches this tableMetaData. + * + * @param PHPUnit_Extensions_Database_DataSet_ITableMetaData $other + */ + public function assertEquals(PHPUnit_Extensions_Database_DataSet_ITableMetaData $other) + { + if ($this->getTableName() != $other->getTableName()) { + throw new Exception("Expected table name of {$this->getTableName()}, has a name of {$other->getTableName()}"); + } + + if ($this->getColumns() != $other->getColumns()) { + throw new Exception("Expected following columns: " . implode(', ', $this->getColumns()) . "; has columns: " . implode(', ', $other->getColumns())); + } + + return TRUE; + } +} +?> Property changes on: test/PHPUnit/Extensions/Database/DataSet/AbstractTableMetaData.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Extensions/Database/DataSet/FlatXmlDataSet.php =================================================================== --- test/PHPUnit/Extensions/Database/DataSet/FlatXmlDataSet.php (revision 0) +++ test/PHPUnit/Extensions/Database/DataSet/FlatXmlDataSet.php (revision 0) @@ -0,0 +1,94 @@ +. + * 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 Mike Lively + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: FlatXmlDataSet.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/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; + +require_once 'PHPUnit/Extensions/Database/DataSet/AbstractXmlDataSet.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * The default implementation of a data set. + * + * @category Testing + * @package PHPUnit + * @author Mike Lively + * @copyright 2008 Mike Lively + * @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_Extensions_Database_DataSet_FlatXmlDataSet extends PHPUnit_Extensions_Database_DataSet_AbstractXmlDataSet +{ + + protected function getTableInfo(Array &$tableColumns, Array &$tableValues) + { + if ($this->xmlFileContents->getName() != 'dataset') { + throw new Exception("The root element of a flat xml file must be called "); + } + + foreach ($this->xmlFileContents->children() as $row) { + $tableName = $row->getName(); + + if (!isset($tableColumns[$tableName])) { + $tableColumns[$tableName] = array(); + } + + $values = array(); + foreach ($row->attributes() as $name => $value) { + if (!in_array($name, $tableColumns[$tableName])) { + $tableColumns[$tableName][] = $name; + } + + $values[$name] = $value; + } + $tableValues[$tableName][] = $values; + } + } +} +?> Property changes on: test/PHPUnit/Extensions/Database/DataSet/FlatXmlDataSet.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Extensions/Database/DB/DefaultDatabaseConnection.php =================================================================== --- test/PHPUnit/Extensions/Database/DB/DefaultDatabaseConnection.php (revision 0) +++ test/PHPUnit/Extensions/Database/DB/DefaultDatabaseConnection.php (revision 0) @@ -0,0 +1,214 @@ +. + * 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 Mike Lively + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id:DefaultDatabaseConnection.php 1254 2008-09-02 04:36:15Z mlively $ + * @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/Extensions/Database/DB/IDatabaseConnection.php'; +require_once 'PHPUnit/Extensions/Database/DB/MetaData.php'; +require_once 'PHPUnit/Extensions/Database/DB/ResultSetTable.php'; +require_once 'PHPUnit/Extensions/Database/DB/DataSet.php'; +require_once 'PHPUnit/Extensions/Database/DB/FilteredDataSet.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Provides a basic interface for communicating with a database. + * + * @category Testing + * @package PHPUnit + * @author Mike Lively + * @copyright 2008 Mike Lively + * @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_Extensions_Database_DB_DefaultDatabaseConnection implements PHPUnit_Extensions_Database_DB_IDatabaseConnection +{ + + /** + * @var PDO + */ + protected $connection; + + /** + * @var string + */ + protected $schema; + + /** + * The metadata object used to retrieve table meta data from the database. + * + * @var PHPUnit_Extensions_Database_DB_IMetaData + */ + protected $metaData; + + /** + * Creates a new database connection + * + * @param PDO $connection + * @param string $schema - The name of the database schema you will be testing against. + */ + public function __construct(PDO $connection, $schema) + { + $this->connection = $connection; + $this->metaData = PHPUnit_Extensions_Database_DB_MetaData::createMetaData($connection, $schema); + $this->schema = $schema; + + $connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + } + + /** + * Close this connection. + */ + public function close() + { + unset($this->connection); + } + + /** + * Returns a database metadata object that can be used to retrieve table + * meta data from the database. + * + * @return PHPUnit_Extensions_Database_DB_IMetaData + */ + public function getMetaData() + { + return $this->metaData; + } + + /** + * Returns the schema for the connection. + * + * @return string + */ + public function getSchema() + { + return $this->schema; + } + + /** + * Creates a dataset containing the specified table names. If no table + * names are specified then it will created a dataset over the entire + * database. + * + * @param array $tableNames + * @return PHPUnit_Extensions_Database_DataSet_IDataSet + * @todo Implement the filtered data set. + */ + public function createDataSet(Array $tableNames = null) + { + if (empty($tableNames)) { + return new PHPUnit_Extensions_Database_DB_DataSet($this); + } else { + return new PHPUnit_Extensions_Database_DB_FilteredDataSet($this, $tableNames); + } + } + + /** + * Creates a table with the result of the specified SQL statement. + * + * @param string $resultName + * @param string $sql + * @return PHPUnit_Extensions_Database_DB_Table + */ + public function createQueryTable($resultName, $sql) + { + $statement = $this->connection->query($sql); + return new PHPUnit_Extensions_Database_DB_ResultSetTable($resultName, $statement); + } + + /** + * Returns this connection database configuration + * + * @return PHPUnit_Extensions_Database_Database_DatabaseConfig + */ + public function getConfig() + { + + } + + /** + * Returns a PDO Connection + * + * @return PDO + */ + public function getConnection() + { + return $this->connection; + } + + /** + * Returns the number of rows in the given table. You can specify an + * optional where clause to return a subset of the table. + * + * @param string $tableName + * @param string $whereClause + * @param int + */ + public function getRowCount($tableName, $whereClause = null) + { + $query = "SELECT COUNT(*) FROM {$tableName}"; + + if (isset($whereClause)) { + $query .= " WHERE {$whereClause}"; + } + } + + /** + * Returns a quoted schema object. (table name, column name, etc) + * + * @param string $object + * @return string + */ + public function quoteSchemaObject($object) + { + return $this->getMetaData()->quoteSchemaObject($object); + } + +} +?> Property changes on: test/PHPUnit/Extensions/Database/DB/DefaultDatabaseConnection.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Extensions/Database/DB/IMetaData.php =================================================================== --- test/PHPUnit/Extensions/Database/DB/IMetaData.php (revision 0) +++ test/PHPUnit/Extensions/Database/DB/IMetaData.php (revision 0) @@ -0,0 +1,108 @@ +. + * 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 Mike Lively + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: IMetaData.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/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Provides a basic interface for retreiving metadata from a database. + * + * @category Testing + * @package PHPUnit + * @author Mike Lively + * @copyright 2008 Mike Lively + * @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 + */ +interface PHPUnit_Extensions_Database_DB_IMetaData +{ + + /** + * Returns an array containing the names of all the tables in the database. + * + * @return array + */ + public function getTableNames(); + + /** + * Returns an array containing the names of all the columns in the + * $tableName table, + * + * @param string $tableName + * @return array + */ + public function getTableColumns($tableName); + + /** + * Returns an array containing the names of all the primary key columns in + * the $tableName table. + * + * @param string $tableName + * @return array + */ + public function getTablePrimaryKeys($tableName); + + /** + * Returns the name of the default schema. + * + * @return string + */ + public function getSchema(); + + /** + * Returns a quoted schema object. (table name, column name, etc) + * + * @param string $object + * @return string + */ + public function quoteSchemaObject($object); + +} +?> Property changes on: test/PHPUnit/Extensions/Database/DB/IMetaData.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Extensions/Database/DB/MetaData/Oci.php =================================================================== --- test/PHPUnit/Extensions/Database/DB/MetaData/Oci.php (revision 0) +++ test/PHPUnit/Extensions/Database/DB/MetaData/Oci.php (revision 0) @@ -0,0 +1,159 @@ +. + * 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 Trond Hansen + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: Oci.php 1985 2007-12-26 18:11:55Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 3.2.3 + */ + +require_once 'PHPUnit/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; +require_once 'PHPUnit/Extensions/Database/DB/MetaData.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Provides functionality to retrieve meta data from an Oracle database. + * + * @category Testing + * @package PHPUnit + * @author Trond Hansen + * @copyright 2002-2008 Sebastian Bergmann + * @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.3 + */ +class PHPUnit_Extensions_Database_DB_MetaData_Oci extends PHPUnit_Extensions_Database_DB_MetaData +{ + protected $columns = array(); + protected $keys = array(); + + /** + * Returns an array containing the names of all the tables in the database. + * + * @return array + */ + public function getTableNames() + { + $tableNames = array(); + + $query = "SELECT table_name + FROM cat + WHERE table_type='TABLE' + ORDER BY table_name"; + + $result = $this->pdo->query($query); + + while ($tableName = $result->fetchColumn(0)) { + $tableNames[] = $tableName; + } + + return $tableNames; + } + + /** + * Returns an array containing the names of all the columns in the + * $tableName table, + * + * @param string $tableName + * @return array + */ + public function getTableColumns($tableName) + { + if (!isset($this->columns[$tableName])) { + $this->loadColumnInfo($tableName); + } + + return $this->columns[$tableName]; + } + + /** + * Returns an array containing the names of all the primary key columns in + * the $tableName table. + * + * @param string $tableName + * @return array + */ + public function getTablePrimaryKeys($tableName) + { + if (!isset($this->keys[$tableName])) { + $this->loadColumnInfo($tableName); + } + + return $this->keys[$tableName]; + } + + /** + * Loads column info from a oracle database. + * + * @param string $tableName + */ + protected function loadColumnInfo($tableName) + { + $this->columns[$tableName] = array(); + $this->keys[$tableName] = array(); + + $query = "SELECT DISTINCT COLUMN_NAME + FROM USER_TAB_COLUMNS + WHERE TABLE_NAME='".$tableName."' + ORDER BY COLUMN_NAME"; + + $result = $this->pdo->query($query); + + while ($columnName = $result->fetchColumn(0)) { + $this->columns[$tableName][] = $columnName; + } + + $keyQuery = "SELECT b.column_name + FROM all_constraints a, all_cons_columns b + WHERE a.constraint_type='P' + AND a.constraint_name=b.constraint_name + AND a.table_name = '".$tableName."' "; + + $result = $this->pdo->query($keyQuery); + + while ($columnName = $result->fetchColumn(0)) { + $this->keys[$tableName][] = $columnName; + } + } +} +?> Property changes on: test/PHPUnit/Extensions/Database/DB/MetaData/Oci.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Extensions/Database/DB/MetaData/Sqlite.php =================================================================== --- test/PHPUnit/Extensions/Database/DB/MetaData/Sqlite.php (revision 0) +++ test/PHPUnit/Extensions/Database/DB/MetaData/Sqlite.php (revision 0) @@ -0,0 +1,151 @@ +. + * 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 Mike Lively + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id:Sqlite.php 1254 2008-09-02 04:36:15Z mlively $ + * @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/Extensions/Database/DB/MetaData.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Provides functionality to retrieve meta data from a sqlite database. + * + * @category Testing + * @package PHPUnit + * @author Mike Lively + * @copyright 2002-2008 Sebastian Bergmann + * @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_Extensions_Database_DB_MetaData_Sqlite extends PHPUnit_Extensions_Database_DB_MetaData +{ + + protected $columns = array(); + + protected $keys = array(); + + /** + * Returns an array containing the names of all the tables in the database. + * + * @return array + */ + public function getTableNames() + { + $query = " + SELECT name + FROM sqlite_master + WHERE + type='table' AND + name <> 'sqlite_sequence' + ORDER BY name + "; + + $result = $this->pdo->query($query); + + while ($tableName = $result->fetchColumn(0)) { + $tableNames[] = $tableName; + } + + return $tableNames; + } + + /** + * Returns an array containing the names of all the columns in the + * $tableName table, + * + * @param string $tableName + * @return array + */ + public function getTableColumns($tableName) + { + if (!isset($this->columns[$tableName])) { + $this->loadColumnInfo($tableName); + } + + return $this->columns[$tableName]; + } + + /** + * Returns an array containing the names of all the primary key columns in + * the $tableName table. + * + * @param string $tableName + * @return array + */ + public function getTablePrimaryKeys($tableName) + { + if (!isset($this->keys[$tableName])) { + $this->loadColumnInfo($tableName); + } + + return $this->keys[$tableName]; + } + + /** + * Loads column info from a sqlite database. + * + * @param string $tableName + */ + protected function loadColumnInfo($tableName) + { + $query = "PRAGMA table_info('{$tableName}')"; + $statement = $this->pdo->query($query); + + /* @var $statement PDOStatement */ + $this->columns[$tableName] = array(); + $this->keys[$tableName] = array(); + while ($columnData = $statement->fetch(PDO::FETCH_NUM)) { + $this->columns[$tableName][] = $columnData[1]; + + if ($columnData[5] == 1) { + $this->keys[$tableName][] = $columnData[1]; + } + } + } +} +?> Property changes on: test/PHPUnit/Extensions/Database/DB/MetaData/Sqlite.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Extensions/Database/DB/MetaData/MySQL.php =================================================================== --- test/PHPUnit/Extensions/Database/DB/MetaData/MySQL.php (revision 0) +++ test/PHPUnit/Extensions/Database/DB/MetaData/MySQL.php (revision 0) @@ -0,0 +1,69 @@ +. + * 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 Mike Lively + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id:InformationSchema.php 1254 2008-09-02 04:36:15Z mlively $ + * @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/Extensions/Database/DB/MetaData/InformationSchema.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Provides functionality to retrieve meta data from a database with information_schema support. + * + * @category Testing + * @package PHPUnit + * @author Mike Lively + * @copyright 2002-2008 Sebastian Bergmann + * @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_Extensions_Database_DB_MetaData_MySQL extends PHPUnit_Extensions_Database_DB_MetaData_InformationSchema +{ + protected $schemaObjectQuoteChar = '`'; +} +?> Property changes on: test/PHPUnit/Extensions/Database/DB/MetaData/MySQL.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Extensions/Database/DB/MetaData/InformationSchema.php =================================================================== --- test/PHPUnit/Extensions/Database/DB/MetaData/InformationSchema.php (revision 0) +++ test/PHPUnit/Extensions/Database/DB/MetaData/InformationSchema.php (revision 0) @@ -0,0 +1,184 @@ +. + * 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 Mike Lively + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id:InformationSchema.php 1254 2008-09-02 04:36:15Z mlively $ + * @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/Extensions/Database/DB/MetaData.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Provides functionality to retrieve meta data from a database with information_schema support. + * + * @category Testing + * @package PHPUnit + * @author Mike Lively + * @copyright 2002-2008 Sebastian Bergmann + * @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_Extensions_Database_DB_MetaData_InformationSchema extends PHPUnit_Extensions_Database_DB_MetaData +{ + + protected $columns = array(); + + protected $keys = array(); + + /** + * Returns an array containing the names of all the tables in the database. + * + * @return array + */ + public function getTableNames() + { + $query = " + SELECT DISTINCT + TABLE_NAME + FROM INFORMATION_SCHEMA.TABLES + WHERE + TABLE_TYPE='BASE TABLE' AND + TABLE_SCHEMA = ? + ORDER BY TABLE_NAME + "; + + $statement = $this->pdo->prepare($query); + $statement->execute(array($this->getSchema())); + + $tableNames = array(); + while ($tableName = $statement->fetchColumn(0)) { + $tableNames[] = $tableName; + } + + return $tableNames; + } + + /** + * Returns an array containing the names of all the columns in the + * $tableName table, + * + * @param string $tableName + * @return array + */ + public function getTableColumns($tableName) + { + if (!isset($this->columns[$tableName])) { + $this->loadColumnInfo($tableName); + } + + return $this->columns[$tableName]; + } + + /** + * Returns an array containing the names of all the primary key columns in + * the $tableName table. + * + * @param string $tableName + * @return array + */ + public function getTablePrimaryKeys($tableName) + { + if (!isset($this->keys[$tableName])) { + $this->loadColumnInfo($tableName); + } + + return $this->keys[$tableName]; + } + + /** + * Loads column info from a sqlite database. + * + * @param string $tableName + */ + protected function loadColumnInfo($tableName) + { + $this->columns[$tableName] = array(); + $this->keys[$tableName] = array(); + + $columnQuery = " + SELECT DISTINCT + COLUMN_NAME + FROM INFORMATION_SCHEMA.COLUMNS + WHERE + TABLE_NAME = ? AND + TABLE_SCHEMA = ? + ORDER BY ORDINAL_POSITION + "; + + $columnStatement = $this->pdo->prepare($columnQuery); + $columnStatement->execute(array($tableName, $this->getSchema())); + + while ($columName = $columnStatement->fetchColumn(0)) { + $this->columns[$tableName][] = $columName; + } + + $keyQuery = " + SELECT + KCU.COLUMN_NAME + FROM + INFORMATION_SCHEMA.TABLE_CONSTRAINTS as TC, + INFORMATION_SCHEMA.KEY_COLUMN_USAGE as KCU + WHERE + TC.CONSTRAINT_NAME = KCU.CONSTRAINT_NAME AND + TC.TABLE_NAME = KCU.TABLE_NAME AND + TC.TABLE_SCHEMA = KCU.TABLE_SCHEMA AND + TC.CONSTRAINT_TYPE = 'PRIMARY KEY' AND + TC.TABLE_NAME = ? AND + TC.TABLE_SCHEMA = ? + ORDER BY + KCU.ORDINAL_POSITION ASC + "; + + $keyStatement = $this->pdo->prepare($keyQuery); + $keyStatement->execute(array($tableName, $this->getSchema())); + + while ($columName = $keyStatement->fetchColumn(0)) { + $this->keys[$tableName][] = $columName; + } + } +} +?> Property changes on: test/PHPUnit/Extensions/Database/DB/MetaData/InformationSchema.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Extensions/Database/DB/IDatabaseConnection.php =================================================================== --- test/PHPUnit/Extensions/Database/DB/IDatabaseConnection.php (revision 0) +++ test/PHPUnit/Extensions/Database/DB/IDatabaseConnection.php (revision 0) @@ -0,0 +1,123 @@ +. + * 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 Mike Lively + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: IDatabaseConnection.php 2165 2008-01-17 16:04:38Z 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'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Provides a basic interface for communicating with a database. + * + * @category Testing + * @package PHPUnit + * @author Mike Lively + * @copyright 2008 Mike Lively + * @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 + */ +interface PHPUnit_Extensions_Database_DB_IDatabaseConnection +{ + + /** + * Close this connection. + */ + public function close(); + + /** + * Creates a dataset containing the specified table names. If no table + * names are specified then it will created a dataset over the entire + * database. + * + * @param array $tableNames + * @return PHPUnit_Extensions_Database_DataSet_IDataSet + */ + public function createDataSet(Array $tableNames = null); + + /** + * Creates a table with the result of the specified SQL statement. + * + * @param string $resultName + * @param string $sql + * @return PHPUnit_Extensions_Database_DataSet_ITable + */ + public function createQueryTable($resultName, $sql); + + /** + * Returns a PDO Connection + * + * @return PDO + */ + public function getConnection(); + + /** + * Returns the number of rows in the given table. You can specify an + * optional where clause to return a subset of the table. + * + * @param string $tableName + * @param string $whereClause + * @param int + */ + public function getRowCount($tableName, $whereClause = null); + + /** + * Returns the schema for the connection. + * + * @return string + */ + public function getSchema(); + + /** + * Returns a quoted schema object. (table name, column name, etc) + * + * @param string $object + * @return string + */ + public function quoteSchemaObject($object); +} +?> Property changes on: test/PHPUnit/Extensions/Database/DB/IDatabaseConnection.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Extensions/Database/DB/MetaData.php =================================================================== --- test/PHPUnit/Extensions/Database/DB/MetaData.php (revision 0) +++ test/PHPUnit/Extensions/Database/DB/MetaData.php (revision 0) @@ -0,0 +1,189 @@ +. + * 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 Mike Lively + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id:MetaData.php 1254 2008-09-02 04:36:15Z mlively $ + * @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/Extensions/Database/DB/IMetaData.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Provides a basic constructor for all meta data classes and a factory for + * generating the appropriate meta data class. + * + * @category Testing + * @package PHPUnit + * @author Mike Lively + * @copyright 2008 Mike Lively + * @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_Extensions_Database_DB_MetaData implements PHPUnit_Extensions_Database_DB_IMetaData +{ + protected static $metaDataClassMap = array( + 'mysql' => 'PHPUnit_Extensions_Database_DB_MetaData_MySQL', + 'oci' => 'PHPUnit_Extensions_Database_DB_MetaData_Oci', + 'sqlite' => 'PHPUnit_Extensions_Database_DB_MetaData_Sqlite' + ); + + /** + * The PDO connection used to retreive database meta data + * + * @var PDO + */ + protected $pdo; + + /** + * The default schema name for the meta data object. + * + * @var string + */ + protected $schema; + + /** + * The character used to quote schema objects. + */ + protected $schemaObjectQuoteChar = '"'; + + /** + * Creates a new database meta data object using the given pdo connection + * and schema name. + * + * @param PDO $pdo + * @param string $schema + */ + public final function __construct(PDO $pdo, $schema) + { + $this->pdo = $pdo; + $this->schema = $schema; + } + + /** + * Creates a meta data object based on the driver of given $pdo object and + * $schema name. + * + * @param PDO $pdo + * @param string $schema + * @return PHPUnit_Extensions_Database_DB_MetaData + */ + public static function createMetaData(PDO $pdo, $schema) + { + $driverName = $pdo->getAttribute(PDO::ATTR_DRIVER_NAME); + if (isset(self::$metaDataClassMap[$driverName])) { + $className = self::$metaDataClassMap[$driverName]; + + if ($className instanceof ReflectionClass) { + return $className->newInstance($pdo, $schema); + } else { + return self::registerClassWithDriver($className, $driverName)->newInstance($pdo, $schema); + } + } else { + throw new Exception("Could not find a meta data driver for {$driverName} pdo driver."); + } + } + + /** + * Validates and registers the given $className with the given $pdoDriver. + * It should be noted that this function will not attempt to include / + * require the file. The $pdoDriver can be determined by the value of the + * PDO::ATTR_DRIVER_NAME attribute for a pdo object. + * + * A reflection of the $className is returned. + * + * @param string $className + * @param string $pdoDriver + * @return ReflectionClass + */ + public static function registerClassWithDriver($className, $pdoDriver) + { + if (!class_exists($className)) { + throw new Exception("Specified class for {$pdoDriver} driver ({$className}) does not exist."); + } + + $reflection = new ReflectionClass($className); + if ($reflection->isSubclassOf('PHPUnit_Extensions_Database_DB_MetaData')) { + return self::$metaDataClassMap[$pdoDriver] = $reflection; + } else { + throw new Exception("Specified class for {$pdoDriver} driver ({$className}) does not extend PHPUnit_Extensions_Database_DB_MetaData."); + } + } + + /** + * Returns the schema for the connection. + * + * @return string + */ + public function getSchema() + { + return $this->schema; + } + + /** + * Returns a quoted schema object. (table name, column name, etc) + * + * @param string $object + * @return string + */ + public function quoteSchemaObject($object) + { + return $this->schemaObjectQuoteChar. + str_replace($this->schemaObjectQuoteChar, $this->schemaObjectQuoteChar.$this->schemaObjectQuoteChar, $object). + $this->schemaObjectQuoteChar; + } +} + +/** + * I am not sure why these requires can't go above the class, but when they do + * the classes can't find the PHPUnit_Extensions_Database_DB_MetaData + * class. + */ +require_once 'PHPUnit/Extensions/Database/DB/MetaData/Sqlite.php'; +require_once 'PHPUnit/Extensions/Database/DB/MetaData/InformationSchema.php'; +require_once 'PHPUnit/Extensions/Database/DB/MetaData/MySQL.php'; + +?> Property changes on: test/PHPUnit/Extensions/Database/DB/MetaData.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Extensions/Database/DB/TableIterator.php =================================================================== --- test/PHPUnit/Extensions/Database/DB/TableIterator.php (revision 0) +++ test/PHPUnit/Extensions/Database/DB/TableIterator.php (revision 0) @@ -0,0 +1,176 @@ +. + * 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 Mike Lively + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: TableIterator.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/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; + +require_once 'PHPUnit/Extensions/Database/DataSet/ITableIterator.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Provides iterative access to tables from a database instance. + * + * @category Testing + * @package PHPUnit + * @author Mike Lively + * @copyright 2008 Mike Lively + * @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_Extensions_Database_DB_TableIterator implements PHPUnit_Extensions_Database_DataSet_ITableIterator +{ + + /** + * An array of tablenames. + * + * @var Array + */ + protected $tableNames; + + /** + * If this property is true then the tables will be iterated in reverse + * order. + * + * @var bool + */ + protected $reverse; + + /** + * The database dataset that this iterator iterates over. + * + * @var PHPUnit_Extensions_Database_DB_DataSet + */ + protected $dataSet; + + public function __construct($tableNames, PHPUnit_Extensions_Database_DB_DataSet $dataSet, $reverse = false) + { + $this->tableNames = $tableNames; + $this->dataSet = $dataSet; + $this->reverse = $reverse; + + $this->rewind(); + } + + /** + * Returns the current table. + * + * @return PHPUnit_Extensions_Database_DataSet_ITable + */ + public function getTable() + { + $this->current(); + } + + /** + * Returns the current table's meta data. + * + * @return PHPUnit_Extensions_Database_DataSet_ITableMetaData + */ + public function getTableMetaData() + { + $this->current()->getTableMetaData(); + } + + /** + * Returns the current table. + * + * @return PHPUnit_Extensions_Database_DataSet_ITable + */ + public function current() + { + $tableName = current($this->tableNames); + return $this->dataSet->getTable($tableName); + } + + /** + * Returns the name of the current table. + * + * @return string + */ + public function key() + { + return $this->current()->getTableMetaData()->getTableName(); + } + + /** + * advances to the next element. + * + */ + public function next() + { + if ($this->reverse) { + prev($this->tableNames); + } else { + next($this->tableNames); + } + } + + /** + * Rewinds to the first element + */ + public function rewind() + { + if ($this->reverse) { + end($this->tableNames); + } else { + reset($this->tableNames); + } + } + + /** + * Returns true if the current index is valid + * + * @return bool + */ + public function valid() + { + return (current($this->tableNames) !== false); + } +} +?> Property changes on: test/PHPUnit/Extensions/Database/DB/TableIterator.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Extensions/Database/DB/ResultSetTable.php =================================================================== --- test/PHPUnit/Extensions/Database/DB/ResultSetTable.php (revision 0) +++ test/PHPUnit/Extensions/Database/DB/ResultSetTable.php (revision 0) @@ -0,0 +1,89 @@ +. + * 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 Mike Lively + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: ResultSetTable.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/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +require_once 'PHPUnit/Extensions/Database/DataSet/AbstractTable.php'; + +/** + * Provides the functionality to represent a database result set as a DBUnit + * table. + * + * @category Testing + * @package PHPUnit + * @author Mike Lively + * @copyright 2008 Mike Lively + * @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_Extensions_Database_DB_ResultSetTable extends PHPUnit_Extensions_Database_DataSet_AbstractTable +{ + + /** + * Creates a new result set table. + * + * @param string $tableName + * @param PDOStatement $pdoStatement + */ + public function __construct($tableName, PDOStatement $pdoStatement) + { + $this->data = $pdoStatement->fetchAll(PDO::FETCH_ASSOC); + + if (count($this->data)) { + $columns = array_keys($this->data[0]); + } else { + $columns = array(); + } + + $this->setTableMetaData(new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData($tableName, $columns)); + } +} +?> Property changes on: test/PHPUnit/Extensions/Database/DB/ResultSetTable.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Extensions/Database/DB/FilteredDataSet.php =================================================================== --- test/PHPUnit/Extensions/Database/DB/FilteredDataSet.php (revision 0) +++ test/PHPUnit/Extensions/Database/DB/FilteredDataSet.php (revision 0) @@ -0,0 +1,95 @@ +. + * 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 Mike Lively + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id:FilteredDataSet.php 1254 2008-09-02 04:36:15Z mlively $ + * @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/Extensions/Database/DB/DataSet.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Provides access to a database instance as a data set. + * + * @category Testing + * @package PHPUnit + * @author Mike Lively + * @copyright 2008 Mike Lively + * @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_Extensions_Database_DB_FilteredDataSet extends PHPUnit_Extensions_Database_DB_DataSet +{ + + /** + * @var Array + */ + protected $tableNames; + + /** + * Creates a new dataset using the given database connection. + * + * @param PHPUnit_Extensions_Database_DB_DefaultDatabaseConnection $databaseConnection + */ + public function __construct(PHPUnit_Extensions_Database_DB_DefaultDatabaseConnection $databaseConnection, Array $tableNames) + { + parent::__construct($databaseConnection); + $this->tableNames = $tableNames; + } + + /** + * Returns a list of table names for the database + * + * @return Array + */ + public function getTableNames() + { + return $this->tableNames; + } +} +?> Property changes on: test/PHPUnit/Extensions/Database/DB/FilteredDataSet.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Extensions/Database/DB/DataSet.php =================================================================== --- test/PHPUnit/Extensions/Database/DB/DataSet.php (revision 0) +++ test/PHPUnit/Extensions/Database/DB/DataSet.php (revision 0) @@ -0,0 +1,173 @@ +. + * 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 Mike Lively + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id:DataSet.php 1254 2008-09-02 04:36:15Z mlively $ + * @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/Extensions/Database/DataSet/AbstractDataSet.php'; +require_once 'PHPUnit/Extensions/Database/DB/TableIterator.php'; +require_once 'PHPUnit/Extensions/Database/DB/Table.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Provides access to a database instance as a data set. + * + * @category Testing + * @package PHPUnit + * @author Mike Lively + * @copyright 2008 Mike Lively + * @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_Extensions_Database_DB_DataSet extends PHPUnit_Extensions_Database_DataSet_AbstractDataSet +{ + + /** + * An array of ITable objects. + * + * @var array + */ + protected $tables = array(); + + /** + * The database connection this dataset is using. + * + * @var PHPUnit_Extensions_Database_DB_DefaultDatabaseConnection + */ + protected $databaseConnection; + + /** + * Creates a new dataset using the given database connection. + * + * @param PHPUnit_Extensions_Database_DB_DefaultDatabaseConnection $databaseConnection + */ + public function __construct(PHPUnit_Extensions_Database_DB_DefaultDatabaseConnection $databaseConnection) + { + $this->databaseConnection = $databaseConnection; + } + + /** + * Creates the query necessary to pull all of the data from a table. + * + * @param PHPUnit_Extensions_Database_DataSet_ITableMetaData $tableMetaData + * @return unknown + */ + public static function buildTableSelect(PHPUnit_Extensions_Database_DataSet_ITableMetaData $tableMetaData) + { + if ($tableMetaData->getTableName() == '') { + $e = new Exception("Empty Table Name"); + echo $e->getTraceAsString(); + throw $e; + } + + $columnList = implode(', ', $tableMetaData->getColumns()); + + $primaryKeys = $tableMetaData->getPrimaryKeys(); + if (count($primaryKeys)) { + $orderBy = 'ORDER BY ' . implode(' ASC, ', $primaryKeys) . ' ASC'; + } else { + $orderBy = ''; + } + + return "SELECT {$columnList} FROM {$tableMetaData->getTableName()} {$orderBy}"; + } + + /** + * Creates an iterator over the tables in the data set. If $reverse is + * true a reverse iterator will be returned. + * + * @param bool $reverse + * @return PHPUnit_Extensions_Database_DB_TableIterator + */ + protected function createIterator($reverse = false) + { + return new PHPUnit_Extensions_Database_DB_TableIterator($this->getTableNames(), $this, $reverse); + } + + /** + * Returns a table object for the given table. + * + * @param string $tableName + * @return PHPUnit_Extensions_Database_DB_Table + */ + public function getTable($tableName) + { + if (!in_array($tableName, $this->getTableNames())) { + throw new InvalidArgumentException("$tableName is not a table in the current database."); + } + + if (empty($this->tables[$tableName])) { + $this->tables[$tableName] = new PHPUnit_Extensions_Database_DB_Table($this->getTableMetaData($tableName), $this->databaseConnection); + } + + return $this->tables[$tableName]; + } + + /** + * Returns a table meta data object for the given table. + * + * @param string $tableName + * @return PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData + */ + public function getTableMetaData($tableName) + { + return new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData($tableName, $this->databaseConnection->getMetaData()->getTableColumns($tableName), $this->databaseConnection->getMetaData()->getTablePrimaryKeys($tableName)); + } + + /** + * Returns a list of table names for the database + * + * @return Array + */ + public function getTableNames() + { + return $this->databaseConnection->getMetaData()->getTableNames(); + } +} +?> Property changes on: test/PHPUnit/Extensions/Database/DB/DataSet.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Extensions/Database/DB/Table.php =================================================================== --- test/PHPUnit/Extensions/Database/DB/Table.php (revision 0) +++ test/PHPUnit/Extensions/Database/DB/Table.php (revision 0) @@ -0,0 +1,84 @@ +. + * 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 Mike Lively + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: Table.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/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; + +require_once 'PHPUnit/Extensions/Database/DataSet/AbstractTable.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Provides the functionality to represent a database table. + * + * @category Testing + * @package PHPUnit + * @author Mike Lively + * @copyright 2008 Mike Lively + * @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_Extensions_Database_DB_Table extends PHPUnit_Extensions_Database_DataSet_AbstractTable +{ + + /** + * Creates a new database table object. + * + * @param PHPUnit_Extensions_Database_DataSet_ITableMetaData $tableMetaData + * @param PHPUnit_Extensions_Database_DB_IDatabaseConnection $databaseConnection + */ + public function __construct(PHPUnit_Extensions_Database_DataSet_ITableMetaData $tableMetaData, PHPUnit_Extensions_Database_DB_IDatabaseConnection $databaseConnection) + { + $this->setTableMetaData($tableMetaData); + + $pdoStatement = $databaseConnection->getConnection()->prepare(PHPUnit_Extensions_Database_DB_DataSet::buildTableSelect($tableMetaData)); + $pdoStatement->execute(); + $this->data = $pdoStatement->fetchAll(PDO::FETCH_ASSOC); + } +} +?> Property changes on: test/PHPUnit/Extensions/Database/DB/Table.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Extensions/Database/DB/TableMetaData.php =================================================================== --- test/PHPUnit/Extensions/Database/DB/TableMetaData.php (revision 0) +++ test/PHPUnit/Extensions/Database/DB/TableMetaData.php (revision 0) @@ -0,0 +1,75 @@ +. + * 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 Mike Lively + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: TableMetaData.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/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; +require_once 'PHPUnit/Extensions/Database/DataSet/DefaultTableMetaData.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * This class loads a table metadata object with database metadata. + * + * @category Testing + * @package PHPUnit + * @author Mike Lively + * @copyright 2008 Mike Lively + * @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_Extensions_Database_DB_TableMetaData extends PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData +{ + + public function __construct($tableName, PHPUnit_Extensions_Database_DB_IMetaData $databaseMetaData) + { + $this->tableName = $tableName; + $this->columns = $databaseMetaData->getTableColumns($tableName); + $this->primaryKeys = $databaseMetaData->getTablePrimaryKeys($tableName); + } +} +?> Property changes on: test/PHPUnit/Extensions/Database/DB/TableMetaData.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Extensions/Database/ITester.php =================================================================== --- test/PHPUnit/Extensions/Database/ITester.php (revision 0) +++ test/PHPUnit/Extensions/Database/ITester.php (revision 0) @@ -0,0 +1,128 @@ +. + * 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 Mike Lively + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id:IDatabaseTester.php 1254 2008-09-02 04:36:15Z mlively $ + * @link http://www.phpunit.de/ + * @since File available since Release 3.2.0 + */ + +require_once 'PHPUnit/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * This is the interface for DatabaseTester objects. These objects are used to + * add database testing to existing test cases using composition instead of + * extension. + * + * @category Testing + * @package PHPUnit + * @author Mike Lively + * @copyright 2008 Mike Lively + * @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 + */ +interface PHPUnit_Extensions_Database_ITester +{ + + /** + * Closes the specified connection. + * + * @param PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection + */ + public function closeConnection(PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection); + + /** + * Returns the test database connection. + * + * @return PHPUnit_Extensions_Database_DB_IDatabaseConnection + */ + public function getConnection(); + + /** + * Returns the test dataset. + * + * @return PHPUnit_Extensions_Database_DataSet_IDataSet + */ + public function getDataSet(); + + /** + * TestCases must call this method inside setUp(). + */ + public function onSetUp(); + + /** + * TestCases must call this method inside teadDown(). + */ + public function onTearDown(); + + /** + * Sets the test dataset to use. + * + * @param PHPUnit_Extensions_Database_DataSet_IDataSet $dataSet + */ + public function setDataSet(PHPUnit_Extensions_Database_DataSet_IDataSet $dataSet); + + /** + * Sets the schema value. + * + * @param string $schema + */ + public function setSchema($schema); + + /** + * Sets the DatabaseOperation to call when starting the test. + * + * @param PHPUnit_Extensions_Database_Operation_DatabaseOperation $setUpOperation + */ + public function setSetUpOperation(PHPUnit_Extensions_Database_Operation_IDatabaseOperation $setUpOperation); + + /** + * Sets the DatabaseOperation to call when starting the test. + * + * @param PHPUnit_Extensions_Database_Operation_DatabaseOperation $tearDownOperation + */ + public function setTearDownOperation(PHPUnit_Extensions_Database_Operation_IDatabaseOperation $tearDownOperation); +} +?> Property changes on: test/PHPUnit/Extensions/Database/ITester.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Extensions/TestSetup.php =================================================================== --- test/PHPUnit/Extensions/TestSetup.php (revision 0) +++ test/PHPUnit/Extensions/TestSetup.php (revision 0) @@ -0,0 +1,152 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: TestSetup.php 2154 2008-01-17 11:19:53Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit/Framework.php'; +require_once 'PHPUnit/Extensions/TestDecorator.php'; +require_once 'PHPUnit/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +trigger_error( + "Class PHPUnit_Extensions_TestSetup is deprecated. ". + "It will be removed in PHPUnit 3.3. ". + "Please use the new functionality in PHPUnit_Framework_TestSuite instead." +); + +/** + * A Decorator to set up and tear down additional fixture state. + * Subclass TestSetup and insert it into your tests when you want + * to set up additional state once before the tests are run. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class PHPUnit_Extensions_TestSetup extends PHPUnit_Extensions_TestDecorator +{ + /** + * Runs the decorated test and collects the + * result in a TestResult. + * + * @param PHPUnit_Framework_TestResult $result + * @return PHPUnit_Framework_TestResult + * @throws InvalidArgumentException + * @access public + */ + public function run(PHPUnit_Framework_TestResult $result = NULL) + { + if ($result === NULL) { + $result = $this->createResult(); + } + + $this->setUp(); + $this->copyFixtureToTest(); + $this->basicRun($result); + $this->tearDown(); + + return $result; + } + + /** + * Copies the fixture set up by setUp() to the test. + * + * @access private + * @since Method available since Release 2.3.0 + */ + private function copyFixtureToTest() + { + $object = new ReflectionClass($this); + + foreach ($object->getProperties() as $attribute) { + $name = $attribute->getName(); + + if ($name != 'test') { + $this->doCopyFixtureToTest($this->test, $name, $this->$name); + } + } + } + + /** + * @access private + * @since Method available since Release 2.3.0 + */ + private function doCopyFixtureToTest($object, $name, &$value) + { + if ($object instanceof PHPUnit_Framework_TestSuite) { + foreach ($object->tests() as $test) { + $this->doCopyFixtureToTest($test, $name, $value); + } + } else { + $object->$name =& $value; + } + } + + /** + * Sets up the fixture. Override to set up additional fixture + * state. + * + * @access protected + */ + protected function setUp() + { + } + + /** + * Tears down the fixture. Override to tear down the additional + * fixture state. + * + * @access protected + */ + protected function tearDown() + { + } +} +?> Property changes on: test/PHPUnit/Extensions/TestSetup.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Extensions/PhptTestCase/Logger.php =================================================================== --- test/PHPUnit/Extensions/PhptTestCase/Logger.php (revision 0) +++ test/PHPUnit/Extensions/PhptTestCase/Logger.php (revision 0) @@ -0,0 +1,69 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: Logger.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'); + +/** + * Dummy logger for PEAR_RunTest. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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_Extensions_PhptTestCase_Logger +{ + public function log($level, $msg, $append_crlf = TRUE) + { + } +} +?> Property changes on: test/PHPUnit/Extensions/PhptTestCase/Logger.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Extensions/TestDecorator.php =================================================================== --- test/PHPUnit/Extensions/TestDecorator.php (revision 0) +++ test/PHPUnit/Extensions/TestDecorator.php (revision 0) @@ -0,0 +1,166 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: TestDecorator.php 1985 2007-12-26 18:11:55Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * A Decorator for Tests. + * + * Use TestDecorator as the base class for defining new + * test decorators. Test decorator subclasses can be introduced + * to add behaviour before or after a test is run. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class PHPUnit_Extensions_TestDecorator extends PHPUnit_Framework_Assert implements PHPUnit_Framework_Test, PHPUnit_Framework_SelfDescribing +{ + /** + * The Test to be decorated. + * + * @var object + * @access protected + */ + protected $test = NULL; + + /** + * Constructor. + * + * @param PHPUnit_Framework_Test $test + * @access public + */ + public function __construct(PHPUnit_Framework_Test $test) + { + $this->test = $test; + } + + /** + * Returns a string representation of the test. + * + * @return string + * @access public + */ + public function toString() + { + return $this->test->toString(); + } + + /** + * Runs the test and collects the + * result in a TestResult. + * + * @param PHPUnit_Framework_TestResult $result + * @access public + */ + public function basicRun(PHPUnit_Framework_TestResult $result) + { + $this->test->run($result); + } + + /** + * Counts the number of test cases that + * will be run by this test. + * + * @return integer + * @access public + */ + public function count() + { + return count($this->test); + } + + /** + * Creates a default TestResult object. + * + * @return PHPUnit_Framework_TestResult + * @access protected + */ + protected function createResult() + { + return new PHPUnit_Framework_TestResult; + } + + /** + * Returns the test to be run. + * + * @return PHPUnit_Framework_Test + * @access public + */ + public function getTest() + { + return $this->test; + } + + /** + * Runs the decorated test and collects the + * result in a TestResult. + * + * @param PHPUnit_Framework_TestResult $result + * @return PHPUnit_Framework_TestResult + * @throws InvalidArgumentException + * @access public + */ + public function run(PHPUnit_Framework_TestResult $result = NULL) + { + if ($result === NULL) { + $result = $this->createResult(); + } + + $this->basicRun($result); + + return $result; + } +} +?> Property changes on: test/PHPUnit/Extensions/TestDecorator.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Extensions/PhptTestSuite.php =================================================================== --- test/PHPUnit/Extensions/PhptTestSuite.php (revision 0) +++ test/PHPUnit/Extensions/PhptTestSuite.php (revision 0) @@ -0,0 +1,96 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: PhptTestSuite.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/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; +require_once 'PHPUnit/Util/FilterIterator.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Suite for .phpt test cases. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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_Extensions_PhptTestSuite extends PHPUnit_Framework_TestSuite +{ + /** + * Constructs a new TestSuite for .phpt test cases. + * + * @param string $directory + * @param array $options Array with ini settings for the php instance run, + * key being the name if the setting, value the ini value. + * @throws InvalidArgumentException + * @access public + */ + public function __construct($directory, $options = array()) + { + if (is_dir($directory)) { + $this->setName($directory); + + $iterator = new PHPUnit_Util_FilterIterator( + new RecursiveIteratorIterator( + new RecursiveDirectoryIterator($directory) + ), + '.phpt' + ); + + foreach ($iterator as $testFile) { + $this->addTestFile($testFile->getPathname(), TRUE, $options); + } + } else { + throw new InvalidArgumentException; + } + } +} +?> Property changes on: test/PHPUnit/Extensions/PhptTestSuite.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Extensions/PhptTestCase.php =================================================================== --- test/PHPUnit/Extensions/PhptTestCase.php (revision 0) +++ test/PHPUnit/Extensions/PhptTestCase.php (revision 0) @@ -0,0 +1,248 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: PhptTestCase.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/Framework.php'; +require_once 'PHPUnit/Extensions/PhptTestCase/Logger.php'; +require_once 'PHPUnit/Util/Filter.php'; + +@include_once 'PEAR/RunTest.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Wrapper to run .phpt test cases. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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_Extensions_PhptTestCase implements PHPUnit_Framework_Test +{ + /** + * The filename of the .phpt file. + * + * @var string + * @access protected + */ + protected $filename; + + protected $options = array(); + + /** + * Constructs a test case with the given filename. + * + * @param string $filename + * @param array $options Array with ini settings for the php instance run, + * key being the name if the setting, value the ini value. + * @access public + */ + public function __construct($filename, $options = array()) + { + if (!is_string($filename)) { + throw new InvalidArgumentException; + } + + if (!is_file($filename)) { + throw new RuntimeException( + sprintf( + 'File "%s" does not exist.', + $filename + ) + ); + } + + if (!is_array($options)) { + throw new InvalidArgumentException; + } + + $this->filename = $filename; + $this->options = $options; + } + + /** + * Counts the number of test cases executed by run(TestResult result). + * + * @return integer + * @access public + */ + public function count() + { + return 1; + } + + /** + * Runs a test and collects its result in a TestResult instance. + * + * @param PHPUnit_Framework_TestResult $result + * @param array $options Array with ini settings for the php instance run, + * key being the name if the setting, value the ini value. + * @return PHPUnit_Framework_TestResult + * @access public + */ + public function run(PHPUnit_Framework_TestResult $result = NULL, $options = array()) + { + if (!class_exists('PEAR_RunTest', FALSE)) { + throw new RuntimeException('Class PEAR_RunTest not found.'); + } + + if ($result === NULL) { + $result = new PHPUnit_Framework_TestResult; + } + + if (!is_array($options)) { + throw new InvalidArgumentException; + } + + $options = array_merge($options, $this->options); + + $coverage = $result->getCollectCodeCoverageInformation(); + + if ($coverage) { + $options = array('coverage' => TRUE); + } else { + $options = array(); + } + + $runner = new PEAR_RunTest(new PHPUnit_Extensions_PhptTestCase_Logger, $options); + + if ($coverage){ + $runner->xdebug_loaded = TRUE; + } else { + $runner->xdebug_loaded = FALSE; + } + + $result->startTest($this); + + PHPUnit_Util_Timer::start(); + $buffer = $runner->run($this->filename, $options); + $time = PHPUnit_Util_Timer::stop(); + + $base = basename($this->filename); + $path = dirname($this->filename); + $coverageFile = $path . DIRECTORY_SEPARATOR . str_replace('.phpt', '.xdebug', $base); + $diffFile = $path . DIRECTORY_SEPARATOR . str_replace('.phpt', '.diff', $base); + $expFile = $path . DIRECTORY_SEPARATOR . str_replace('.phpt', '.exp', $base); + $logFile = $path . DIRECTORY_SEPARATOR . str_replace('.phpt', '.log', $base); + $outFile = $path . DIRECTORY_SEPARATOR . str_replace('.phpt', '.out', $base); + $phpFile = $path . DIRECTORY_SEPARATOR . str_replace('.phpt', '.php', $base); + + if (is_object($buffer) && $buffer instanceof PEAR_Error) { + $result->addError( + $this, + new RuntimeException($buffer->getMessage()), + $time + ); + } + + else if ($buffer == 'SKIPPED') { + $result->addFailure($this, new PHPUnit_Framework_SkippedTestError, 0); + } + + else if ($buffer != 'PASSED') { + $result->addFailure( + $this, + PHPUnit_Framework_ComparisonFailure::diffEqual( + file_get_contents($expFile), + file_get_contents($outFile), + FALSE, + $this->getName() + ), + $time + ); + } + + foreach (array($diffFile, $expFile, $logFile, $phpFile, $outFile) as $file) { + if (file_exists($file)) { + unlink($file); + } + } + + if ($coverage) { + eval('$coverageData = ' . file_get_contents($coverageFile) . ';'); + unset($coverageData[$phpFile]); + + $codeCoverageInformation = array( + 'test' => $this, + 'files' => $coverageData + ); + + $result->appendCodeCoverageInformation($this, $codeCoverageInformation); + unlink($coverageFile); + } + + $result->endTest($this, $time); + + return $result; + } + + /** + * Returns the name of the test case. + * + * @return string + * @access public + */ + public function getName() + { + return $this->toString(); + } + + /** + * Returns a string representation of the test case. + * + * @return string + * @access public + */ + public function toString() + { + return $this->filename; + } +} +?> Property changes on: test/PHPUnit/Extensions/PhptTestCase.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/Extensions/RepeatedTestTest.php =================================================================== --- test/PHPUnit/Tests/Extensions/RepeatedTestTest.php (revision 0) +++ test/PHPUnit/Tests/Extensions/RepeatedTestTest.php (revision 0) @@ -0,0 +1,118 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: RepeatedTestTest.php 1985 2007-12-26 18:11:55Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit/Framework/TestCase.php'; +require_once 'PHPUnit/Framework/TestResult.php'; +require_once 'PHPUnit/Framework/TestSuite.php'; +require_once 'PHPUnit/Extensions/RepeatedTest.php'; + +require_once '_files/Success.php'; + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class Extensions_RepeatedTestTest extends PHPUnit_Framework_TestCase +{ + protected $suite; + + public function __construct() + { + $this->suite = new PHPUnit_Framework_TestSuite; + + $this->suite->addTest(new Success); + $this->suite->addTest(new Success); + } + + public function testRepeatedOnce() + { + $test = new PHPUnit_Extensions_RepeatedTest($this->suite, 1); + $this->assertEquals(2, count($test)); + + $result = $test->run(); + $this->assertEquals(2, count($result)); + } + + public function testRepeatedMoreThanOnce() + { + $test = new PHPUnit_Extensions_RepeatedTest($this->suite, 3); + $this->assertEquals(6, count($test)); + + $result = $test->run(); + $this->assertEquals(6, count($result)); + } + + public function testRepeatedZero() + { + $test = new PHPUnit_Extensions_RepeatedTest($this->suite, 0); + $this->assertEquals(0, count($test)); + + $result = $test->run(); + $this->assertEquals(0, count($result)); + } + + public function testRepeatedNegative() + { + try { + $test = new PHPUnit_Extensions_RepeatedTest($this->suite, -1); + } + + catch (Exception $e) { + return; + } + + $this->fail('Should throw an Exception'); + } +} +?> Property changes on: test/PHPUnit/Tests/Extensions/RepeatedTestTest.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/Extensions/AllTests.php =================================================================== --- test/PHPUnit/Tests/Extensions/AllTests.php (revision 0) +++ test/PHPUnit/Tests/Extensions/AllTests.php (revision 0) @@ -0,0 +1,102 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: AllTests.php 1985 2007-12-26 18:11:55Z 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__); + +if (!defined('PHPUnit_MAIN_METHOD')) { + define('PHPUnit_MAIN_METHOD', 'Extensions_AllTests::main'); + chdir(dirname(dirname(__FILE__))); +} + +require_once 'PHPUnit/Framework/TestSuite.php'; +require_once 'PHPUnit/TextUI/TestRunner.php'; +require_once 'PHPUnit/Util/Filter.php'; + +require_once 'Extensions/OutputTestCaseTest.php'; +require_once 'Extensions/PerformanceTestCaseTest.php'; +require_once 'Extensions/RepeatedTestTest.php'; +require_once 'Extensions/SeleniumTestCaseTest.php'; +require_once 'Extensions/Database/AllTests.php'; + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class Extensions_AllTests +{ + public static function main() + { + PHPUnit_TextUI_TestRunner::run(self::suite()); + } + + public static function suite() + { + $suite = new PHPUnit_Framework_TestSuite('PHPUnit_Extensions'); + + $suite->addTestSuite('Extensions_OutputTestCaseTest'); + $suite->addTestSuite('Extensions_PerformanceTestCaseTest'); + $suite->addTestSuite('Extensions_RepeatedTestTest'); + $suite->addTestSuite('Extensions_SeleniumTestCaseTest'); + $suite->addTest(Extensions_Database_AllTests::suite()); + + return $suite; + } +} + +if (PHPUnit_MAIN_METHOD == 'Extensions_AllTests::main') { + Extensions_AllTests::main(); +} +?> Property changes on: test/PHPUnit/Tests/Extensions/AllTests.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/Extensions/OutputTestCaseTest.php =================================================================== --- test/PHPUnit/Tests/Extensions/OutputTestCaseTest.php (revision 0) +++ test/PHPUnit/Tests/Extensions/OutputTestCaseTest.php (revision 0) @@ -0,0 +1,101 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: OutputTestCaseTest.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/TestCase.php'; + +require_once '_files/OutputTestCase.php'; + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class Extensions_OutputTestCaseTest extends PHPUnit_Framework_TestCase +{ + public function testExpectOutputStringFooActualFoo() + { + $test = new OutputTestCase('testExpectOutputStringFooActualFoo'); + $result = $test->run(); + + $this->assertEquals(1, count($result)); + $this->assertTrue($result->wasSuccessful()); + } + + public function testExpectOutputStringFooActualBar() + { + $test = new OutputTestCase('testExpectOutputStringFooActualBar'); + $result = $test->run(); + + $this->assertEquals(1, count($result)); + $this->assertFalse($result->wasSuccessful()); + } + + public function testExpectOutputRegexFooActualFoo() + { + $test = new OutputTestCase('testExpectOutputRegexFooActualFoo'); + $result = $test->run(); + + $this->assertEquals(1, count($result)); + $this->assertTrue($result->wasSuccessful()); + } + + public function testExpectOutputRegexFooActualBar() + { + $test = new OutputTestCase('testExpectOutputRegexFooActualBar'); + $result = $test->run(); + + $this->assertEquals(1, count($result)); + $this->assertFalse($result->wasSuccessful()); + } +} +?> Property changes on: test/PHPUnit/Tests/Extensions/OutputTestCaseTest.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/Extensions/PerformanceTestCaseTest.php =================================================================== --- test/PHPUnit/Tests/Extensions/PerformanceTestCaseTest.php (revision 0) +++ test/PHPUnit/Tests/Extensions/PerformanceTestCaseTest.php (revision 0) @@ -0,0 +1,85 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: PerformanceTestCaseTest.php 1985 2007-12-26 18:11:55Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit/Framework/AssertionFailedError.php'; +require_once 'PHPUnit/Framework/TestCase.php'; +require_once 'PHPUnit/Framework/TestResult.php'; + +require_once '_files/Sleep.php'; + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class Extensions_PerformanceTestCaseTest extends PHPUnit_Framework_TestCase +{ + public function testDoesNotExceedMaxRunningTime() + { + $test = new Sleep('testSleepTwoSeconds'); + $test->setMaxRunningTime(3); + + $result = $test->run(); + $this->assertEquals(0, $result->failureCount()); + } + + public function testExceedsMaxRunningTime() + { + $test = new Sleep('testSleepTwoSeconds'); + $test->setMaxRunningTime(1); + + $result = $test->run(); + $this->assertEquals(1, $result->failureCount()); + } +} +?> Property changes on: test/PHPUnit/Tests/Extensions/PerformanceTestCaseTest.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/Extensions/SeleniumTestCaseTest.php =================================================================== --- test/PHPUnit/Tests/Extensions/SeleniumTestCaseTest.php (revision 0) +++ test/PHPUnit/Tests/Extensions/SeleniumTestCaseTest.php (revision 0) @@ -0,0 +1,164 @@ +. + * 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 + * @author Sebastian Nohn + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: SeleniumTestCaseTest.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/Extensions/SeleniumTestCase.php'; + +/** + * Tests for PHPUnit_Extensions_SeleniumTestCase. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @author Sebastian Nohn + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class Extensions_SeleniumTestCaseTest extends PHPUnit_Extensions_SeleniumTestCase +{ + public function setUp() + { + if (!PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_ENABLED) { + $this->markTestSkipped( + 'The Selenium tests are disabled.' + ); + } + + $this->setHost(PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_HOST); + $this->setPort(PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_PORT); + $this->setBrowser(PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_BROWSER); + $this->setBrowserUrl('http://www.openqa.org/'); + $this->setTimeout(10000); + } + + public function testOpen() + { + $this->open('http://www.openqa.org/selenium-core/demo/passing/html/test_open.html'); + $this->assertTextPresent('This is a test of the open command.'); + } + + public function testClick() + { + $this->open('http://www.openqa.org/selenium-core/demo/passing/html/test_click_page1.html'); + $this->assertElementContainsText('nextPage', 'Click here for next page'); + $this->clickAndWait('nextPage'); + $this->assertLocationEquals('http://www.openqa.org/selenium-core/demo/passing/html/test_click_page2.html'); + $this->assertTextPresent('This is a test of the click command.'); + $this->clickAndWait('previousPage'); + $this->assertLocationEquals('http://www.openqa.org/selenium-core/demo/passing/html/test_click_page1.html'); + } + + public function testType() + { + $this->open('http://www.openqa.org/selenium-core/demo/passing/html/test_type_page1.html'); + $this->assertElementPresent('username'); + $this->type('username', 'TestUser'); + $this->assertElementValueEquals('username', 'TestUser'); + $this->assertElementPresent('password'); + $this->type('password', 'testUserPassword'); + $this->assertElementValueEquals('password', 'testUserPassword'); + $this->clickAndWait('submitButton'); + $this->assertTextPresent('Welcome, TestUser!'); + } + + public function testOpenFail() + { + $this->open('http://www.openqa.org/selenium-core/demo/failing/html/test_open.html'); + + try { + $this->assertTextPresent('This test has been modified so it will fail.'); + } + + catch (Exception $e) { + return; + } + + $this->fail(); + } + + public function testTypeFail() + { + $this->open('http://www.openqa.org/selenium-core/demo/failing/html/test_type_page1.html'); + $this->assertElementPresent('username'); + $this->type('username', 'TestUser'); + $this->assertElementValueEquals('username', 'TestUser'); + $this->assertElementPresent('password'); + $this->type('password', 'usersPassword'); + + try { + $this->assertElementValueEquals('password', 'testUserPassword'); + } + + catch (Exception $e) { + return; + } + + $this->fail(); + } + + public function testInPlaceEditor() + { + $this->open('http://www.openqa.org/selenium-core/ajaxdemo/scriptaculous-js-1.6.1/test/functional/ajax_inplaceeditor_test.html'); + $this->mouseOver('tobeedited'); + $this->click('tobeedited'); + $this->assertNotVisible('tobeedited'); + $this->assertElementPresent('tobeedited-inplaceeditor'); + $this->click('link=cancel'); + $this->assertElementContainsText('tobeedited', 'To be edited'); + $this->assertVisible('tobeedited'); + $this->click('tobeedited'); + $this->click("//input[@class='editor_ok_button']"); + $this->assertVisible('tobeedited'); +# $this->waitForText('tobeedited', 'Server received: To be edited'); + // Workaround for not yet implemented waitForText + sleep(1); + $this->assertElementContainsText('tobeedited', 'Server received: To be edited'); + } +} +?> Property changes on: test/PHPUnit/Tests/Extensions/SeleniumTestCaseTest.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/Extensions/Database/Operation/AllTests.php =================================================================== --- test/PHPUnit/Tests/Extensions/Database/Operation/AllTests.php (revision 0) +++ test/PHPUnit/Tests/Extensions/Database/Operation/AllTests.php (revision 0) @@ -0,0 +1,96 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: AllTests.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'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__); + +if (!defined('PHPUnit_MAIN_METHOD')) { + define('PHPUnit_MAIN_METHOD', 'Extensions_Database_Operation_AllTests::main'); + chdir(dirname(dirname(__FILE__))); +} + +require_once 'PHPUnit/Framework/TestSuite.php'; +require_once 'PHPUnit/TextUI/TestRunner.php'; +require_once 'PHPUnit/Util/Filter.php'; + +require_once 'Extensions/Database/Operation/OperationsTest.php'; +require_once 'Extensions/Database/Operation/RowBasedTest.php'; + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 Extensions_Database_Operation_AllTests +{ + public static function main() + { + PHPUnit_TextUI_TestRunner::run(self::suite()); + } + + public static function suite() + { + $suite = new PHPUnit_Framework_TestSuite('PHPUnit_Extensions_Database_Operation'); + + $suite->addTestSuite('Extensions_Database_Operation_OperationsTest'); + $suite->addTestSuite('Extensions_Database_Operation_RowBasedTest'); + + return $suite; + } +} + +if (PHPUnit_MAIN_METHOD == 'Extensions_Database_Operation_AllTests::main') { + Extensions_Database_Operation_AllTests::main(); +} +?> Property changes on: test/PHPUnit/Tests/Extensions/Database/Operation/AllTests.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/Extensions/Database/Operation/OperationsTest.php =================================================================== --- test/PHPUnit/Tests/Extensions/Database/Operation/OperationsTest.php (revision 0) +++ test/PHPUnit/Tests/Extensions/Database/Operation/OperationsTest.php (revision 0) @@ -0,0 +1,178 @@ +. + * 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 Mike Lively + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: OperationsTest.php 2038 2008-01-08 09:38:47Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 3.2.0 + */ + +require_once 'PHPUnit/Extensions/Database/TestCase.php'; +require_once 'PHPUnit/Extensions/Database/DB/DefaultDatabaseConnection.php'; +require_once 'PHPUnit/Extensions/Database/DataSet/FlatXmlDataSet.php'; +require_once 'PHPUnit/Extensions/Database/DataSet/DefaultDataSet.php'; +require_once 'PHPUnit/Extensions/Database/DataSet/DefaultTable.php'; +require_once 'PHPUnit/Extensions/Database/DataSet/DefaultTableMetaData.php'; + +require_once 'PHPUnit/Extensions/Database/Operation/Delete.php'; +require_once 'PHPUnit/Extensions/Database/Operation/DeleteAll.php'; +require_once 'PHPUnit/Extensions/Database/Operation/Insert.php'; +require_once 'PHPUnit/Extensions/Database/Operation/Update.php'; +require_once 'PHPUnit/Extensions/Database/Operation/Truncate.php'; +require_once 'PHPUnit/Extensions/Database/Operation/Replace.php'; + +require_once 'Extensions/Database/_files/DatabaseTestUtility.php'; + +/** + * @category Testing + * @package PHPUnit + * @author Mike Lively + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: OperationsTest.php 2038 2008-01-08 09:38:47Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 3.2.0 + */ +class Extensions_Database_Operation_OperationsTest extends PHPUnit_Extensions_Database_TestCase +{ + protected function setUp() + { + if (!extension_loaded('pdo_sqlite')) { + $this->markTestSkipped('PDO/SQLite is required to run this test.'); + } + + parent::setUp(); + } + + public function getConnection() + { + return new PHPUnit_Extensions_Database_DB_DefaultDatabaseConnection(DBUnitTestUtility::getSQLiteMemoryDB(), 'sqlite'); + } + + public function getDataSet() + { + return new PHPUnit_Extensions_Database_DataSet_FlatXmlDataSet(dirname(__FILE__).'/../_files/XmlDataSets/OperationsTestFixture.xml'); + } + + public function testDelete() + { + $deleteOperation = new PHPUnit_Extensions_Database_Operation_Delete(); + + $deleteOperation->execute($this->getConnection(), new PHPUnit_Extensions_Database_DataSet_FlatXmlDataSet(dirname(__FILE__).'/../_files/XmlDataSets/DeleteOperationTest.xml')); + + $this->assertDataSetsEqual(new PHPUnit_Extensions_Database_DataSet_FlatXmlDataSet(dirname(__FILE__).'/../_files/XmlDataSets/DeleteOperationResult.xml'), $this->getConnection()->createDataSet()); + } + + public function testDeleteAll() + { + $deleteAllOperation = new PHPUnit_Extensions_Database_Operation_DeleteAll(); + + $deleteAllOperation->execute($this->getConnection(), new PHPUnit_Extensions_Database_DataSet_FlatXmlDataSet(dirname(__FILE__).'/../_files/XmlDataSets/DeleteAllOperationTest.xml')); + + $expectedDataSet = new PHPUnit_Extensions_Database_DataSet_DefaultDataSet(array( + new PHPUnit_Extensions_Database_DataSet_DefaultTable( + new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData('table1', + array('table1_id', 'column1', 'column2', 'column3', 'column4')) + ), + new PHPUnit_Extensions_Database_DataSet_DefaultTable( + new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData('table2', + array('table2_id', 'column5', 'column6', 'column7', 'column8')) + ), + new PHPUnit_Extensions_Database_DataSet_DefaultTable( + new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData('table3', + array('table3_id', 'column9', 'column10', 'column11', 'column12')) + ), + )); + + $this->assertDataSetsEqual($expectedDataSet, $this->getConnection()->createDataSet()); + } + + public function testTruncate() + { + $truncateOperation = new PHPUnit_Extensions_Database_Operation_Truncate(); + + $truncateOperation->execute($this->getConnection(), new PHPUnit_Extensions_Database_DataSet_FlatXmlDataSet(dirname(__FILE__).'/../_files/XmlDataSets/DeleteAllOperationTest.xml')); + + $expectedDataSet = new PHPUnit_Extensions_Database_DataSet_DefaultDataSet(array( + new PHPUnit_Extensions_Database_DataSet_DefaultTable( + new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData('table1', + array('table1_id', 'column1', 'column2', 'column3', 'column4')) + ), + new PHPUnit_Extensions_Database_DataSet_DefaultTable( + new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData('table2', + array('table2_id', 'column5', 'column6', 'column7', 'column8')) + ), + new PHPUnit_Extensions_Database_DataSet_DefaultTable( + new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData('table3', + array('table3_id', 'column9', 'column10', 'column11', 'column12')) + ), + )); + + $this->assertDataSetsEqual($expectedDataSet, $this->getConnection()->createDataSet()); + } + + public function testInsert() + { + $insertOperation = new PHPUnit_Extensions_Database_Operation_Insert(); + + $insertOperation->execute($this->getConnection(), new PHPUnit_Extensions_Database_DataSet_FlatXmlDataSet(dirname(__FILE__).'/../_files/XmlDataSets/InsertOperationTest.xml')); + + $this->assertDataSetsEqual(new PHPUnit_Extensions_Database_DataSet_FlatXmlDataSet(dirname(__FILE__).'/../_files/XmlDataSets/InsertOperationResult.xml'), $this->getConnection()->createDataSet()); + } + + public function testUpdate() + { + $updateOperation = new PHPUnit_Extensions_Database_Operation_Update(); + + $updateOperation->execute($this->getConnection(), new PHPUnit_Extensions_Database_DataSet_FlatXmlDataSet(dirname(__FILE__).'/../_files/XmlDataSets/UpdateOperationTest.xml')); + + $this->assertDataSetsEqual(new PHPUnit_Extensions_Database_DataSet_FlatXmlDataSet(dirname(__FILE__).'/../_files/XmlDataSets/UpdateOperationResult.xml'), $this->getConnection()->createDataSet()); + } + + public function testReplace() + { + $replaceOperation = new PHPUnit_Extensions_Database_Operation_Replace(); + + $replaceOperation->execute($this->getConnection(), new PHPUnit_Extensions_Database_DataSet_FlatXmlDataSet(dirname(__FILE__).'/../_files/XmlDataSets/ReplaceOperationTest.xml')); + + $this->assertDataSetsEqual(new PHPUnit_Extensions_Database_DataSet_FlatXmlDataSet(dirname(__FILE__).'/../_files/XmlDataSets/ReplaceOperationResult.xml'), $this->getConnection()->createDataSet()); + } +} +?> Property changes on: test/PHPUnit/Tests/Extensions/Database/Operation/OperationsTest.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/Extensions/Database/Operation/RowBasedTest.php =================================================================== --- test/PHPUnit/Tests/Extensions/Database/Operation/RowBasedTest.php (revision 0) +++ test/PHPUnit/Tests/Extensions/Database/Operation/RowBasedTest.php (revision 0) @@ -0,0 +1,188 @@ +. + * 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 Mike Lively + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: RowBasedTest.php 2038 2008-01-08 09:38:47Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 3.2.0 + */ + +require_once 'PHPUnit/Extensions/Database/TestCase.php'; +require_once 'PHPUnit/Extensions/Database/DB/DefaultDatabaseConnection.php'; +require_once 'PHPUnit/Extensions/Database/DataSet/DefaultDataSet.php'; +require_once 'PHPUnit/Extensions/Database/DataSet/DefaultTable.php'; +require_once 'PHPUnit/Extensions/Database/DataSet/DefaultTableMetaData.php'; +require_once 'PHPUnit/Extensions/Database/DataSet/FlatXmlDataSet.php'; +require_once 'PHPUnit/Extensions/Database/Operation/RowBased.php'; + +require_once 'Extensions/Database/_files/DatabaseTestUtility.php'; + + +/** + * @category Testing + * @package PHPUnit + * @author Mike Lively + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: RowBasedTest.php 2038 2008-01-08 09:38:47Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 3.2.0 + */ +class Extensions_Database_Operation_RowBasedTest extends PHPUnit_Extensions_Database_TestCase +{ + protected function setUp() + { + if (!extension_loaded('pdo_sqlite')) { + $this->markTestSkipped('PDO/SQLite is required to run this test.'); + } + + parent::setUp(); + } + + public function getConnection() + { + return new PHPUnit_Extensions_Database_DB_DefaultDatabaseConnection(DBUnitTestUtility::getSQLiteMemoryDB(), 'sqlite'); + } + + public function getDataSet() + { + $tables = array( + new PHPUnit_Extensions_Database_DataSet_DefaultTable( + new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData('table1', + array('table1_id', 'column1', 'column2', 'column3', 'column4')) + ), + new PHPUnit_Extensions_Database_DataSet_DefaultTable( + new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData('table2', + array('table2_id', 'column5', 'column6', 'column7', 'column8')) + ), + new PHPUnit_Extensions_Database_DataSet_DefaultTable( + new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData('table3', + array('table3_id', 'column9', 'column10', 'column11', 'column12')) + ), + ); + + return new PHPUnit_Extensions_Database_DataSet_DefaultDataSet($tables); + } + + public function testExcecute() + { + $connection = $this->getConnection(); + /* @var $connection PHPUnit_Extensions_Database_DB_DefaultDatabaseConnection */ + $table1 = new PHPUnit_Extensions_Database_DataSet_DefaultTable( + new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData('table1', array('table1_id', 'column1', 'column2', 'column3', 'column4')) + ); + + $table1->addRow(array( + 'table1_id' => 1, + 'column1' => 'foo', + 'column2' => 42, + 'column3' => 4.2, + 'column4' => 'bar' + )); + + $table1->addRow(array( + 'table1_id' => 2, + 'column1' => 'qwerty', + 'column2' => 23, + 'column3' => 2.3, + 'column4' => 'dvorak' + )); + + + $table2 = new PHPUnit_Extensions_Database_DataSet_DefaultTable( + new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData('table2', array('table2_id', 'column5', 'column6', 'column7', 'column8')) + ); + + $table2->addRow(array( + 'table2_id' => 1, + 'column5' => 'fdyhkn', + 'column6' => 64, + 'column7' => 4568.64, + 'column8' => 'hkladfg' + )); + + $dataSet = new PHPUnit_Extensions_Database_DataSet_DefaultDataSet(array($table1, $table2)); + + $mockOperation = $this->getMock('PHPUnit_Extensions_Database_Operation_RowBased', + array('buildOperationQuery', 'buildOperationArguments')); + + /* @var $mockOperation PHPUnit_Framework_MockObject_MockObject */ + $mockOperation->expects($this->at(0)) + ->method('buildOperationQuery') + ->with($connection->createDataSet()->getTableMetaData('table1'), $table1) + ->will( + $this->returnValue('INSERT INTO table1 (table1_id, column1, column2, column3, column4) VALUES (?, ?, ?, ?, ?)') + ); + + $mockOperation->expects($this->at(1)) + ->method('buildOperationArguments') + ->with($connection->createDataSet()->getTableMetaData('table1'), $table1, 0) + ->will( + $this->returnValue(array(1, 'foo', 42, 4.2, 'bar')) + ); + + $mockOperation->expects($this->at(2)) + ->method('buildOperationArguments') + ->with($connection->createDataSet()->getTableMetaData('table1'), $table1, 1) + ->will( + $this->returnValue(array(2, 'qwerty', 23, 2.3, 'dvorak')) + ); + + $mockOperation->expects($this->at(3)) + ->method('buildOperationQuery') + ->with($connection->createDataSet()->getTableMetaData('table2'), $table2) + ->will( + $this->returnValue('INSERT INTO table2 (table2_id, column5, column6, column7, column8) VALUES (?, ?, ?, ?, ?)') + ); + + $mockOperation->expects($this->at(4)) + ->method('buildOperationArguments') + ->with($connection->createDataSet()->getTableMetaData('table2'), $table2, 0) + ->will( + $this->returnValue(array(1, 'fdyhkn', 64, 4568.64, 'hkladfg')) + ); + + /* @var $mockOperation PHPUnit_Extensions_Database_Operation_RowBased */ + $mockOperation->execute($connection, $dataSet); + + $this->assertDataSetsEqual(new PHPUnit_Extensions_Database_DataSet_FlatXmlDataSet(dirname(__FILE__).'/../_files/XmlDataSets/RowBasedExecute.xml'), $connection->createDataSet(array('table1', 'table2'))); + } +} +?> Property changes on: test/PHPUnit/Tests/Extensions/Database/Operation/RowBasedTest.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/Extensions/Database/_files/XmlDataSets/DeleteOperationResult.xml =================================================================== --- test/PHPUnit/Tests/Extensions/Database/_files/XmlDataSets/DeleteOperationResult.xml (revision 0) +++ test/PHPUnit/Tests/Extensions/Database/_files/XmlDataSets/DeleteOperationResult.xml (revision 0) @@ -0,0 +1,7 @@ + + + + + + + Property changes on: test/PHPUnit/Tests/Extensions/Database/_files/XmlDataSets/DeleteOperationResult.xml ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/Extensions/Database/_files/XmlDataSets/DeleteOperationTest.xml =================================================================== --- test/PHPUnit/Tests/Extensions/Database/_files/XmlDataSets/DeleteOperationTest.xml (revision 0) +++ test/PHPUnit/Tests/Extensions/Database/_files/XmlDataSets/DeleteOperationTest.xml (revision 0) @@ -0,0 +1,5 @@ + + + + + Property changes on: test/PHPUnit/Tests/Extensions/Database/_files/XmlDataSets/DeleteOperationTest.xml ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/Extensions/Database/_files/XmlDataSets/InsertOperationResult.xml =================================================================== --- test/PHPUnit/Tests/Extensions/Database/_files/XmlDataSets/InsertOperationResult.xml (revision 0) +++ test/PHPUnit/Tests/Extensions/Database/_files/XmlDataSets/InsertOperationResult.xml (revision 0) @@ -0,0 +1,12 @@ + + + + + + + + + + + + Property changes on: test/PHPUnit/Tests/Extensions/Database/_files/XmlDataSets/InsertOperationResult.xml ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/Extensions/Database/_files/XmlDataSets/InsertOperationTest.xml =================================================================== --- test/PHPUnit/Tests/Extensions/Database/_files/XmlDataSets/InsertOperationTest.xml (revision 0) +++ test/PHPUnit/Tests/Extensions/Database/_files/XmlDataSets/InsertOperationTest.xml (revision 0) @@ -0,0 +1,6 @@ + + + + + + Property changes on: test/PHPUnit/Tests/Extensions/Database/_files/XmlDataSets/InsertOperationTest.xml ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/Extensions/Database/_files/XmlDataSets/FilteredTestComparison.xml =================================================================== --- test/PHPUnit/Tests/Extensions/Database/_files/XmlDataSets/FilteredTestComparison.xml (revision 0) +++ test/PHPUnit/Tests/Extensions/Database/_files/XmlDataSets/FilteredTestComparison.xml (revision 0) @@ -0,0 +1,9 @@ + + + + + + + + + Property changes on: test/PHPUnit/Tests/Extensions/Database/_files/XmlDataSets/FilteredTestComparison.xml ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/Extensions/Database/_files/XmlDataSets/RowBasedExecute.xml =================================================================== --- test/PHPUnit/Tests/Extensions/Database/_files/XmlDataSets/RowBasedExecute.xml (revision 0) +++ test/PHPUnit/Tests/Extensions/Database/_files/XmlDataSets/RowBasedExecute.xml (revision 0) @@ -0,0 +1,6 @@ + + + + + + Property changes on: test/PHPUnit/Tests/Extensions/Database/_files/XmlDataSets/RowBasedExecute.xml ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/Extensions/Database/_files/XmlDataSets/OperationsTestFixture.xml =================================================================== --- test/PHPUnit/Tests/Extensions/Database/_files/XmlDataSets/OperationsTestFixture.xml (revision 0) +++ test/PHPUnit/Tests/Extensions/Database/_files/XmlDataSets/OperationsTestFixture.xml (revision 0) @@ -0,0 +1,9 @@ + + + + + + + + + Property changes on: test/PHPUnit/Tests/Extensions/Database/_files/XmlDataSets/OperationsTestFixture.xml ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/Extensions/Database/_files/XmlDataSets/ReplaceOperationResult.xml =================================================================== --- test/PHPUnit/Tests/Extensions/Database/_files/XmlDataSets/ReplaceOperationResult.xml (revision 0) +++ test/PHPUnit/Tests/Extensions/Database/_files/XmlDataSets/ReplaceOperationResult.xml (revision 0) @@ -0,0 +1,12 @@ + + + + + + + + + + + + Property changes on: test/PHPUnit/Tests/Extensions/Database/_files/XmlDataSets/ReplaceOperationResult.xml ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/Extensions/Database/_files/XmlDataSets/ReplaceOperationTest.xml =================================================================== --- test/PHPUnit/Tests/Extensions/Database/_files/XmlDataSets/ReplaceOperationTest.xml (revision 0) +++ test/PHPUnit/Tests/Extensions/Database/_files/XmlDataSets/ReplaceOperationTest.xml (revision 0) @@ -0,0 +1,9 @@ + + + + + + + + + Property changes on: test/PHPUnit/Tests/Extensions/Database/_files/XmlDataSets/ReplaceOperationTest.xml ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/Extensions/Database/_files/XmlDataSets/UpdateOperationResult.xml =================================================================== --- test/PHPUnit/Tests/Extensions/Database/_files/XmlDataSets/UpdateOperationResult.xml (revision 0) +++ test/PHPUnit/Tests/Extensions/Database/_files/XmlDataSets/UpdateOperationResult.xml (revision 0) @@ -0,0 +1,9 @@ + + + + + + + + + Property changes on: test/PHPUnit/Tests/Extensions/Database/_files/XmlDataSets/UpdateOperationResult.xml ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/Extensions/Database/_files/XmlDataSets/UpdateOperationTest.xml =================================================================== --- test/PHPUnit/Tests/Extensions/Database/_files/XmlDataSets/UpdateOperationTest.xml (revision 0) +++ test/PHPUnit/Tests/Extensions/Database/_files/XmlDataSets/UpdateOperationTest.xml (revision 0) @@ -0,0 +1,6 @@ + + + + + + Property changes on: test/PHPUnit/Tests/Extensions/Database/_files/XmlDataSets/UpdateOperationTest.xml ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/Extensions/Database/_files/XmlDataSets/FilteredTestFixture.xml =================================================================== --- test/PHPUnit/Tests/Extensions/Database/_files/XmlDataSets/FilteredTestFixture.xml (revision 0) +++ test/PHPUnit/Tests/Extensions/Database/_files/XmlDataSets/FilteredTestFixture.xml (revision 0) @@ -0,0 +1,8 @@ + + + + + + + + Property changes on: test/PHPUnit/Tests/Extensions/Database/_files/XmlDataSets/FilteredTestFixture.xml ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/Extensions/Database/_files/XmlDataSets/XmlDataSet.xml =================================================================== --- test/PHPUnit/Tests/Extensions/Database/_files/XmlDataSets/XmlDataSet.xml (revision 0) +++ test/PHPUnit/Tests/Extensions/Database/_files/XmlDataSets/XmlDataSet.xml (revision 0) @@ -0,0 +1,65 @@ + + + + table1_id + column1 + column2 + column3 + column4 + + 1 + tgfahgasdf + 200 + 34.64 + yghkf;a hahfg8ja h; + + + 2 + hk;afg + 654 + 46.54 + 24rwehhads + + + 3 + ha;gyt + 462 + 1654.4 + asfgklg + +
+ + table2_id + column5 + column6 + column7 + column8 + + 1 + fhah + 456 + 46.5 + fsdbghfdas + + + 2 + asdhfoih + 654 + + 43asdfhgj + + + 3 + ajsdlkfguitah + 654 + + + +
+ + + + + + +
Property changes on: test/PHPUnit/Tests/Extensions/Database/_files/XmlDataSets/XmlDataSet.xml ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/Extensions/Database/_files/XmlDataSets/DeleteAllOperationTest.xml =================================================================== --- test/PHPUnit/Tests/Extensions/Database/_files/XmlDataSets/DeleteAllOperationTest.xml (revision 0) +++ test/PHPUnit/Tests/Extensions/Database/_files/XmlDataSets/DeleteAllOperationTest.xml (revision 0) @@ -0,0 +1,6 @@ + + + + + + Property changes on: test/PHPUnit/Tests/Extensions/Database/_files/XmlDataSets/DeleteAllOperationTest.xml ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/Extensions/Database/_files/XmlDataSets/FlatXmlDataSet.xml =================================================================== --- test/PHPUnit/Tests/Extensions/Database/_files/XmlDataSets/FlatXmlDataSet.xml (revision 0) +++ test/PHPUnit/Tests/Extensions/Database/_files/XmlDataSets/FlatXmlDataSet.xml (revision 0) @@ -0,0 +1,9 @@ + + + + + + + + + Property changes on: test/PHPUnit/Tests/Extensions/Database/_files/XmlDataSets/FlatXmlDataSet.xml ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/Extensions/Database/AllTests.php =================================================================== --- test/PHPUnit/Tests/Extensions/Database/AllTests.php (revision 0) +++ test/PHPUnit/Tests/Extensions/Database/AllTests.php (revision 0) @@ -0,0 +1,97 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: AllTests.php 1985 2007-12-26 18:11:55Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 3.2.0 + */ + +error_reporting(E_ALL | E_STRICT); + +require_once 'PHPUnit/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__); + +if (!defined('PHPUnit_MAIN_METHOD')) { + define('PHPUnit_MAIN_METHOD', 'Extensions_Database_AllTests::main'); + chdir(dirname(__FILE__)); +} + +require_once 'PHPUnit/Framework/TestSuite.php'; +require_once 'PHPUnit/TextUI/TestRunner.php'; + +require_once 'Extensions/Database/DataSet/AllTests.php'; +require_once 'Extensions/Database/Operation/AllTests.php'; + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 Extensions_Database_AllTests +{ + public static function main() + { + PHPUnit_TextUI_TestRunner::run(self::suite()); + } + + public static function suite() + { + $suite = new PHPUnit_Framework_TestSuite('PHPUnit_Extensions_Database'); + + $suite->addTest(Extensions_Database_Operation_AllTests::suite()); + $suite->addTest(Extensions_Database_DataSet_AllTests::suite()); + + return $suite; + } +} + +if (PHPUnit_MAIN_METHOD == 'Extensions_Database_AllTests::main') { + Extensions_Database_AllTests::main(); +} +?> Property changes on: test/PHPUnit/Tests/Extensions/Database/AllTests.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/Extensions/Database/DataSet/XmlDataSetsTest.php =================================================================== --- test/PHPUnit/Tests/Extensions/Database/DataSet/XmlDataSetsTest.php (revision 0) +++ test/PHPUnit/Tests/Extensions/Database/DataSet/XmlDataSetsTest.php (revision 0) @@ -0,0 +1,144 @@ +. + * 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 Mike Lively + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: XmlDataSetsTest.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/Framework/TestCase.php'; +require_once 'PHPUnit/Extensions/Database/DataSet/DefaultDataSet.php'; +require_once 'PHPUnit/Extensions/Database/DataSet/DefaultTable.php'; +require_once 'PHPUnit/Extensions/Database/DataSet/DefaultTableMetaData.php'; +require_once 'PHPUnit/Extensions/Database/DataSet/FlatXmlDataSet.php'; +require_once 'PHPUnit/Extensions/Database/DataSet/XmlDataSet.php'; +require_once 'PHPUnit/Extensions/Database/Constraint/DataSetIsEqual.php'; + +/** + * @category Testing + * @package PHPUnit + * @author Mike Lively + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: XmlDataSetsTest.php 1985 2007-12-26 18:11:55Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 3.2.0 + */ +class Extensions_Database_DataSet_XmlDataSetsTest extends PHPUnit_Framework_TestCase +{ + protected $expectedDataSet; + + public function setUp() + { + $table1MetaData = new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData( + 'table1', array('table1_id', 'column1', 'column2', 'column3', 'column4') + ); + $table2MetaData = new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData( + 'table2', array('table2_id', 'column5', 'column6', 'column7', 'column8') + ); + + $table1 = new PHPUnit_Extensions_Database_DataSet_DefaultTable($table1MetaData); + $table2 = new PHPUnit_Extensions_Database_DataSet_DefaultTable($table2MetaData); + + $table1->addRow(array( + 'table1_id' => 1, + 'column1' => 'tgfahgasdf', + 'column2' => 200, + 'column3' => 34.64, + 'column4' => 'yghkf;a hahfg8ja h;' + )); + $table1->addRow(array( + 'table1_id' => 2, + 'column1' => 'hk;afg', + 'column2' => 654, + 'column3' => 46.54, + 'column4' => '24rwehhads' + )); + $table1->addRow(array( + 'table1_id' => 3, + 'column1' => 'ha;gyt', + 'column2' => 462, + 'column3' => 1654.4, + 'column4' => 'asfgklg' + )); + + $table2->addRow(array( + 'table2_id' => 1, + 'column5' => 'fhah', + 'column6' => 456, + 'column7' => 46.5, + 'column8' => 'fsdbghfdas' + )); + $table2->addRow(array( + 'table2_id' => 2, + 'column5' => 'asdhfoih', + 'column6' => 654, + 'column7' => null, + 'column8' => '43asdfhgj' + )); + $table2->addRow(array( + 'table2_id' => 3, + 'column5' => 'ajsdlkfguitah', + 'column6' => 654, + 'column7' => null, + 'column8' => null + )); + + $this->expectedDataSet = new PHPUnit_Extensions_Database_DataSet_DefaultDataSet(array($table1, $table2)); + } + + public function testFlatXmlDataSet() + { + $constraint = new PHPUnit_Extensions_Database_Constraint_DataSetIsEqual($this->expectedDataSet); + $xmlFlatDataSet = new PHPUnit_Extensions_Database_DataSet_FlatXmlDataSet(dirname(__FILE__).'/../_files/XmlDataSets/FlatXmlDataSet.xml'); + + self::assertThat($xmlFlatDataSet, $constraint); + } + + public function testXmlDataSet() + { + $constraint = new PHPUnit_Extensions_Database_Constraint_DataSetIsEqual($this->expectedDataSet); + $xmlDataSet = new PHPUnit_Extensions_Database_DataSet_XmlDataSet(dirname(__FILE__).'/../_files/XmlDataSets/XmlDataSet.xml'); + + self::assertThat($xmlDataSet, $constraint); + } +} +?> Property changes on: test/PHPUnit/Tests/Extensions/Database/DataSet/XmlDataSetsTest.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/Extensions/Database/DataSet/AllTests.php =================================================================== --- test/PHPUnit/Tests/Extensions/Database/DataSet/AllTests.php (revision 0) +++ test/PHPUnit/Tests/Extensions/Database/DataSet/AllTests.php (revision 0) @@ -0,0 +1,96 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: AllTests.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'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__); + +if (!defined('PHPUnit_MAIN_METHOD')) { + define('PHPUnit_MAIN_METHOD', 'Extensions_Database_Operation_AllTests::main'); + chdir(dirname(dirname(__FILE__))); +} + +require_once 'PHPUnit/Framework/TestSuite.php'; +require_once 'PHPUnit/TextUI/TestRunner.php'; +require_once 'PHPUnit/Util/Filter.php'; + +require_once 'Extensions/Database/DataSet/XmlDataSetsTest.php'; +require_once 'Extensions/Database/DataSet/FilterTest.php'; + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 Extensions_Database_DataSet_AllTests +{ + public static function main() + { + PHPUnit_TextUI_TestRunner::run(self::suite()); + } + + public static function suite() + { + $suite = new PHPUnit_Framework_TestSuite('PHPUnit_Extensions_Database_DataSet'); + + $suite->addTestSuite('Extensions_Database_DataSet_XmlDataSetsTest'); + $suite->addTestSuite('Extensions_Database_DataSet_FilterTest'); + + return $suite; + } +} + +if (PHPUnit_MAIN_METHOD == 'Extensions_Database_DataSet_AllTests::main') { + Extensions_Database_DataSet_AllTests::main(); +} +?> Property changes on: test/PHPUnit/Tests/Extensions/Database/DataSet/AllTests.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/Extensions/Database/DataSet/FilterTest.php =================================================================== --- test/PHPUnit/Tests/Extensions/Database/DataSet/FilterTest.php (revision 0) +++ test/PHPUnit/Tests/Extensions/Database/DataSet/FilterTest.php (revision 0) @@ -0,0 +1,89 @@ +. + * 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 Mike Lively + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: FilterTest.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/Framework/TestCase.php'; +require_once 'PHPUnit/Extensions/Database/DataSet/FlatXmlDataSet.php'; +require_once 'PHPUnit/Extensions/Database/DataSet/DataSetFilter.php'; +require_once 'PHPUnit/Extensions/Database/Constraint/DataSetIsEqual.php'; + +/** + * @category Testing + * @package PHPUnit + * @author Mike Lively + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: FilterTest.php 1985 2007-12-26 18:11:55Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 3.2.0 + */ +class Extensions_Database_DataSet_FilterTest extends PHPUnit_Framework_TestCase +{ + protected $expectedDataSet; + + public function setUp() + { + $this->expectedDataSet = new PHPUnit_Extensions_Database_DataSet_FlatXmlDataSet( + dirname(__FILE__).'/../_files/XmlDataSets/FilteredTestFixture.xml' + ); + } + + public function testFilteredDataSet() + { + $constraint = new PHPUnit_Extensions_Database_Constraint_DataSetIsEqual($this->expectedDataSet); + $dataSet = new PHPUnit_Extensions_Database_DataSet_FlatXmlDataSet( + dirname(__FILE__).'/../_files/XmlDataSets/FilteredTestComparison.xml' + ); + + $filteredDataSet = new PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet, array( + 'table1' => array('table1_id'), + 'table2' => '*', + 'table3' => array('table3_id') + )); + + self::assertThat($filteredDataSet, $constraint); + } +} +?> Property changes on: test/PHPUnit/Tests/Extensions/Database/DataSet/FilterTest.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/TestConfiguration.php.dist =================================================================== --- test/PHPUnit/Tests/TestConfiguration.php.dist (revision 0) +++ test/PHPUnit/Tests/TestConfiguration.php.dist (revision 0) @@ -0,0 +1,61 @@ +. + * 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, STRIC + * 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 + * @copyright 2002-2007 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id$ + * @link http://www.phpunit.de/ + * @since File available since Release 3.0.0 + */ + +define('PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_ENABLED', FALSE); +define('PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_HOST', '127.0.0.1'); +define('PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_PORT', 4444); +define('PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_BROWSER', '*firefox'); + +/* On Linux you need to put firefox-bin in $PATH, + * alternatively specify the full path: + */ +/* +define( + 'PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_BROWSER', + '*firefox /usr/lib/mozilla-firefox/firefox-bin' +); +*/ +?> Property changes on: test/PHPUnit/Tests/TestConfiguration.php.dist ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/_files/TestIterator.php =================================================================== --- test/PHPUnit/Tests/_files/TestIterator.php (revision 0) +++ test/PHPUnit/Tests/_files/TestIterator.php (revision 0) @@ -0,0 +1,98 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: TestIterator.php 1985 2007-12-26 18:11:55Z 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__); + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class TestIterator implements Iterator +{ + protected $array; + protected $position; + + public function __construct($array = array()) + { + $this->array = $array; + } + + public function rewind() + { + $this->position = 0; + } + + public function valid() + { + return $this->position < count($this->array); + } + + public function key() + { + return $this->position; + } + + public function current() + { + return $this->array[$this->position]; + } + + public function next() + { + $this->position++; + } +} +?> Property changes on: test/PHPUnit/Tests/_files/TestIterator.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/_files/TearDownFailure.php =================================================================== --- test/PHPUnit/Tests/_files/TearDownFailure.php (revision 0) +++ test/PHPUnit/Tests/_files/TearDownFailure.php (revision 0) @@ -0,0 +1,72 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: TearDownFailure.php 1985 2007-12-26 18:11:55Z 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__); + +require_once 'Success.php'; + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class TearDownFailure extends Success +{ + protected function tearDown() + { + throw new Exception; + } +} +?> Property changes on: test/PHPUnit/Tests/_files/TearDownFailure.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/_files/NotPublicTestCase.php =================================================================== --- test/PHPUnit/Tests/_files/NotPublicTestCase.php (revision 0) +++ test/PHPUnit/Tests/_files/NotPublicTestCase.php (revision 0) @@ -0,0 +1,74 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: NotPublicTestCase.php 1985 2007-12-26 18:11:55Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__); + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class NotPublicTestCase extends PHPUnit_Framework_TestCase +{ + public function testPublic() + { + } + + protected function testNotPublic() + { + } +} +?> Property changes on: test/PHPUnit/Tests/_files/NotPublicTestCase.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/_files/NoTestCases.php =================================================================== --- test/PHPUnit/Tests/_files/NoTestCases.php (revision 0) +++ test/PHPUnit/Tests/_files/NoTestCases.php (revision 0) @@ -0,0 +1,70 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: NoTestCases.php 1985 2007-12-26 18:11:55Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__); + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class NoTestCases extends PHPUnit_Framework_TestCase +{ + public function noTestCase() + { + } +} +?> Property changes on: test/PHPUnit/Tests/_files/NoTestCases.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/_files/OutputTestCase.php =================================================================== --- test/PHPUnit/Tests/_files/OutputTestCase.php (revision 0) +++ test/PHPUnit/Tests/_files/OutputTestCase.php (revision 0) @@ -0,0 +1,91 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: OutputTestCase.php 1985 2007-12-26 18:11:55Z 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__); + +require_once 'PHPUnit/Extensions/OutputTestCase.php'; + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class OutputTestCase extends PHPUnit_Extensions_OutputTestCase +{ + public function testExpectOutputStringFooActualFoo() + { + $this->expectOutputString('foo'); + print 'foo'; + } + + public function testExpectOutputStringFooActualBar() + { + $this->expectOutputString('foo'); + print 'bar'; + } + + public function testExpectOutputRegexFooActualFoo() + { + $this->expectOutputRegex('/foo/'); + print 'foo'; + } + + public function testExpectOutputRegexFooActualBar() + { + $this->expectOutputRegex('/foo/'); + print 'bar'; + } +} +?> Property changes on: test/PHPUnit/Tests/_files/OutputTestCase.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/_files/foo.xml =================================================================== --- test/PHPUnit/Tests/_files/foo.xml (revision 0) +++ test/PHPUnit/Tests/_files/foo.xml (revision 0) @@ -0,0 +1 @@ + Property changes on: test/PHPUnit/Tests/_files/foo.xml ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/_files/NonStatic.php =================================================================== --- test/PHPUnit/Tests/_files/NonStatic.php (revision 0) +++ test/PHPUnit/Tests/_files/NonStatic.php (revision 0) @@ -0,0 +1,70 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: NonStatic.php 1985 2007-12-26 18:11:55Z 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__); + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class NonStatic +{ + public function suite() + { + return NULL; + } +} +?> Property changes on: test/PHPUnit/Tests/_files/NonStatic.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/_files/Sleep.php =================================================================== --- test/PHPUnit/Tests/_files/Sleep.php (revision 0) +++ test/PHPUnit/Tests/_files/Sleep.php (revision 0) @@ -0,0 +1,72 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: Sleep.php 1985 2007-12-26 18:11:55Z 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__); + +require_once 'PHPUnit/Extensions/PerformanceTestCase.php'; + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class Sleep extends PHPUnit_Extensions_PerformanceTestCase +{ + public function testSleepTwoSeconds() + { + sleep(2); + } +} +?> Property changes on: test/PHPUnit/Tests/_files/Sleep.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/_files/SetupFailure.php =================================================================== --- test/PHPUnit/Tests/_files/SetupFailure.php (revision 0) +++ test/PHPUnit/Tests/_files/SetupFailure.php (revision 0) @@ -0,0 +1,72 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: SetupFailure.php 1985 2007-12-26 18:11:55Z 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__); + +require_once 'Success.php'; + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class SetupFailure extends Success +{ + protected function setUp() + { + throw new Exception; + } +} +?> Property changes on: test/PHPUnit/Tests/_files/SetupFailure.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/_files/TornDown.php =================================================================== --- test/PHPUnit/Tests/_files/TornDown.php (revision 0) +++ test/PHPUnit/Tests/_files/TornDown.php (revision 0) @@ -0,0 +1,79 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: TornDown.php 1985 2007-12-26 18:11:55Z 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__); + +require_once 'PHPUnit/Framework/TestCase.php'; + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class TornDown extends PHPUnit_Framework_TestCase +{ + public $tornDown = FALSE; + + protected function tearDown() + { + $this->tornDown = TRUE; + } + + protected function runTest() + { + throw new Exception; + } +} +?> Property changes on: test/PHPUnit/Tests/_files/TornDown.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/_files/OneTestCase.php =================================================================== --- test/PHPUnit/Tests/_files/OneTestCase.php (revision 0) +++ test/PHPUnit/Tests/_files/OneTestCase.php (revision 0) @@ -0,0 +1,74 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: OneTestCase.php 1985 2007-12-26 18:11:55Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__); + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class OneTestCase extends PHPUnit_Framework_TestCase +{ + public function noTestCase() + { + } + + public function testCase($arg = '') + { + } +} +?> Property changes on: test/PHPUnit/Tests/_files/OneTestCase.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/_files/ThrowExceptionTestCase.php =================================================================== --- test/PHPUnit/Tests/_files/ThrowExceptionTestCase.php (revision 0) +++ test/PHPUnit/Tests/_files/ThrowExceptionTestCase.php (revision 0) @@ -0,0 +1,70 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: ThrowExceptionTestCase.php 1985 2007-12-26 18:11:55Z 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__); + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class ThrowExceptionTestCase extends PHPUnit_Framework_TestCase +{ + public function test() + { + throw new Exception; + } +} +?> Property changes on: test/PHPUnit/Tests/_files/ThrowExceptionTestCase.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/_files/BankAccount.pmd =================================================================== --- test/PHPUnit/Tests/_files/BankAccount.pmd (revision 0) +++ test/PHPUnit/Tests/_files/BankAccount.pmd (revision 0) @@ -0,0 +1 @@ + Property changes on: test/PHPUnit/Tests/_files/BankAccount.pmd ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/_files/MockRunner.php =================================================================== --- test/PHPUnit/Tests/_files/MockRunner.php (revision 0) +++ test/PHPUnit/Tests/_files/MockRunner.php (revision 0) @@ -0,0 +1,83 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: MockRunner.php 1985 2007-12-26 18:11:55Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; +require_once 'PHPUnit/Runner/BaseTestRunner.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__); + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class MockRunner extends PHPUnit_Runner_BaseTestRunner +{ + public function testEnded($testName) + { + } + + public function testFailed($status, PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e) + { + } + + public function testStarted($testName) + { + } + + protected function runFailed($message) + { + } +} +?> Property changes on: test/PHPUnit/Tests/_files/MockRunner.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/_files/BankAccount.tap =================================================================== --- test/PHPUnit/Tests/_files/BankAccount.tap (revision 0) +++ test/PHPUnit/Tests/_files/BankAccount.tap (revision 0) @@ -0,0 +1,6 @@ +1..3 +# TestSuite "BankAccountTest" started. +ok 1 - testBalanceIsInitiallyZero(BankAccountTest) +ok 2 - testBalanceCannotBecomeNegative(BankAccountTest) +ok 3 - testBalanceCannotBecomeNegative2(BankAccountTest) +# TestSuite "BankAccountTest" ended. Property changes on: test/PHPUnit/Tests/_files/BankAccount.tap ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/_files/Failure.php =================================================================== --- test/PHPUnit/Tests/_files/Failure.php (revision 0) +++ test/PHPUnit/Tests/_files/Failure.php (revision 0) @@ -0,0 +1,71 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: Failure.php 1985 2007-12-26 18:11:55Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__); + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class Failure extends PHPUnit_Framework_TestCase +{ + public function runTest() + { + $this->fail(); + } +} +?> Property changes on: test/PHPUnit/Tests/_files/Failure.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/_files/Error.php =================================================================== --- test/PHPUnit/Tests/_files/Error.php (revision 0) +++ test/PHPUnit/Tests/_files/Error.php (revision 0) @@ -0,0 +1,71 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: Error.php 1985 2007-12-26 18:11:55Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__); + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class Error extends PHPUnit_Framework_TestCase +{ + public function runTest() + { + throw new Exception; + } +} +?> Property changes on: test/PHPUnit/Tests/_files/Error.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/_files/TornDown2.php =================================================================== --- test/PHPUnit/Tests/_files/TornDown2.php (revision 0) +++ test/PHPUnit/Tests/_files/TornDown2.php (revision 0) @@ -0,0 +1,78 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: TornDown2.php 1985 2007-12-26 18:11:55Z 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__); + +require_once 'TornDown.php'; + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class TornDown2 extends TornDown +{ + protected function tearDown() + { + parent::tearDown(); + throw new Exception; + } + + protected function runTest() + { + throw new Exception; + } +} +?> Property changes on: test/PHPUnit/Tests/_files/TornDown2.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/_files/TornDown3.php =================================================================== --- test/PHPUnit/Tests/_files/TornDown3.php (revision 0) +++ test/PHPUnit/Tests/_files/TornDown3.php (revision 0) @@ -0,0 +1,72 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: TornDown3.php 1985 2007-12-26 18:11:55Z 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__); + +require_once 'TornDown.php'; + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class TornDown3 extends TornDown +{ + protected function setUp() + { + throw new Exception; + } +} +?> Property changes on: test/PHPUnit/Tests/_files/TornDown3.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/_files/TornDown4.php =================================================================== --- test/PHPUnit/Tests/_files/TornDown4.php (revision 0) +++ test/PHPUnit/Tests/_files/TornDown4.php (revision 0) @@ -0,0 +1,72 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: TornDown4.php 1985 2007-12-26 18:11:55Z 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__); + +require_once 'TornDown.php'; + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class TornDown4 extends TornDown +{ + protected function tearDown() + { + throw new Exception('tearDown'); + } +} +?> Property changes on: test/PHPUnit/Tests/_files/TornDown4.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/_files/NoTestCaseClass.php =================================================================== --- test/PHPUnit/Tests/_files/NoTestCaseClass.php (revision 0) +++ test/PHPUnit/Tests/_files/NoTestCaseClass.php (revision 0) @@ -0,0 +1,66 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: NoTestCaseClass.php 1985 2007-12-26 18:11:55Z 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__); + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class NoTestCaseClass +{ +} +?> Property changes on: test/PHPUnit/Tests/_files/NoTestCaseClass.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/_files/TornDown5.php =================================================================== --- test/PHPUnit/Tests/_files/TornDown5.php (revision 0) +++ test/PHPUnit/Tests/_files/TornDown5.php (revision 0) @@ -0,0 +1,72 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: TornDown5.php 1985 2007-12-26 18:11:55Z 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__); + +require_once 'TornDown.php'; + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class TornDown5 extends TornDown +{ + protected function setUp() + { + $this->fail(); + } +} +?> Property changes on: test/PHPUnit/Tests/_files/TornDown5.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/_files/BankAccount.xml =================================================================== --- test/PHPUnit/Tests/_files/BankAccount.xml (revision 0) +++ test/PHPUnit/Tests/_files/BankAccount.xml (revision 0) @@ -0,0 +1,8 @@ + + + + + + + + Property changes on: test/PHPUnit/Tests/_files/BankAccount.xml ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/_files/NoArgTestCaseTest.php =================================================================== --- test/PHPUnit/Tests/_files/NoArgTestCaseTest.php (revision 0) +++ test/PHPUnit/Tests/_files/NoArgTestCaseTest.php (revision 0) @@ -0,0 +1,70 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: NoArgTestCaseTest.php 1985 2007-12-26 18:11:55Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__); + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class NoArgTestCaseTest extends PHPUnit_Framework_TestCase +{ + public function testNothing() + { + } +} +?> Property changes on: test/PHPUnit/Tests/_files/NoArgTestCaseTest.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/_files/DoubleTestCase.php =================================================================== --- test/PHPUnit/Tests/_files/DoubleTestCase.php (revision 0) +++ test/PHPUnit/Tests/_files/DoubleTestCase.php (revision 0) @@ -0,0 +1,88 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: DoubleTestCase.php 1985 2007-12-26 18:11:55Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__); + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class DoubleTestCase implements PHPUnit_Framework_Test +{ + protected $testCase; + + public function __construct(PHPUnit_Framework_TestCase $testCase) + { + $this->testCase = $testCase; + } + + public function count() + { + return 2; + } + + public function run(PHPUnit_Framework_TestResult $result = NULL) + { + $result->startTest($this); + + $this->testCase->runBare(); + $this->testCase->runBare(); + + $result->endTest($this, 0); + } +} +?> Property changes on: test/PHPUnit/Tests/_files/DoubleTestCase.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/_files/InheritedTestCase.php =================================================================== --- test/PHPUnit/Tests/_files/InheritedTestCase.php (revision 0) +++ test/PHPUnit/Tests/_files/InheritedTestCase.php (revision 0) @@ -0,0 +1,71 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: InheritedTestCase.php 1985 2007-12-26 18:11:55Z 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__); + +require_once 'OneTestCase.php'; + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class InheritedTestCase extends OneTestCase +{ + public function test2() + { + } +} +?> Property changes on: test/PHPUnit/Tests/_files/InheritedTestCase.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/_files/BankAccount.metrics =================================================================== --- test/PHPUnit/Tests/_files/BankAccount.metrics (revision 0) +++ test/PHPUnit/Tests/_files/BankAccount.metrics (revision 0) @@ -0,0 +1 @@ + Property changes on: test/PHPUnit/Tests/_files/BankAccount.metrics ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/_files/SampleClass.php =================================================================== --- test/PHPUnit/Tests/_files/SampleClass.php (revision 0) +++ test/PHPUnit/Tests/_files/SampleClass.php (revision 0) @@ -0,0 +1,76 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: SampleClass.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/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__); + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class SampleClass +{ + public $a; + protected $b; + protected $c; + + public function __construct($a, $b, $c) + { + $this->a = $a; + $this->b = $b; + $this->c = $c; + } +} +?> Property changes on: test/PHPUnit/Tests/_files/SampleClass.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/_files/Success.php =================================================================== --- test/PHPUnit/Tests/_files/Success.php (revision 0) +++ test/PHPUnit/Tests/_files/Success.php (revision 0) @@ -0,0 +1,71 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: Success.php 1985 2007-12-26 18:11:55Z 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__); + +require_once 'PHPUnit/Framework/TestCase.php'; + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class Success extends PHPUnit_Framework_TestCase +{ + public function runTest() + { + } +} +?> Property changes on: test/PHPUnit/Tests/_files/Success.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/_files/BankAccount.json =================================================================== --- test/PHPUnit/Tests/_files/BankAccount.json (revision 0) +++ test/PHPUnit/Tests/_files/BankAccount.json (revision 0) @@ -0,0 +1 @@ +{"event":"suiteStart","suite":"BankAccountTest","tests":3}{"event":"test","suite":"BankAccountTest","test":"testBalanceIsInitiallyZero(BankAccountTest)","status":"pass","time":0,"trace":[],"message":""}{"event":"test","suite":"BankAccountTest","test":"testBalanceCannotBecomeNegative(BankAccountTest)","status":"pass","time":0,"trace":[],"message":""}{"event":"test","suite":"BankAccountTest","test":"testBalanceCannotBecomeNegative2(BankAccountTest)","status":"pass","time":0,"trace":[],"message":""} Property changes on: test/PHPUnit/Tests/_files/BankAccount.json ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/_files/OverrideTestCase.php =================================================================== --- test/PHPUnit/Tests/_files/OverrideTestCase.php (revision 0) +++ test/PHPUnit/Tests/_files/OverrideTestCase.php (revision 0) @@ -0,0 +1,71 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: OverrideTestCase.php 1985 2007-12-26 18:11:55Z 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__); + +require_once 'OneTestCase.php'; + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class OverrideTestCase extends OneTestCase +{ + public function testCase($arg = '') + { + } +} +?> Property changes on: test/PHPUnit/Tests/_files/OverrideTestCase.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/_files/ThrowNoExceptionTestCase.php =================================================================== --- test/PHPUnit/Tests/_files/ThrowNoExceptionTestCase.php (revision 0) +++ test/PHPUnit/Tests/_files/ThrowNoExceptionTestCase.php (revision 0) @@ -0,0 +1,69 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: ThrowNoExceptionTestCase.php 1985 2007-12-26 18:11:55Z 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__); + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class ThrowNoExceptionTestCase extends PHPUnit_Framework_TestCase +{ + public function test() + { + } +} +?> Property changes on: test/PHPUnit/Tests/_files/ThrowNoExceptionTestCase.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/_files/bar.xml =================================================================== --- test/PHPUnit/Tests/_files/bar.xml (revision 0) +++ test/PHPUnit/Tests/_files/bar.xml (revision 0) @@ -0,0 +1 @@ + Property changes on: test/PHPUnit/Tests/_files/bar.xml ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/_files/NotVoidTestCase.php =================================================================== --- test/PHPUnit/Tests/_files/NotVoidTestCase.php (revision 0) +++ test/PHPUnit/Tests/_files/NotVoidTestCase.php (revision 0) @@ -0,0 +1,67 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: NotVoidTestCase.php 1985 2007-12-26 18:11:55Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__); + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class NotVoidTestCase extends PHPUnit_Framework_TestCase +{ +} +?> Property changes on: test/PHPUnit/Tests/_files/NotVoidTestCase.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/_files/AnInterface.php =================================================================== --- test/PHPUnit/Tests/_files/AnInterface.php (revision 0) +++ test/PHPUnit/Tests/_files/AnInterface.php (revision 0) @@ -0,0 +1,67 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: AnInterface.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/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__); + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +interface AnInterface +{ + public function doSomething(); +} +?> Property changes on: test/PHPUnit/Tests/_files/AnInterface.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/_files/WasRun.php =================================================================== --- test/PHPUnit/Tests/_files/WasRun.php (revision 0) +++ test/PHPUnit/Tests/_files/WasRun.php (revision 0) @@ -0,0 +1,73 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: WasRun.php 1985 2007-12-26 18:11:55Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__); + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class WasRun extends PHPUnit_Framework_TestCase +{ + public $wasRun = FALSE; + + protected function runTest() + { + $this->wasRun = TRUE; + } +} +?> Property changes on: test/PHPUnit/Tests/_files/WasRun.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/_files/ClassWithNonPublicAttributes.php =================================================================== --- test/PHPUnit/Tests/_files/ClassWithNonPublicAttributes.php (revision 0) +++ test/PHPUnit/Tests/_files/ClassWithNonPublicAttributes.php (revision 0) @@ -0,0 +1,85 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: ClassWithNonPublicAttributes.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/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__); + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class ParentClassWithPrivateAttributes +{ + protected static $privateStaticParentAttribute = 'parent'; + protected $privateParentAttribute = 'parent'; +} + +class ClassWithNonPublicAttributes extends ParentClassWithPrivateAttributes +{ + public static $publicStaticAttribute = 'foo'; + protected static $protectedStaticAttribute = 'bar'; + protected static $privateStaticAttribute = 'baz'; + + public $publicAttribute = 'foo'; + public $foo = 1; + public $bar = 2; + protected $protectedAttribute = 'bar'; + protected $privateAttribute = 'baz'; + + public $publicArray = array('foo'); + protected $protectedArray = array('bar'); + protected $privateArray = array('baz'); +} +?> Property changes on: test/PHPUnit/Tests/_files/ClassWithNonPublicAttributes.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/_files/Struct.php =================================================================== --- test/PHPUnit/Tests/_files/Struct.php (revision 0) +++ test/PHPUnit/Tests/_files/Struct.php (revision 0) @@ -0,0 +1,72 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: Struct.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/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__); + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class Struct +{ + public $var; + + public function __construct($var) + { + $this->var = $var; + } +} +?> Property changes on: test/PHPUnit/Tests/_files/Struct.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/AllTests.php =================================================================== --- test/PHPUnit/Tests/AllTests.php (revision 0) +++ test/PHPUnit/Tests/AllTests.php (revision 0) @@ -0,0 +1,107 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: AllTests.php 1985 2007-12-26 18:11:55Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 2.0.0 + */ + +error_reporting(E_ALL | E_STRICT); + +require_once 'PHPUnit/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__); + +if (!defined('PHPUnit_MAIN_METHOD')) { + define('PHPUnit_MAIN_METHOD', 'AllTests::main'); + chdir(dirname(__FILE__)); +} + +require_once 'PHPUnit/Framework/TestSuite.php'; +require_once 'PHPUnit/TextUI/TestRunner.php'; + +require_once 'Framework/AllTests.php'; +require_once 'Extensions/AllTests.php'; +require_once 'Runner/AllTests.php'; +require_once 'Util/AllTests.php'; + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class AllTests +{ + public static function main() + { + PHPUnit_TextUI_TestRunner::run(self::suite()); + } + + public static function suite() + { + $suite = new PHPUnit_Framework_TestSuite('PHPUnit'); + + $suite->addTest(Framework_AllTests::suite()); + $suite->addTest(Extensions_AllTests::suite()); + $suite->addTest(Runner_AllTests::suite()); + $suite->addTest(Util_AllTests::suite()); + + return $suite; + } +} + +if (is_readable(dirname(__FILE__) . '/TestConfiguration.php')) { + require_once 'TestConfiguration.php'; +} else { + require_once 'TestConfiguration.php.dist'; +} + +if (PHPUnit_MAIN_METHOD == 'AllTests::main') { + AllTests::main(); +} +?> Property changes on: test/PHPUnit/Tests/AllTests.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/Runner/AllTests.php =================================================================== --- test/PHPUnit/Tests/Runner/AllTests.php (revision 0) +++ test/PHPUnit/Tests/Runner/AllTests.php (revision 0) @@ -0,0 +1,94 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: AllTests.php 1985 2007-12-26 18:11:55Z 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__); + +if (!defined('PHPUnit_MAIN_METHOD')) { + define('PHPUnit_MAIN_METHOD', 'Runner_AllTests::main'); + chdir(dirname(dirname(__FILE__))); +} + +require_once 'PHPUnit/Framework/TestSuite.php'; +require_once 'PHPUnit/TextUI/TestRunner.php'; +require_once 'PHPUnit/Util/Filter.php'; + +require_once 'Runner/BaseTestRunnerTest.php'; + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class Runner_AllTests +{ + public static function main() + { + PHPUnit_TextUI_TestRunner::run(self::suite()); + } + + public static function suite() + { + $suite = new PHPUnit_Framework_TestSuite('PHPUnit_Runner'); + + $suite->addTestSuite('Runner_BaseTestRunnerTest'); + + return $suite; + } +} + +if (PHPUnit_MAIN_METHOD == 'Runner_AllTests::main') { + Runner_AllTests::main(); +} +?> Property changes on: test/PHPUnit/Tests/Runner/AllTests.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/Runner/BaseTestRunnerTest.php =================================================================== --- test/PHPUnit/Tests/Runner/BaseTestRunnerTest.php (revision 0) +++ test/PHPUnit/Tests/Runner/BaseTestRunnerTest.php (revision 0) @@ -0,0 +1,72 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: BaseTestRunnerTest.php 1985 2007-12-26 18:11:55Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit/Framework/TestCase.php'; + +require_once '_files/MockRunner.php'; +require_once '_files/NonStatic.php'; + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class Runner_BaseTestRunnerTest extends PHPUnit_Framework_TestCase +{ + public function testInvokeNonStaticSuite() + { + $runner = new MockRunner; + $runner->getTest('NonStatic'); + } +} +?> Property changes on: test/PHPUnit/Tests/Runner/BaseTestRunnerTest.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/Framework/SuiteTest.php =================================================================== --- test/PHPUnit/Tests/Framework/SuiteTest.php (revision 0) +++ test/PHPUnit/Tests/Framework/SuiteTest.php (revision 0) @@ -0,0 +1,198 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: SuiteTest.php 1985 2007-12-26 18:11:55Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit/Framework/TestCase.php'; +require_once 'PHPUnit/Framework/TestResult.php'; +require_once 'PHPUnit/Framework/TestSuite.php'; + +require_once '_files/InheritedTestCase.php'; +require_once '_files/NoTestCaseClass.php'; +require_once '_files/NoTestCases.php'; +require_once '_files/NotPublicTestCase.php'; +require_once '_files/NotVoidTestCase.php'; +require_once '_files/OneTestCase.php'; +require_once '_files/OverrideTestCase.php'; + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class Framework_SuiteTest extends PHPUnit_Framework_TestCase { + protected $result; + + protected function setUp() + { + $this->result = new PHPUnit_Framework_TestResult; + } + + public static function suite() + { + $suite = new PHPUnit_Framework_TestSuite; + + $suite->addTest(new Framework_SuiteTest('testAddTestSuite')); + $suite->addTest(new Framework_SuiteTest('testInheritedTests')); + $suite->addTest(new Framework_SuiteTest('testNoTestCases')); + $suite->addTest(new Framework_SuiteTest('testNoTestCaseClass')); + $suite->addTest(new Framework_SuiteTest('testNotExistingTestCase')); + $suite->addTest(new Framework_SuiteTest('testNotPublicTestCase')); + $suite->addTest(new Framework_SuiteTest('testNotVoidTestCase')); + $suite->addTest(new Framework_SuiteTest('testOneTestCase')); + $suite->addTest(new Framework_SuiteTest('testShadowedTests')); + + return $suite; + } + + public function testAddTestSuite() + { + $suite = new PHPUnit_Framework_TestSuite( + 'OneTestCase' + ); + + $suite->run($this->result); + + $this->assertEquals(1, count($this->result)); + } + + public function testInheritedTests() + { + $suite = new PHPUnit_Framework_TestSuite( + 'InheritedTestCase' + ); + + $suite->run($this->result); + + $this->assertTrue($this->result->wasSuccessful()); + $this->assertEquals(2, count($this->result)); + } + + public function testNoTestCases() + { + $suite = new PHPUnit_Framework_TestSuite( + 'NoTestCases' + ); + + $suite->run($this->result); + + $this->assertTrue(!$this->result->wasSuccessful()); + $this->assertEquals(1, $this->result->failureCount()); + $this->assertEquals(1, count($this->result)); + } + + public function testNoTestCaseClass() + { + $suite = new PHPUnit_Framework_TestSuite( + 'NoTestCaseClass' + ); + + $suite->run($this->result); + + $this->assertTrue(!$this->result->wasSuccessful()); + $this->assertEquals(1, count($this->result)); + } + + public function testNotExistingTestCase() + { + $suite = new Framework_SuiteTest('notExistingMethod'); + + $suite->run($this->result); + + $this->assertEquals(0, $this->result->errorCount()); + $this->assertEquals(1, $this->result->failureCount()); + $this->assertEquals(1, count($this->result)); + } + + public function testNotPublicTestCase() + { + $suite = new PHPUnit_Framework_TestSuite( + 'NotPublicTestCase' + ); + + $this->assertEquals(2, count($suite)); + } + + public function testNotVoidTestCase() + { + $suite = new PHPUnit_Framework_TestSuite( + 'NotVoidTestCase' + ); + + $this->assertEquals(1, count($suite)); + } + + public function testOneTestCase() + { + $suite = new PHPUnit_Framework_TestSuite( + 'OneTestCase' + ); + + $suite->run($this->result); + + $this->assertEquals(0, $this->result->errorCount()); + $this->assertEquals(0, $this->result->failureCount()); + $this->assertEquals(1, count($this->result)); + $this->assertTrue($this->result->wasSuccessful()); + } + + public function testShadowedTests() + { + $suite = new PHPUnit_Framework_TestSuite( + 'OverrideTestCase' + ); + + $suite->run($this->result); + + $this->assertEquals(1, count($this->result)); + } +} +?> Property changes on: test/PHPUnit/Tests/Framework/SuiteTest.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/Framework/AllTests.php =================================================================== --- test/PHPUnit/Tests/Framework/AllTests.php (revision 0) +++ test/PHPUnit/Tests/Framework/AllTests.php (revision 0) @@ -0,0 +1,108 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: AllTests.php 1985 2007-12-26 18:11:55Z 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__); + +if (!defined('PHPUnit_MAIN_METHOD')) { + define('PHPUnit_MAIN_METHOD', 'Framework_AllTests::main'); + chdir(dirname(dirname(__FILE__))); +} + +require_once 'PHPUnit/Framework/TestSuite.php'; +require_once 'PHPUnit/TextUI/TestRunner.php'; +require_once 'PHPUnit/Util/Filter.php'; + +require_once 'Framework/AssertTest.php'; +require_once 'Framework/ComparisonFailureTest.php'; +require_once 'Framework/ConstraintTest.php'; +require_once 'Framework/MockObjectTest.php'; +require_once 'Framework/SuiteTest.php'; +require_once 'Framework/TestCaseTest.php'; +require_once 'Framework/TestImplementorTest.php'; +require_once 'Framework/TestListenerTest.php'; + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class Framework_AllTests +{ + public static function main() + { + PHPUnit_TextUI_TestRunner::run(self::suite()); + } + + public static function suite() + { + $suite = new PHPUnit_Framework_TestSuite('PHPUnit_Framework'); + + $suite->addTestSuite('Framework_AssertTest'); + $suite->addTestSuite('Framework_ComparisonFailureTest'); + $suite->addTestSuite('Framework_ConstraintTest'); + $suite->addTestSuite('Framework_MockObjectTest'); + $suite->addTestSuite('Framework_SuiteTest'); + $suite->addTestSuite('Framework_TestCaseTest'); + $suite->addTestSuite('Framework_TestImplementorTest'); + $suite->addTestSuite('Framework_TestListenerTest'); + + return $suite; + } +} + +if (PHPUnit_MAIN_METHOD == 'Framework_AllTests::main') { + Framework_AllTests::main(); +} +?> Property changes on: test/PHPUnit/Tests/Framework/AllTests.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/Framework/TestCaseTest.php =================================================================== --- test/PHPUnit/Tests/Framework/TestCaseTest.php (revision 0) +++ test/PHPUnit/Tests/Framework/TestCaseTest.php (revision 0) @@ -0,0 +1,235 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: TestCaseTest.php 1985 2007-12-26 18:11:55Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit/Framework/TestCase.php'; + +require_once '_files/Error.php'; +require_once '_files/Failure.php'; +require_once '_files/NoArgTestCaseTest.php'; +require_once '_files/SetupFailure.php'; +require_once '_files/Success.php'; +require_once '_files/TearDownFailure.php'; +require_once '_files/ThrowExceptionTestCase.php'; +require_once '_files/ThrowNoExceptionTestCase.php'; +require_once '_files/TornDown.php'; +require_once '_files/TornDown2.php'; +require_once '_files/TornDown3.php'; +require_once '_files/TornDown4.php'; +require_once '_files/WasRun.php'; + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class Framework_TestCaseTest extends PHPUnit_Framework_TestCase +{ + public function testCaseToString() + { + $this->assertEquals( + 'testCaseToString(Framework_TestCaseTest)', + $this->toString() + ); + } + + public function testError() + { + $this->verifyError(new Error); + } + + public function testExceptionRunningAndTearDown() + { + $result = new PHPUnit_Framework_TestResult(); + $t = new TornDown4; + + $t->run($result); + + $errors = $result->errors(); + + $this->assertEquals( + 'tearDown', + $errors[0]->thrownException()->getMessage() + ); + } + + public function testFailure() + { + $this->verifyFailure(new Failure); + } + + /* PHP does not support anonymous classes + public function testNamelessTestCase() + { + } + */ + + public function testNoArgTestCasePasses() + { + $result = new PHPUnit_Framework_TestResult(); + $t = new PHPUnit_Framework_TestSuite('NoArgTestCaseTest'); + + $t->run($result); + + $this->assertEquals(1, count($result)); + $this->assertEquals(0, $result->failureCount()); + $this->assertEquals(0, $result->errorCount()); + } + + public function testRunAndTearDownFails() + { + $fails = new TornDown2; + + $this->verifyError($fails); + $this->assertTrue($fails->tornDown); + } + + public function testSetupFails() + { + $this->verifyError(new SetupFailure); + } + + public function testSuccess() + { + $this->verifySuccess(new Success); + } + + public function testTearDownAfterError() + { + $fails = new TornDown; + + $this->verifyError($fails); + $this->assertTrue($fails->tornDown); + } + + public function testTearDownFails() + { + $this->verifyError(new TearDownFailure); + } + + public function testTearDownSetupFails() + { + $fails = new TornDown3; + + $this->verifyError($fails); + $this->assertFalse($fails->tornDown); + } + + public function testWasRun() + { + $test = new WasRun; + $test->run(); + + $this->assertTrue($test->wasRun); + } + + public function testException() + { + $test = new ThrowExceptionTestCase('test'); + $test->setExpectedException('Exception'); + + $result = $test->run(); + + $this->assertEquals(1, count($result)); + $this->assertTrue($result->wasSuccessful()); + } + + public function testNoException() + { + $test = new ThrowNoExceptionTestCase('test'); + $test->setExpectedException('Exception'); + + $result = $test->run(); + + $this->assertEquals(1, $result->failureCount()); + $this->assertEquals(1, count($result)); + } + + public function testWrongException() + { + $test = new ThrowExceptionTestCase('test'); + $test->setExpectedException('RuntimeException'); + + $result = $test->run(); + + $this->assertEquals(1, $result->errorCount()); + $this->assertEquals(1, count($result)); + } + + protected function verifyError(PHPUnit_Framework_TestCase $test) + { + $result = $test->run(); + + $this->assertEquals(1, $result->errorCount()); + $this->assertEquals(0, $result->failureCount()); + $this->assertEquals(1, count($result)); + } + + protected function verifyFailure(PHPUnit_Framework_TestCase $test) + { + $result = $test->run(); + + $this->assertEquals(0, $result->errorCount()); + $this->assertEquals(1, $result->failureCount()); + $this->assertEquals(1, count($result)); + } + + protected function verifySuccess(PHPUnit_Framework_TestCase $test) + { + $result = $test->run(); + + $this->assertEquals(0, $result->errorCount()); + $this->assertEquals(0, $result->failureCount()); + $this->assertEquals(1, count($result)); + } +} +?> Property changes on: test/PHPUnit/Tests/Framework/TestCaseTest.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/Framework/TestImplementorTest.php =================================================================== --- test/PHPUnit/Tests/Framework/TestImplementorTest.php (revision 0) +++ test/PHPUnit/Tests/Framework/TestImplementorTest.php (revision 0) @@ -0,0 +1,87 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: TestImplementorTest.php 1985 2007-12-26 18:11:55Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit/Framework/TestCase.php'; +require_once 'PHPUnit/Framework/TestResult.php'; + +require_once '_files/DoubleTestCase.php'; +require_once '_files/Success.php'; + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class Framework_TestImplementorTest extends PHPUnit_Framework_TestCase +{ + protected $test; + + public function __construct() + { + $this->test = new DoubleTestCase( + new Success + ); + } + + public function testSuccessfulRun() + { + $result = new PHPUnit_Framework_TestResult; + + $this->test->run($result); + + $this->assertEquals(count($this->test), count($result)); + $this->assertEquals(0, $result->errorCount()); + $this->assertEquals(0, $result->failureCount()); + } +} +?> Property changes on: test/PHPUnit/Tests/Framework/TestImplementorTest.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/Framework/MockObjectTest.php =================================================================== --- test/PHPUnit/Tests/Framework/MockObjectTest.php (revision 0) +++ test/PHPUnit/Tests/Framework/MockObjectTest.php (revision 0) @@ -0,0 +1,149 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: MockObjectTest.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/TestCase.php'; + +require_once '_files/AnInterface.php'; + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @author Patrick M??ller + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class Framework_MockObjectTest extends PHPUnit_Framework_TestCase +{ + public function testMockedMethodIsNeverCalled() + { + $mock = $this->getMock('AnInterface'); + $mock->expects($this->never()) + ->method('doSomething'); + } + + public function testMockedMethodIsCalledAtLeastOnce() + { + $mock = $this->getMock('AnInterface'); + $mock->expects($this->atLeastOnce()) + ->method('doSomething'); + + $mock->doSomething(); + } + + public function testMockedMethodIsCalledAtLeastOnce2() + { + $mock = $this->getMock('AnInterface'); + $mock->expects($this->atLeastOnce()) + ->method('doSomething'); + + $mock->doSomething(); + $mock->doSomething(); + } + + public function testMockedMethodIsCalledOnce() + { + $mock = $this->getMock('AnInterface'); + $mock->expects($this->once()) + ->method('doSomething'); + + $mock->doSomething(); + } + + public function testMockedMethodIsCalledOnceWithParameter() + { + $mock = $this->getMock('AnInterface'); + $mock->expects($this->once()) + ->method('doSomething') + ->with($this->equalTo('something')); + + $mock->doSomething('something'); + } + + public function testMockedMethodIsCalledExactly() + { + $mock = $this->getMock('AnInterface'); + $mock->expects($this->exactly(2)) + ->method('doSomething'); + + $mock->doSomething(); + $mock->doSomething(); + } + + public function testStubbedException() + { + $mock = $this->getMock('AnInterface'); + $mock->expects($this->any()) + ->method('doSomething') + ->will($this->throwException(new Exception)); + + try { + $mock->doSomething(); + } + + catch (Exception $e) { + return; + } + + $this->fail(); + } + + public function testStubbedReturnValue() + { + $mock = $this->getMock('AnInterface'); + $mock->expects($this->any()) + ->method('doSomething') + ->will($this->returnValue('something')); + + $this->assertEquals('something', $mock->doSomething()); + } +} +?> Property changes on: test/PHPUnit/Tests/Framework/MockObjectTest.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/Framework/AssertTest.php =================================================================== --- test/PHPUnit/Tests/Framework/AssertTest.php (revision 0) +++ test/PHPUnit/Tests/Framework/AssertTest.php (revision 0) @@ -0,0 +1,2291 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: AssertTest.php 2129 2008-01-16 11:08:24Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit/Framework/TestCase.php'; + +require_once '_files/ClassWithNonPublicAttributes.php'; +require_once '_files/SampleClass.php'; +require_once '_files/Struct.php'; +require_once '_files/TestIterator.php'; +require_once '_files/WasRun.php'; + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class Framework_AssertTest extends PHPUnit_Framework_TestCase +{ + public function testFail() + { + try { + $this->fail(); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertArrayContainsObject() + { + $a = new stdClass; + $b = new stdClass; + + $this->assertContains($a, array($a)); + + try { + $this->assertContains($a, array($b)); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertArrayContainsString() + { + $this->assertContains('foo', array('foo')); + + try { + $this->assertContains('foo', array('bar')); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertArrayHasIntegerKey() + { + $this->assertArrayHasKey(0, array('foo')); + + try { + $this->assertArrayHasKey(1, array('foo')); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertArrayNotHasIntegerKey() + { + $this->assertArrayNotHasKey(1, array('foo')); + + try { + $this->assertArrayNotHasKey(0, array('foo')); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertArrayHasStringKey() + { + $this->assertArrayHasKey('foo', array('foo' => 'bar')); + + try { + $this->assertArrayHasKey('bar', array('foo' => 'bar')); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertArrayNotHasStringKey() + { + $this->assertArrayNotHasKey('bar', array('foo' => 'bar')); + + try { + $this->assertArrayNotHasKey('foo', array('foo' => 'bar')); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertIteratorContainsObject() + { + $foo = new stdClass; + + $this->assertContains($foo, new TestIterator(array($foo))); + + try { + $this->assertContains($foo, new TestIterator(array(new stdClass))); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertIteratorContainsString() + { + $this->assertContains('foo', new TestIterator(array('foo'))); + + try { + $this->assertContains('foo', new TestIterator(array('bar'))); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertStringContainsString() + { + $this->assertContains('foo', 'foobar'); + + try { + $this->assertContains('foo', 'bar'); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertArrayNotContainsObject() + { + $a = new stdClass; + $b = new stdClass; + + $this->assertNotContains($a, array($b)); + + try { + $this->assertNotContains($a, array($a)); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertArrayNotContainsString() + { + $this->assertNotContains('foo', array('bar')); + + try { + $this->assertNotContains('foo', array('foo')); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertStringNotContainsString() + { + $this->assertNotContains('foo', 'bar'); + + try { + $this->assertNotContains('foo', 'foo'); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertArrayContainsOnlyIntegers() + { + $this->assertContainsOnly('integer', array(1, 2, 3)); + + try { + $this->assertContainsOnly('integer', array("1", 2, 3)); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertArrayNotContainsOnlyIntegers() + { + $this->assertNotContainsOnly('integer', array("1", 2, 3)); + + try { + $this->assertNotContainsOnly('integer', array(1, 2, 3)); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertArrayContainsOnlyStdClass() + { + $this->assertContainsOnly('StdClass', array(new StdClass)); + + try { + $this->assertContainsOnly('StdClass', array('StdClass')); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertArrayNotContainsOnlyStdClass() + { + $this->assertNotContainsOnly('StdClass', array('StdClass')); + + try { + $this->assertNotContainsOnly('StdClass', array(new StdClass)); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertEqualsArray() + { + $this->assertEquals(array('a', 'b' => array(1, 2)), array('a', 'b' => array(1, 2))); + + try { + $this->assertEquals(array('a', 'b' => array(1, 2)), array('a', 'b' => array(2, 1))); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertNotEqualsArray() + { + $this->assertNotEquals(array('a', 'b' => array(1, 2)), array('a', 'b' => array(2, 1))); + + try { + $this->assertNotEquals(array('a', 'b' => array(1, 2)), array('a', 'b' => array(1, 2))); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertEqualsFloat() + { + $this->assertEquals(2.3, 2.3); + + try { + $this->assertEquals(2.3, 4.2); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertNotEqualsFloat() + { + $this->assertNotEquals(2.3, 4.2); + + try { + $this->assertNotEquals(2.3, 2.3); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertEqualsFloatDelta() + { + $this->assertEquals(2.3, 2.5, '', 0.5); + + try { + $this->assertEquals(2.3, 4.2, '', 0.5); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertNotEqualsFloatDelta() + { + $this->assertNotEquals(2.3, 4.2, '', 0.5); + + try { + $this->assertNotEquals(2.3, 2.5, '', 0.5); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertEqualsArrayFloatDelta() + { + $this->assertEquals(array(2.3), array(2.5), '', 0.5); + + try { + $this->assertEquals(array(2.3), array(4.2), '', 0.5); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertNotEqualsArrayFloatDelta() + { + $this->assertNotEquals(array(2.3), array(4.2), '', 0.5); + + try { + $this->assertNotEquals(array(2.3), array(2.5), '', 0.5); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertEqualsStructFloatDelta() + { + $this->assertEquals(new Struct(2.3), new Struct(2.5), '', 0.5); + + try { + $this->assertEquals(new Struct(2.3), new Struct(4.2), '', 0.5); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertNotEqualsStructFloatDelta() + { + $this->assertNotEquals(new Struct(2.3), new Struct(4.2), '', 0.5); + + try { + $this->assertNotEquals(new Struct(2.3), new Struct(2.5), '', 0.5); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertEqualsArrayStructFloatDelta() + { + $this->assertEquals(array(new Struct(2.3)), array(new Struct(2.5)), '', 0.5); + + try { + $this->assertEquals(array(new Struct(2.3)), array(new Struct(4.2)), '', 0.5); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertNotEqualsArrayStructFloatDelta() + { + $this->assertNotEquals(array(new Struct(2.3)), array(new Struct(4.2)), '', 0.5); + + try { + $this->assertNotEquals(array(new Struct(2.3)), array(new Struct(2.5)), '', 0.5); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertEqualsArrayOfArrayFloatDelta() + { + $this->assertEquals(array(array(2.3)), array(array(2.5)), '', 0.5); + + try { + $this->assertEquals(array(array(2.3)), array(array(4.2)), '', 0.5); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertNotEqualsArrayOfArrayFloatDelta() + { + $this->assertNotEquals(array(array(2.3)), array(array(4.2)), '', 0.5); + + try { + $this->assertNotEquals(array(array(2.3)), array(array(2.5)), '', 0.5); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertEqualsInteger() + { + $this->assertEquals(23, 23); + + try { + $this->assertEquals(23, 42); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertNotEqualsInteger() + { + $this->assertNotEquals(23, 42); + + try { + $this->assertNotEquals(23, 23); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertEqualsObject() + { + $a = new SampleClass( 4, 8, 15); + $b = new SampleClass(16, 23, 42); + + $this->assertEquals($a, $a); + + try { + $this->assertEquals($a, $b); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertNotEqualsObject() + { + $a = new SampleClass( 4, 8, 15); + $b = new SampleClass(16, 23, 42); + + $this->assertNotEquals($a, $b); + + try { + $this->assertNotEquals($a, $a); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertEqualsString() + { + $this->assertEquals('ab', 'ab'); + + try { + $this->assertEquals('ab', 'ba'); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertNotEqualsString() + { + $this->assertNotEquals('ab', 'ba'); + + try { + $this->assertNotEquals('ab', 'ab'); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertXmlFileEqualsXmlFile() + { + $this->assertXmlFileEqualsXmlFile( + dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'foo.xml', + dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'foo.xml' + ); + + try { + $this->assertXmlFileEqualsXmlFile( + dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'foo.xml', + dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'bar.xml' + ); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertXmlFileNotEqualsXmlFile() + { + $this->assertXmlFileNotEqualsXmlFile( + dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'foo.xml', + dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'bar.xml' + ); + + try { + $this->assertXmlFileNotEqualsXmlFile( + dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'foo.xml', + dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'foo.xml' + ); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertXmlStringEqualsXmlString() + { + $this->assertXmlStringEqualsXmlString('', ''); + + try { + $this->assertXmlStringEqualsXmlString('', ''); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertXmlStringNotEqualsXmlString() + { + $this->assertXmlStringNotEqualsXmlString('', ''); + + try { + $this->assertXmlStringNotEqualsXmlString('', ''); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertEqualsDOMDocument() + { + $expected = new DOMDocument; + $expected->loadXML(''); + + $actual = new DOMDocument; + $actual->loadXML(''); + + $this->assertEquals($expected, $actual); + + try { + $this->assertNotEquals($expected, $actual); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertEqualsDOMDocument2() + { + $expected = new DOMDocument; + $expected->loadXML(''); + + $actual = new DOMDocument; + $actual->loadXML(''); + + $this->assertNotEquals($expected, $actual); + + try { + $this->assertEquals($expected, $actual); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertEqualsDOMDocument3() + { + $expected = new DOMDocument; + $expected->loadXML(''); + + $actual = new DOMDocument; + $actual->loadXML(''); + + $this->assertEquals($expected, $actual); + + try { + $this->assertNotEquals($expected, $actual); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertEqualsDOMDocument4() + { + $expected = new DOMDocument; + $expected->loadXML(''); + + $actual = new DOMDocument; + $actual->loadXML(''); + + $this->assertEquals($expected, $actual); + + try { + $this->assertNotEquals($expected, $actual); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertEqualsDOMDocument5() + { + $expected = new DOMDocument; + $expected->loadXML(''); + + $actual = new DOMDocument; + $actual->loadXML(''); + + $this->assertNotEquals($expected, $actual); + + try { + $this->assertEquals($expected, $actual); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertEqualsDOMDocument6() + { + $expected = new DOMDocument; + $expected->loadXML(' bar '); + + $actual = new DOMDocument; + $actual->loadXML(''); + + $this->assertNotEquals($expected, $actual); + + try { + $this->assertEquals($expected, $actual); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertEqualsDOMDocument7() + { + $expected = new DOMDocument; + $expected->loadXML(''); + + $actual = new DOMDocument; + $actual->loadXML(''); + + $this->assertNotEquals($expected, $actual); + + try { + $this->assertEquals($expected, $actual); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertEqualsDOMDocument8() + { + $expected = new DOMDocument; + $expected->loadXML("\n \n"); + + $actual = new DOMDocument; + $actual->loadXML(''); + + $this->assertEquals($expected, $actual); + + try { + $this->assertNotEquals($expected, $actual); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertEqualsDOMDocument9() + { + $expected = new DOMDocument; + $expected->loadXML(' bar '); + + $actual = new DOMDocument; + $actual->loadXML(' bir '); + + $this->assertNotEquals($expected, $actual); + + try { + $this->assertEquals($expected, $actual); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertStringEqualsNumeric() + { + $this->assertEquals('0', 0); + + try { + $this->assertEquals('0', 1); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertStringEqualsNumeric2() + { + $this->assertNotEquals('A', 0); + } + + public function testAssertFileExists() + { + $this->assertFileExists(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'AllTests.php'); + + try { + $this->assertFileExists(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'NotExisting'); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertFileNotExists() + { + $this->assertFileNotExists(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'NotExisting'); + + try { + $this->assertFileNotExists(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'AllTests.php'); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertObjectHasAttribute() + { + $o = new WasRun('runTest'); + + $this->assertObjectHasAttribute('wasRun', $o); + + try { + $this->assertObjectHasAttribute('foo', $o); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertObjectNotHasAttribute() + { + $o = new WasRun('runTest'); + + $this->assertObjectNotHasAttribute('foo', $o); + + try { + $this->assertObjectNotHasAttribute('wasRun', $o); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertNull() + { + $this->assertNull(NULL); + + try { + $this->assertNull(new stdClass); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertNotNull() + { + $this->assertNotNull(new stdClass); + + try { + $this->assertNotNull(NULL); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertTrue() + { + $this->assertTrue(TRUE); + + try { + $this->assertTrue(FALSE); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertFalse() + { + $this->assertFalse(FALSE); + + try { + $this->assertFalse(TRUE); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertRegExp() + { + $this->assertRegExp('/foo/', 'foobar'); + + try { + $this->assertRegExp('/foo/', 'bar'); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertNotRegExp() + { + $this->assertNotRegExp('/foo/', 'bar'); + + try { + $this->assertNotRegExp('/foo/', 'foobar'); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertSame() + { + $o = new stdClass; + + $this->assertSame($o, $o); + + try { + $this->assertSame( + new stdClass, + new stdClass + ); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertSame2() + { + $this->assertSame(TRUE, TRUE); + $this->assertSame(FALSE, FALSE); + + try { + $this->assertSame(TRUE, FALSE); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertNotSame() + { + $this->assertNotSame( + new stdClass, + NULL + ); + + $this->assertNotSame( + NULL, + new stdClass + ); + + $this->assertNotSame( + new stdClass, + new stdClass + ); + + $o = new stdClass; + + try { + $this->assertNotSame($o, $o); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertNotSame2() + { + $this->assertNotSame(TRUE, FALSE); + $this->assertNotSame(FALSE, TRUE); + + try { + $this->assertNotSame(TRUE, TRUE); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertNotSameFailsNull() + { + try { + $this->assertNotSame(NULL, NULL); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertTypeArray() + { + $this->assertType('array', array()); + + try { + $this->assertType('array', 'string'); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertNotTypeArray() + { + $this->assertNotType('array', 'string'); + + try { + $this->assertNotType('array', array()); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertTypeBool() + { + $this->assertType('bool', TRUE); + + try { + $this->assertType('bool', 'string'); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertNotTypeBool() + { + $this->assertNotType('bool', 'string'); + + try { + $this->assertNotType('bool', TRUE); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertTypeClass() + { + $this->assertType('stdClass', new stdClass); + + try { + $this->assertType('stdClass', new Exception); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertNotTypeClass() + { + $this->assertNotType('stdClass', new Exception); + + try { + $this->assertNotType('stdClass', new stdClass); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertTypeFloat() + { + $this->assertType('float', 22.04); + + try { + $this->assertType('integer', 'string'); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertNotTypeFloat() + { + $this->assertNotType('float', 'string'); + + try { + $this->assertNotType('float', 22.04); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertTypeInteger() + { + $this->assertType('integer', 2204); + + try { + $this->assertType('integer', 'string'); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertNotTypeInteger() + { + $this->assertNotType('integer', 'string'); + + try { + $this->assertNotType('integer', 2204); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertTypeNull() + { + $this->assertType('null', NULL); + + try { + $this->assertType('null', 'string'); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertNotTypeNull() + { + $this->assertNotType('null', 'string'); + + try { + $this->assertNotType('null', NULL); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertTypeObject() + { + $this->assertType('object', new stdClass); + + try { + $this->assertType('object', 'string'); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertNotTypeObject() + { + $this->assertNotType('object', 'string'); + + try { + $this->assertNotType('object', new stdClass); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertTypeString() + { + $this->assertType('string', 'string'); + + try { + $this->assertType('string', 2204); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertNotTypeString() + { + $this->assertNotType('string', 2204); + + try { + $this->assertNotType('string', 'string'); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testGreaterThan() + { + $this->assertGreaterThan(1, 2); + + try { + $this->assertGreaterThan(2, 1); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAttributeGreaterThan() + { + $this->assertAttributeGreaterThan( + 1, 'bar', new ClassWithNonPublicAttributes + ); + + try { + $this->assertAttributeGreaterThan( + 1, 'foo', new ClassWithNonPublicAttributes + ); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testGreaterThanOrEqual() + { + $this->assertGreaterThanOrEqual(1, 2); + + try { + $this->assertGreaterThanOrEqual(2, 1); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAttributeGreaterThanOrEqual() + { + $this->assertAttributeGreaterThanOrEqual( + 1, 'bar', new ClassWithNonPublicAttributes + ); + + try { + $this->assertAttributeGreaterThanOrEqual( + 2, 'foo', new ClassWithNonPublicAttributes + ); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testLessThan() + { + $this->assertLessThan(2, 1); + + try { + $this->assertLessThan(1, 2); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAttributeLessThan() + { + $this->assertAttributeLessThan( + 2, 'foo', new ClassWithNonPublicAttributes + ); + + try { + $this->assertAttributeLessThan( + 1, 'bar', new ClassWithNonPublicAttributes + ); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testLessThanOrEqual() + { + $this->assertLessThanOrEqual(2, 1); + + try { + $this->assertLessThanOrEqual(1, 2); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAttributeLessThanOrEqual() + { + $this->assertAttributeLessThanOrEqual( + 2, 'foo', new ClassWithNonPublicAttributes + ); + + try { + $this->assertAttributeLessThanOrEqual( + 1, 'bar', new ClassWithNonPublicAttributes + ); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testGetObjectAttribute() + { + $obj = new ClassWithNonPublicAttributes; + + $this->assertEquals('foo', $this->readAttribute($obj, 'publicAttribute')); + $this->assertEquals('bar', $this->readAttribute($obj, 'protectedAttribute')); + $this->assertEquals('baz', $this->readAttribute($obj, 'privateAttribute')); + $this->assertEquals('parent', $this->readAttribute($obj, 'privateParentAttribute')); + } + + public function testGetStaticAttribute() + { + $this->assertEquals('foo', $this->readAttribute('ClassWithNonPublicAttributes', 'publicStaticAttribute')); + $this->assertEquals('bar', $this->readAttribute('ClassWithNonPublicAttributes', 'protectedStaticAttribute')); + $this->assertEquals('baz', $this->readAttribute('ClassWithNonPublicAttributes', 'privateStaticAttribute')); + $this->assertEquals('parent', $this->readAttribute('ClassWithNonPublicAttributes', 'privateStaticParentAttribute')); + } + + public function testAssertPublicAttributeContains() + { + $obj = new ClassWithNonPublicAttributes; + + $this->assertAttributeContains('foo', 'publicArray', $obj); + + try { + $this->assertAttributeContains('bar', 'publicArray', $obj); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertPublicAttributeContainsOnly() + { + $obj = new ClassWithNonPublicAttributes; + + $this->assertAttributeContainsOnly('string', 'publicArray', $obj); + + try { + $this->assertAttributeContainsOnly('integer', 'publicArray', $obj); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertPublicAttributeNotContains() + { + $obj = new ClassWithNonPublicAttributes; + + $this->assertAttributeNotContains('bar', 'publicArray', $obj); + + try { + $this->assertAttributeNotContains('foo', 'publicArray', $obj); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertPublicAttributeNotContainsOnly() + { + $obj = new ClassWithNonPublicAttributes; + + $this->assertAttributeNotContainsOnly('integer', 'publicArray', $obj); + + try { + $this->assertAttributeNotContainsOnly('string', 'publicArray', $obj); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertProtectedAttributeContains() + { + $obj = new ClassWithNonPublicAttributes; + + $this->assertAttributeContains('bar', 'protectedArray', $obj); + + try { + $this->assertAttributeContains('foo', 'protectedArray', $obj); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertProtectedAttributeNotContains() + { + $obj = new ClassWithNonPublicAttributes; + + $this->assertAttributeNotContains('foo', 'protectedArray', $obj); + + try { + $this->assertAttributeNotContains('bar', 'protectedArray', $obj); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertPrivateAttributeContains() + { + $obj = new ClassWithNonPublicAttributes; + + $this->assertAttributeContains('baz', 'privateArray', $obj); + + try { + $this->assertAttributeContains('foo', 'privateArray', $obj); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertPrivateAttributeNotContains() + { + $obj = new ClassWithNonPublicAttributes; + + $this->assertAttributeNotContains('foo', 'privateArray', $obj); + + try { + $this->assertAttributeNotContains('baz', 'privateArray', $obj); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertPublicAttributeEquals() + { + $obj = new ClassWithNonPublicAttributes; + + $this->assertAttributeEquals('foo', 'publicAttribute', $obj); + + try { + $this->assertAttributeEquals('bar', 'publicAttribute', $obj); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertPublicAttributeNotEquals() + { + $obj = new ClassWithNonPublicAttributes; + + $this->assertAttributeNotEquals('bar', 'publicAttribute', $obj); + + try { + $this->assertAttributeNotEquals('foo', 'publicAttribute', $obj); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertPublicAttributeSame() + { + $obj = new ClassWithNonPublicAttributes; + + $this->assertAttributeSame('foo', 'publicAttribute', $obj); + + try { + $this->assertAttributeSame('bar', 'publicAttribute', $obj); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertPublicAttributeNotSame() + { + $obj = new ClassWithNonPublicAttributes; + + $this->assertAttributeNotSame('bar', 'publicAttribute', $obj); + + try { + $this->assertAttributeNotSame('foo', 'publicAttribute', $obj); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertProtectedAttributeEquals() + { + $obj = new ClassWithNonPublicAttributes; + + $this->assertAttributeEquals('bar', 'protectedAttribute', $obj); + + try { + $this->assertAttributeEquals('foo', 'protectedAttribute', $obj); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertProtectedAttributeNotEquals() + { + $obj = new ClassWithNonPublicAttributes; + + $this->assertAttributeNotEquals('foo', 'protectedAttribute', $obj); + + try { + $this->assertAttributeNotEquals('bar', 'protectedAttribute', $obj); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertPrivateAttributeEquals() + { + $obj = new ClassWithNonPublicAttributes; + + $this->assertAttributeEquals('baz', 'privateAttribute', $obj); + + try { + $this->assertAttributeEquals('foo', 'privateAttribute', $obj); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertPrivateAttributeNotEquals() + { + $obj = new ClassWithNonPublicAttributes; + + $this->assertAttributeNotEquals('foo', 'privateAttribute', $obj); + + try { + $this->assertAttributeNotEquals('baz', 'privateAttribute', $obj); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertPublicStaticAttributeEquals() + { + $this->assertAttributeEquals('foo', 'publicStaticAttribute', 'ClassWithNonPublicAttributes'); + + try { + $this->assertAttributeEquals('bar', 'publicStaticAttribute', 'ClassWithNonPublicAttributes'); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertPublicStaticAttributeNotEquals() + { + $this->assertAttributeNotEquals('bar', 'publicStaticAttribute', 'ClassWithNonPublicAttributes'); + + try { + $this->assertAttributeNotEquals('foo', 'publicStaticAttribute', 'ClassWithNonPublicAttributes'); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertProtectedStaticAttributeEquals() + { + $this->assertAttributeEquals('bar', 'protectedStaticAttribute', 'ClassWithNonPublicAttributes'); + + try { + $this->assertAttributeEquals('foo', 'protectedStaticAttribute', 'ClassWithNonPublicAttributes'); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertProtectedStaticAttributeNotEquals() + { + $this->assertAttributeNotEquals('foo', 'protectedStaticAttribute', 'ClassWithNonPublicAttributes'); + + try { + $this->assertAttributeNotEquals('bar', 'protectedStaticAttribute', 'ClassWithNonPublicAttributes'); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertPrivateStaticAttributeEquals() + { + $this->assertAttributeEquals('baz', 'privateStaticAttribute', 'ClassWithNonPublicAttributes'); + + try { + $this->assertAttributeEquals('foo', 'privateStaticAttribute', 'ClassWithNonPublicAttributes'); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertPrivateStaticAttributeNotEquals() + { + $this->assertAttributeNotEquals('foo', 'privateStaticAttribute', 'ClassWithNonPublicAttributes'); + + try { + $this->assertAttributeNotEquals('baz', 'privateStaticAttribute', 'ClassWithNonPublicAttributes'); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testClassHasPublicAttribute() + { + $this->assertClassHasAttribute('publicAttribute', 'ClassWithNonPublicAttributes'); + + try { + $this->assertClassHasAttribute('attribute', 'ClassWithNonPublicAttributes'); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testClassNotHasPublicAttribute() + { + $this->assertClassNotHasAttribute('attribute', 'ClassWithNonPublicAttributes'); + + try { + $this->assertClassNotHasAttribute('publicAttribute', 'ClassWithNonPublicAttributes'); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testClassHasPublicStaticAttribute() + { + $this->assertClassHasStaticAttribute('publicStaticAttribute', 'ClassWithNonPublicAttributes'); + + try { + $this->assertClassHasStaticAttribute('attribute', 'ClassWithNonPublicAttributes'); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testClassNotHasPublicStaticAttribute() + { + $this->assertClassNotHasStaticAttribute('attribute', 'ClassWithNonPublicAttributes'); + + try { + $this->assertClassNotHasStaticAttribute('publicStaticAttribute', 'ClassWithNonPublicAttributes'); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testObjectHasPublicAttribute() + { + $obj = new ClassWithNonPublicAttributes; + + $this->assertObjectHasAttribute('publicAttribute', $obj); + + try { + $this->assertObjectHasAttribute('attribute', $obj); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testObjectNotHasPublicAttribute() + { + $obj = new ClassWithNonPublicAttributes; + + $this->assertObjectNotHasAttribute('attribute', $obj); + + try { + $this->assertObjectNotHasAttribute('publicAttribute', $obj); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testObjectHasOnTheFlyAttribute() + { + $obj = new StdClass; + $obj->foo = 'bar'; + + $this->assertObjectHasAttribute('foo', $obj); + + try { + $this->assertObjectHasAttribute('bar', $obj); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testObjectNotHasOnTheFlyAttribute() + { + $obj = new StdClass; + $obj->foo = 'bar'; + + $this->assertObjectNotHasAttribute('bar', $obj); + + try { + $this->assertObjectNotHasAttribute('foo', $obj); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testObjectHasProtectedAttribute() + { + $obj = new ClassWithNonPublicAttributes; + + $this->assertObjectHasAttribute('protectedAttribute', $obj); + + try { + $this->assertObjectHasAttribute('attribute', $obj); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testObjectNotHasProtectedAttribute() + { + $obj = new ClassWithNonPublicAttributes; + + $this->assertObjectNotHasAttribute('attribute', $obj); + + try { + $this->assertObjectNotHasAttribute('protectedAttribute', $obj); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testObjectHasPrivateAttribute() + { + $obj = new ClassWithNonPublicAttributes; + + $this->assertObjectHasAttribute('privateAttribute', $obj); + + try { + $this->assertObjectHasAttribute('attribute', $obj); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testObjectNotHasPrivateAttribute() + { + $obj = new ClassWithNonPublicAttributes; + + $this->assertObjectNotHasAttribute('attribute', $obj); + + try { + $this->assertObjectNotHasAttribute('privateAttribute', $obj); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertThatAttributeEquals() + { + $this->assertThat( + new ClassWithNonPublicAttributes, + $this->attribute( + $this->equalTo('foo'), + 'publicAttribute' + ) + ); + } + + public function testAssertThatAttributeEqualTo() + { + $this->assertThat( + new ClassWithNonPublicAttributes, + $this->attributeEqualTo('publicAttribute', 'foo') + ); + } + + public function testAssertThatAnything() + { + $this->assertThat('anything', $this->anything()); + } + + public function testAssertThatAnythingAndAnything() + { + $this->assertThat( + 'anything', + $this->logicalAnd( + $this->anything(), $this->anything() + ) + ); + } + + public function testAssertThatAnythingOrAnything() + { + $this->assertThat( + 'anything', + $this->logicalOr( + $this->anything(), $this->anything() + ) + ); + } + + public function testAssertThatAnythingXorNotAnything() + { + $this->assertThat( + 'anything', + $this->logicalXor( + $this->anything(), + $this->logicalNot($this->anything()) + ) + ); + } + + public function testAssertThatContains() + { + $this->assertThat(array('foo'), $this->contains('foo')); + } + + public function testAssertThatStringContains() + { + $this->assertThat('barfoobar', $this->stringContains('foo')); + } + + public function testAssertThatContainsOnly() + { + $this->assertThat(array('foo'), $this->containsOnly('string')); + } + + public function testAssertThatArrayHasKey() + { + $this->assertThat(array('foo' => 'bar'), $this->arrayHasKey('foo')); + } + + public function testAssertThatClassHasAttribute() + { + $this->assertThat( + new ClassWithNonPublicAttributes, + $this->classHasAttribute('publicAttribute') + ); + } + + public function testAssertThatClassHasStaticAttribute() + { + $this->assertThat( + new ClassWithNonPublicAttributes, + $this->classHasStaticAttribute('publicStaticAttribute') + ); + } + + public function testAssertThatObjectHasAttribute() + { + $this->assertThat( + new ClassWithNonPublicAttributes, + $this->objectHasAttribute('publicAttribute') + ); + } + + public function testAssertThatEqualTo() + { + $this->assertThat('foo', $this->equalTo('foo')); + } + + public function testAssertThatIdenticalTo() + { + $value = new StdClass; + $constraint = $this->identicalTo($value); + + $this->assertThat($value, $constraint); + } + + public function testAssertThatIsInstanceOf() + { + $this->assertThat(new StdClass, $this->isInstanceOf('StdClass')); + } + + public function testAssertThatIsType() + { + $this->assertThat('string', $this->isType('string')); + } + + public function testAssertThatFileExists() + { + $this->assertThat( + dirname(__FILE__) . DIRECTORY_SEPARATOR . 'AllTests.php', + $this->fileExists() + ); + } + + public function testAssertThatGreaterThan() + { + $this->assertThat(2, $this->greaterThan(1)); + } + + public function testAssertThatGreaterThanOrEqual() + { + $this->assertThat(2, $this->greaterThanOrEqual(1)); + } + + public function testAssertThatLessThan() + { + $this->assertThat(1, $this->lessThan(2)); + } + + public function testAssertThatLessThanOrEqual() + { + $this->assertThat(1, $this->lessThanOrEqual(2)); + } + + public function testAssertThatMatchesRegularExpression() + { + $this->assertThat('foobar', $this->matchesRegularExpression('/foo/')); + } + + /** + * @expectedException PHPUnit_Framework_IncompleteTestError incomplete 0 + */ + public function testMarkTestIncomplete() + { + $this->markTestIncomplete('incomplete'); + } + + /** + * @expectedException PHPUnit_Framework_SkippedTestError + */ + public function testMarkTestSkipped() + { + $this->markTestSkipped(); + } +} +?> Property changes on: test/PHPUnit/Tests/Framework/AssertTest.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/Framework/ComparisonFailureTest.php =================================================================== --- test/PHPUnit/Tests/Framework/ComparisonFailureTest.php (revision 0) +++ test/PHPUnit/Tests/Framework/ComparisonFailureTest.php (revision 0) @@ -0,0 +1,144 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: ComparisonFailureTest.php 1985 2007-12-26 18:11:55Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit/Framework/ComparisonFailure.php'; +require_once 'PHPUnit/Framework/TestCase.php'; + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class Framework_ComparisonFailureTest extends PHPUnit_Framework_TestCase +{ + public function testComparisonErrorMessage() + { + $failure = PHPUnit_Framework_ComparisonFailure::diffEqual('a', 'b', 'c'); + + $this->assertEquals( + "c expected string \n difference \n got string ", + $failure->toString() + ); + } + + public function testComparisonErrorStartSame() + { + $failure = PHPUnit_Framework_ComparisonFailure::diffEqual('ba', 'bc'); + + $this->assertEquals( + "expected string \ndifference < x>\ngot string ", + $failure->toString() + ); + } + + public function testComparisonErrorEndSame() + { + $failure = PHPUnit_Framework_ComparisonFailure::diffEqual('ab', 'cb'); + + $this->assertEquals( + "expected string \ndifference \ngot string ", + $failure->toString() + ); + } + + public function testComparisonErrorStartAndEndSame() + { + $failure = PHPUnit_Framework_ComparisonFailure::diffEqual('abc', 'adc'); + + $this->assertEquals( + "expected string \ndifference < x>\ngot string ", + $failure->toString() + ); + } + + public function testComparisonErrorStartSameComplete() + { + $failure = PHPUnit_Framework_ComparisonFailure::diffEqual('ab', 'abc'); + + $this->assertEquals( + "expected string \ndifference < ?>\ngot string ", + $failure->toString() + ); + } + + public function testComparisonErrorEndSameComplete() + { + $failure = PHPUnit_Framework_ComparisonFailure::diffEqual('bc', 'abc'); + + $this->assertEquals( + "expected string \ndifference \ngot string ", + $failure->toString() + ); + } + + public function testComparisonErrorOverlapingMatches() + { + $failure = PHPUnit_Framework_ComparisonFailure::diffEqual('abc', 'abbc'); + + $this->assertEquals( + "expected string \ndifference < x?>\ngot string ", + $failure->toString() + ); + } + + public function testComparisonErrorOverlapingMatches2() + { + $failure = PHPUnit_Framework_ComparisonFailure::diffEqual('abcdde', 'abcde'); + + $this->assertEquals( + "expected string \ndifference < x?>\ngot string ", + $failure->toString() + ); + } +} +?> Property changes on: test/PHPUnit/Tests/Framework/ComparisonFailureTest.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/Framework/ConstraintTest.php =================================================================== --- test/PHPUnit/Tests/Framework/ConstraintTest.php (revision 0) +++ test/PHPUnit/Tests/Framework/ConstraintTest.php (revision 0) @@ -0,0 +1,686 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: ConstraintTest.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/TestCase.php'; + +require_once '_files/ClassWithNonPublicAttributes.php'; + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class Framework_ConstraintTest extends PHPUnit_Framework_TestCase +{ + public function testConstraintArrayHasKey() + { + $constraint = new PHPUnit_Framework_Constraint_ArrayHasKey(0); + + $this->assertFalse($constraint->evaluate(array())); + $this->assertEquals('has key ', $constraint->toString()); + + try { + $constraint->fail(array(), ''); + } + + catch (PHPUnit_Framework_ExpectationFailedException $e) { + $this->assertEquals( + "Failed asserting that \nArray\n(\n)\n has key .", + $e->getDescription() + ); + + return; + } + + $this->fail(); + } + + public function testConstraintArrayNotHasKey() + { + $constraint = new PHPUnit_Framework_Constraint_Not( + new PHPUnit_Framework_Constraint_ArrayHasKey(0) + ); + + $this->assertTrue($constraint->evaluate(array())); + $this->assertEquals('does not have key ', $constraint->toString()); + + try { + $constraint->fail(array(0), ''); + } + + catch (PHPUnit_Framework_ExpectationFailedException $e) { + $this->assertEquals( + "Failed asserting that \nArray\n(\n [0] => 0\n)\n does not have key .", + $e->getDescription() + ); + + return; + } + + $this->fail(); + } + + public function testConstraintFileExists() + { + $constraint = new PHPUnit_Framework_Constraint_FileExists; + + $this->assertFalse($constraint->evaluate('foo')); + $this->assertEquals('file exists', $constraint->toString()); + + try { + $constraint->fail('foo', ''); + } + + catch (PHPUnit_Framework_ExpectationFailedException $e) { + $this->assertEquals( + 'Failed asserting that file "foo" exists.', + $e->getDescription() + ); + + return; + } + + $this->fail(); + } + + public function testConstraintFileNotExists() + { + $constraint = new PHPUnit_Framework_Constraint_Not( + new PHPUnit_Framework_Constraint_FileExists + ); + + $this->assertTrue($constraint->evaluate('foo')); + $this->assertEquals('file does not exist', $constraint->toString()); + + try { + $constraint->fail('foo', ''); + } + + catch (PHPUnit_Framework_ExpectationFailedException $e) { + $this->assertEquals( + 'Failed asserting that file "foo" does not exist.', + $e->getDescription() + ); + + return; + } + + $this->fail(); + } + + public function testConstraintGreaterThan() + { + $constraint = new PHPUnit_Framework_Constraint_GreaterThan(1); + + $this->assertFalse($constraint->evaluate(0)); + $this->assertTrue($constraint->evaluate(2)); + $this->assertEquals('is greater than ', $constraint->toString()); + + try { + $constraint->fail(0, ''); + } + + catch (PHPUnit_Framework_ExpectationFailedException $e) { + $this->assertEquals( + "Failed asserting that is greater than .", + $e->getDescription() + ); + + return; + } + + $this->fail(); + } + + public function testConstraintNotGreaterThan() + { + $constraint = new PHPUnit_Framework_Constraint_Not( + new PHPUnit_Framework_Constraint_GreaterThan(1) + ); + + $this->assertTrue($constraint->evaluate(1)); + $this->assertEquals('is not greater than ', $constraint->toString()); + + try { + $constraint->fail(1, ''); + } + + catch (PHPUnit_Framework_ExpectationFailedException $e) { + $this->assertEquals( + "Failed asserting that is not greater than .", + $e->getDescription() + ); + + return; + } + + $this->fail(); + } + + public function testConstraintIsAnything() + { + $constraint = new PHPUnit_Framework_Constraint_IsAnything; + + $this->assertTrue($constraint->evaluate(NULL)); + $this->assertNull($constraint->fail(NULL, '')); + $this->assertEquals('is anything', $constraint->toString()); + } + + public function testConstraintNotIsAnything() + { + $constraint = new PHPUnit_Framework_Constraint_Not( + new PHPUnit_Framework_Constraint_IsAnything + ); + + $this->assertFalse($constraint->evaluate(NULL)); + $this->assertNull($constraint->fail(NULL, '')); + $this->assertEquals('is not anything', $constraint->toString()); + } + + public function testConstraintIsEqual() + { + $constraint = new PHPUnit_Framework_Constraint_IsEqual(1); + + $this->assertFalse($constraint->evaluate(0)); + $this->assertTrue($constraint->evaluate(1)); + $this->assertEquals('is equal to ', $constraint->toString()); + + try { + $constraint->fail(0, ''); + } + + catch (PHPUnit_Framework_ExpectationFailedException $e) { + $this->assertEquals( + "Failed asserting that is equal to .", + $e->getDescription() + ); + + return; + } + + $this->fail(); + } + + public function testConstraintIsNotEqual() + { + $constraint = new PHPUnit_Framework_Constraint_Not( + new PHPUnit_Framework_Constraint_IsEqual(1) + ); + + $this->assertTrue($constraint->evaluate(0)); + $this->assertFalse($constraint->evaluate(1)); + $this->assertEquals('is not equal to ', $constraint->toString()); + + try { + $constraint->fail(1, ''); + } + + catch (PHPUnit_Framework_ExpectationFailedException $e) { + $this->assertEquals( + "Failed asserting that is not equal to .", + $e->getDescription() + ); + + return; + } + + $this->fail(); + } + + public function testConstraintIsIdentical() + { + $a = new stdClass; + $b = new stdClass; + + $constraint = new PHPUnit_Framework_Constraint_IsIdentical($a); + + $this->assertFalse($constraint->evaluate($b)); + $this->assertTrue($constraint->evaluate($a)); + $this->assertEquals("is identical to \nstdClass Object\n(\n)\n", $constraint->toString()); + + try { + $constraint->fail($b, ''); + } + + catch (PHPUnit_Framework_ExpectationFailedException $e) { + $this->assertEquals( + "Failed asserting that \nstdClass Object\n(\n)\n is identical to \nstdClass Object\n(\n)\n.", + $e->getDescription() + ); + + return; + } + + $this->fail(); + } + + public function testConstraintIsNotIdentical() + { + $a = new stdClass; + $b = new stdClass; + + $constraint = new PHPUnit_Framework_Constraint_Not( + new PHPUnit_Framework_Constraint_IsIdentical($a) + ); + + $this->assertTrue($constraint->evaluate($b)); + $this->assertFalse($constraint->evaluate($a)); + $this->assertEquals("is not identical to \nstdClass Object\n(\n)\n", $constraint->toString()); + + try { + $constraint->fail($a, ''); + } + + catch (PHPUnit_Framework_ExpectationFailedException $e) { + $this->assertEquals( + "Failed asserting that \nstdClass Object\n(\n)\n is not identical to \nstdClass Object\n(\n)\n.", + $e->getDescription() + ); + + return; + } + + $this->fail(); + } + + public function testConstraintIsInstanceOf() + { + $constraint = new PHPUnit_Framework_Constraint_IsInstanceOf('Exception'); + + $this->assertFalse($constraint->evaluate(new stdClass)); + $this->assertTrue($constraint->evaluate(new Exception)); + $this->assertEquals('is instance of class "Exception"', $constraint->toString()); + + try { + $constraint->fail(new stdClass, ''); + } + + catch (PHPUnit_Framework_ExpectationFailedException $e) { + $this->assertEquals( + 'Failed asserting that is an instance of class "Exception".', + $e->getDescription() + ); + + return; + } + + $this->fail(); + } + + public function testConstraintIsNotInstanceOf() + { + $constraint = new PHPUnit_Framework_Constraint_Not( + new PHPUnit_Framework_Constraint_IsInstanceOf('stdClass') + ); + + $this->assertFalse($constraint->evaluate(new stdClass)); + $this->assertTrue($constraint->evaluate(new Exception)); + $this->assertEquals('is not instance of class "stdClass"', $constraint->toString()); + + try { + $constraint->fail(new stdClass, ''); + } + + catch (PHPUnit_Framework_ExpectationFailedException $e) { + $this->assertEquals( + 'Failed asserting that is not an instance of class "stdClass".', + $e->getDescription() + ); + + return; + } + + $this->fail(); + } + + public function testConstraintIsType() + { + $constraint = new PHPUnit_Framework_Constraint_IsType('string'); + + $this->assertFalse($constraint->evaluate(0)); + $this->assertTrue($constraint->evaluate('')); + $this->assertEquals('is of type "string"', $constraint->toString()); + + try { + $constraint->fail(new stdClass, ''); + } + + catch (PHPUnit_Framework_ExpectationFailedException $e) { + $this->assertEquals( + "Failed asserting that \nstdClass Object\n(\n)\n is of type \"string\".", + $e->getDescription() + ); + + return; + } + + $this->fail(); + } + + public function testConstraintIsNotType() + { + $constraint = new PHPUnit_Framework_Constraint_Not( + new PHPUnit_Framework_Constraint_IsType('string') + ); + + $this->assertTrue($constraint->evaluate(0)); + $this->assertFalse($constraint->evaluate('')); + $this->assertEquals('is not of type "string"', $constraint->toString()); + + try { + $constraint->fail('', ''); + } + + catch (PHPUnit_Framework_ExpectationFailedException $e) { + $this->assertEquals( + 'Failed asserting that is not of type "string".', + $e->getDescription() + ); + + return; + } + + $this->fail(); + } + + public function testConstraintLessThan() + { + $constraint = new PHPUnit_Framework_Constraint_LessThan(1); + + $this->assertTrue($constraint->evaluate(0)); + $this->assertFalse($constraint->evaluate(2)); + $this->assertEquals('is less than ', $constraint->toString()); + + try { + $constraint->fail(0, ''); + } + + catch (PHPUnit_Framework_ExpectationFailedException $e) { + $this->assertEquals( + "Failed asserting that is less than .", + $e->getDescription() + ); + + return; + } + + $this->fail(); + } + + public function testConstraintNotLessThan() + { + $constraint = new PHPUnit_Framework_Constraint_Not( + new PHPUnit_Framework_Constraint_LessThan(1) + ); + + $this->assertTrue($constraint->evaluate(1)); + $this->assertEquals('is not less than ', $constraint->toString()); + + try { + $constraint->fail(1, ''); + } + + catch (PHPUnit_Framework_ExpectationFailedException $e) { + $this->assertEquals( + "Failed asserting that is not less than .", + $e->getDescription() + ); + + return; + } + + $this->fail(); + } + + public function testConstraintObjectHasAttribute() + { + $constraint = new PHPUnit_Framework_Constraint_ObjectHasAttribute('foo'); + + $this->assertFalse($constraint->evaluate(new stdClass)); + $this->assertEquals('has attribute "foo"', $constraint->toString()); + + try { + $constraint->fail(new stdClass, ''); + } + + catch (PHPUnit_Framework_ExpectationFailedException $e) { + $this->assertEquals( + "Failed asserting that \nstdClass Object\n(\n)\n has attribute \"foo\".", + $e->getDescription() + ); + + return; + } + + $this->fail(); + } + + public function testConstraintObjectNotHasAttribute() + { + $constraint = new PHPUnit_Framework_Constraint_Not( + new PHPUnit_Framework_Constraint_ObjectHasAttribute('foo') + ); + + $this->assertTrue($constraint->evaluate(new stdClass)); + $this->assertEquals('does not have attribute "foo"', $constraint->toString()); + + $o = new stdClass; + $o->foo = 'bar'; + + try { + $constraint->fail($o, ''); + } + + catch (PHPUnit_Framework_ExpectationFailedException $e) { + $this->assertEquals( + "Failed asserting that \nstdClass Object\n(\n [foo] => bar\n)\n does not have attribute \"foo\".", + $e->getDescription() + ); + + return; + } + + $this->fail(); + } + + public function testConstraintPCREMatch() + { + $constraint = new PHPUnit_Framework_Constraint_PCREMatch('/foo/'); + + $this->assertFalse($constraint->evaluate('barbazbar')); + $this->assertTrue($constraint->evaluate('barfoobar')); + $this->assertEquals('matches PCRE pattern "/foo/"', $constraint->toString()); + + try { + $constraint->fail('barbazbar', ''); + } + + catch (PHPUnit_Framework_ExpectationFailedException $e) { + $this->assertEquals( + 'Failed asserting that matches PCRE pattern "/foo/".', + $e->getDescription() + ); + + return; + } + + $this->fail(); + } + + public function testConstraintPCRENotMatch() + { + $constraint = new PHPUnit_Framework_Constraint_Not( + new PHPUnit_Framework_Constraint_PCREMatch('/foo/') + ); + + $this->assertTrue($constraint->evaluate('barbazbar')); + $this->assertFalse($constraint->evaluate('barfoobar')); + $this->assertEquals('does not match PCRE pattern "/foo/"', $constraint->toString()); + + try { + $constraint->fail('barfoobar', ''); + } + + catch (PHPUnit_Framework_ExpectationFailedException $e) { + $this->assertEquals( + 'Failed asserting that does not match PCRE pattern "/foo/".', + $e->getDescription() + ); + + return; + } + + $this->fail(); + } + + public function testConstraintStringContains() + { + $constraint = new PHPUnit_Framework_Constraint_StringContains('foo'); + + $this->assertFalse($constraint->evaluate('barbazbar')); + $this->assertTrue($constraint->evaluate('barfoobar')); + $this->assertEquals('contains "foo"', $constraint->toString()); + + try { + $constraint->fail('barbazbar', ''); + } + + catch (PHPUnit_Framework_ExpectationFailedException $e) { + $this->assertEquals( + 'Failed asserting that contains "foo".', + $e->getDescription() + ); + + return; + } + + $this->fail(); + } + + public function testConstraintStringNotContains() + { + $constraint = new PHPUnit_Framework_Constraint_Not( + new PHPUnit_Framework_Constraint_StringContains('foo') + ); + + $this->assertTrue($constraint->evaluate('barbazbar')); + $this->assertFalse($constraint->evaluate('barfoobar')); + $this->assertEquals('does not contain "foo"', $constraint->toString()); + + try { + $constraint->fail('barfoobar', ''); + } + + catch (PHPUnit_Framework_ExpectationFailedException $e) { + $this->assertEquals( + 'Failed asserting that does not contain "foo".', + $e->getDescription() + ); + + return; + } + + $this->fail(); + } + + public function testConstraintTraversableContains() + { + $constraint = new PHPUnit_Framework_Constraint_TraversableContains('foo'); + + $this->assertFalse($constraint->evaluate(array('bar'))); + $this->assertTrue($constraint->evaluate(array('foo'))); + $this->assertEquals('contains ', $constraint->toString()); + + try { + $constraint->fail(array('bar'), ''); + } + + catch (PHPUnit_Framework_ExpectationFailedException $e) { + $this->assertEquals( + "Failed asserting that \nArray\n(\n [0] => bar\n)\n contains .", + $e->getDescription() + ); + + return; + } + + $this->fail(); + } + + public function testConstraintTraversableNotContains() + { + $constraint = new PHPUnit_Framework_Constraint_Not( + new PHPUnit_Framework_Constraint_TraversableContains('foo') + ); + + $this->assertTrue($constraint->evaluate(array('bar'))); + $this->assertFalse($constraint->evaluate(array('foo'))); + $this->assertEquals('does not contain ', $constraint->toString()); + + try { + $constraint->fail(array('foo'), ''); + } + + catch (PHPUnit_Framework_ExpectationFailedException $e) { + $this->assertEquals( + "Failed asserting that \nArray\n(\n [0] => foo\n)\n does not contain .", + $e->getDescription() + ); + + return; + } + + $this->fail(); + } +} +?> Property changes on: test/PHPUnit/Tests/Framework/ConstraintTest.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/Framework/TestListenerTest.php =================================================================== --- test/PHPUnit/Tests/Framework/TestListenerTest.php (revision 0) +++ test/PHPUnit/Tests/Framework/TestListenerTest.php (revision 0) @@ -0,0 +1,154 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: TestListenerTest.php 1985 2007-12-26 18:11:55Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit/Framework/TestCase.php'; +require_once 'PHPUnit/Framework/TestListener.php'; +require_once 'PHPUnit/Framework/TestResult.php'; + +require_once '_files/Error.php'; +require_once '_files/Failure.php'; +require_once '_files/Success.php'; + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class Framework_TestListenerTest extends PHPUnit_Framework_TestCase implements PHPUnit_Framework_TestListener +{ + protected $endCount; + protected $errorCount; + protected $failureCount; + protected $notImplementedCount; + protected $skippedCount; + protected $result; + protected $startCount; + + public function addError(PHPUnit_Framework_Test $test, Exception $e, $time) + { + $this->errorCount++; + } + + public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) + { + $this->failureCount++; + } + + public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time) + { + $this->notImplementedCount++; + } + + public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time) + { + $this->skippedCount++; + } + + public function startTestSuite(PHPUnit_Framework_TestSuite $suite) + { + } + + public function endTestSuite(PHPUnit_Framework_TestSuite $suite) + { + } + + public function startTest(PHPUnit_Framework_Test $test) + { + $this->startCount++; + } + + public function endTest(PHPUnit_Framework_Test $test, $time) + { + $this->endCount++; + } + + protected function setUp() + { + $this->result = new PHPUnit_Framework_TestResult; + $this->result->addListener($this); + + $this->endCount = 0; + $this->failureCount = 0; + $this->notImplementedCount = 0; + $this->skippedCount = 0; + $this->startCount = 0; + } + + public function testError() + { + $test = new Error; + $test->run($this->result); + + $this->assertEquals(1, $this->errorCount); + $this->assertEquals(1, $this->endCount); + } + + public function testFailure() + { + $test = new Failure; + $test->run($this->result); + + $this->assertEquals(1, $this->failureCount); + $this->assertEquals(1, $this->endCount); + } + + public function testStartStop() + { + $test = new Success; + $test->run($this->result); + + $this->assertEquals(1, $this->startCount); + $this->assertEquals(1, $this->endCount); + } +} +?> Property changes on: test/PHPUnit/Tests/Framework/TestListenerTest.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/Util/AllTests.php =================================================================== --- test/PHPUnit/Tests/Util/AllTests.php (revision 0) +++ test/PHPUnit/Tests/Util/AllTests.php (revision 0) @@ -0,0 +1,111 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: AllTests.php 1985 2007-12-26 18:11:55Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 2.3.0 + */ + +require_once 'PHPUnit/Util/Filter.php'; + +if (!defined('PHPUnit_MAIN_METHOD')) { + define('PHPUnit_MAIN_METHOD', 'Util_AllTests::main'); + chdir(dirname(dirname(__FILE__))); +} + +require_once 'PHPUnit/Framework/TestSuite.php'; +require_once 'PHPUnit/TextUI/TestRunner.php'; + +require_once 'Util/Log/AllTests.php'; +require_once 'Util/TestDox/AllTests.php'; +require_once 'Util/TimerTest.php'; + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class Util_AllTests +{ + public static function main() + { + PHPUnit_TextUI_TestRunner::run(self::suite()); + } + + public static function suite() + { + if (!defined('PHPUNIT_TESTSUITE_WHITELIST_PREPARED')) { + PHPUnit_Util_Filter::addDirectoryToWhitelist( + dirname(dirname(dirname(__FILE__))) + ); + + PHPUnit_Util_Filter::removeDirectoryFromWhitelist( + dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'Samples' + ); + + PHPUnit_Util_Filter::removeDirectoryFromWhitelist( + dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'Tests' + ); + + define('PHPUNIT_TESTSUITE_WHITELIST_PREPARED', TRUE); + } + + $suite = new PHPUnit_Framework_TestSuite('PHPUnit_Util'); + + $suite->addTest(Util_Log_AllTests::suite()); + $suite->addTest(Util_TestDox_AllTests::suite()); + $suite->addTestSuite('Util_TimerTest'); + + return $suite; + } +} + +if (PHPUnit_MAIN_METHOD == 'Util_AllTests::main') { + Util_AllTests::main(); +} +?> Property changes on: test/PHPUnit/Tests/Util/AllTests.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/Util/TimerTest.php =================================================================== --- test/PHPUnit/Tests/Util/TimerTest.php (revision 0) +++ test/PHPUnit/Tests/Util/TimerTest.php (revision 0) @@ -0,0 +1,78 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: TimerTest.php 1985 2007-12-26 18:11:55Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 2.3.0 + */ + +require_once 'PHPUnit/Framework/TestCase.php'; + +require_once 'PHPUnit/Util/Timer.php'; + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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.1.0 + */ +class Util_TimerTest extends PHPUnit_Framework_TestCase +{ + public function testSecondsToTimeString() + { + $this->assertEquals('0 seconds', PHPUnit_Util_Timer::secondsToTimeString(0)); + $this->assertEquals('1 second', PHPUnit_Util_Timer::secondsToTimeString(1)); + $this->assertEquals('2 seconds', PHPUnit_Util_Timer::secondsToTimeString(2)); + $this->assertEquals('01:00', PHPUnit_Util_Timer::secondsToTimeString(60)); + $this->assertEquals('01:01', PHPUnit_Util_Timer::secondsToTimeString(61)); + $this->assertEquals('02:00', PHPUnit_Util_Timer::secondsToTimeString(120)); + $this->assertEquals('02:01', PHPUnit_Util_Timer::secondsToTimeString(121)); + $this->assertEquals('01:00:00', PHPUnit_Util_Timer::secondsToTimeString(3600)); + $this->assertEquals('01:00:01', PHPUnit_Util_Timer::secondsToTimeString(3601)); + } +} +?> Property changes on: test/PHPUnit/Tests/Util/TimerTest.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/Util/TestDox/AllTests.php =================================================================== --- test/PHPUnit/Tests/Util/TestDox/AllTests.php (revision 0) +++ test/PHPUnit/Tests/Util/TestDox/AllTests.php (revision 0) @@ -0,0 +1,93 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: AllTests.php 1985 2007-12-26 18:11:55Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 2.3.0 + */ + +require_once 'PHPUnit/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__); + +if (!defined('PHPUnit_MAIN_METHOD')) { + define('PHPUnit_MAIN_METHOD', 'Util_TestDox_AllTests::main'); + chdir(dirname(dirname(dirname(__FILE__)))); +} + +require_once 'PHPUnit/Framework/TestSuite.php'; +require_once 'PHPUnit/TextUI/TestRunner.php'; + +require_once 'Util/TestDox/NamePrettifierTest.php'; + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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.1.0 + */ +class Util_TestDox_AllTests +{ + public static function main() + { + PHPUnit_TextUI_TestRunner::run(self::suite()); + } + + public static function suite() + { + $suite = new PHPUnit_Framework_TestSuite('PHPUnit_Util_TestDox'); + + $suite->addTestSuite('Util_TestDox_NamePrettifierTest'); + + return $suite; + } +} + +if (PHPUnit_MAIN_METHOD == 'Util_TestDox_AllTests::main') { + Util_TestDox_AllTests::main(); +} +?> Property changes on: test/PHPUnit/Tests/Util/TestDox/AllTests.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Tests/Util/TestDox/NamePrettifierTest.php =================================================================== --- test/PHPUnit/Tests/Util/TestDox/NamePrettifierTest.php (revision 0) +++ test/PHPUnit/Tests/Util/TestDox/NamePrettifierTest.php (revision 0) @@ -0,0 +1,108 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: NamePrettifierTest.php 1985 2007-12-26 18:11:55Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 2.3.0 + */ + +require_once 'PHPUnit/Framework/TestCase.php'; + +require_once 'PHPUnit/Util/TestDox/NamePrettifier.php'; + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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.1.0 + */ +class Util_TestDox_NamePrettifierTest extends PHPUnit_Framework_TestCase +{ + protected $namePrettifier; + + protected function setUp() + { + $this->namePrettifier = new PHPUnit_Util_TestDox_NamePrettifier; + } + + public function testTitleHasSensibleDefaults() + { + $this->assertEquals('Foo', $this->namePrettifier->prettifyTestClass('FooTest')); + $this->assertEquals('Foo', $this->namePrettifier->prettifyTestClass('TestFoo')); + $this->assertEquals('Foo', $this->namePrettifier->prettifyTestClass('TestFooTest')); + } + + public function testCaterForUserDefinedSuffix() + { + $this->namePrettifier->setSuffix('TestCase'); + $this->namePrettifier->setPrefix(NULL); + + $this->assertEquals('Foo', $this->namePrettifier->prettifyTestClass('FooTestCase')); + $this->assertEquals('TestFoo', $this->namePrettifier->prettifyTestClass('TestFoo')); + $this->assertEquals('FooTest', $this->namePrettifier->prettifyTestClass('FooTest')); + } + + public function testCaterForUserDefinedPrefix() + { + $this->namePrettifier->setSuffix(NULL); + $this->namePrettifier->setPrefix('XXX'); + + $this->assertEquals('Foo', $this->namePrettifier->prettifyTestClass('XXXFoo')); + $this->assertEquals('TestXXX', $this->namePrettifier->prettifyTestClass('TestXXX')); + $this->assertEquals('XXX', $this->namePrettifier->prettifyTestClass('XXXXXX')); + } + + public function testTestNameIsConvertedToASentence() + { + $this->assertEquals('This is a test', $this->namePrettifier->prettifyTestMethod('testThisIsATest')); + $this->assertEquals('This is a test', $this->namePrettifier->prettifyTestMethod('testThisIsATest2')); + $this->assertEquals('database_column_spec is set correctly', $this->namePrettifier->prettifyTestMethod('testdatabase_column_specIsSetCorrectly')); + $this->assertEquals('Foo for bar is 0', $this->namePrettifier->prettifyTestMethod('testFooForBarIs0')); + $this->assertEquals('Foo for baz is 1', $this->namePrettifier->prettifyTestMethod('testFooForBazIs1')); + } +} +?> Property changes on: test/PHPUnit/Tests/Util/TestDox/NamePrettifierTest.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/TextUI/TestRunner.php =================================================================== --- test/PHPUnit/TextUI/TestRunner.php (revision 0) +++ test/PHPUnit/TextUI/TestRunner.php (revision 0) @@ -0,0 +1,745 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: TestRunner.php 2144 2008-01-17 10:53:25Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit/Framework.php'; +require_once 'PHPUnit/Runner/BaseTestRunner.php'; +require_once 'PHPUnit/Extensions/RepeatedTest.php'; +require_once 'PHPUnit/Runner/StandardTestSuiteLoader.php'; +require_once 'PHPUnit/Runner/Version.php'; +require_once 'PHPUnit/TextUI/ResultPrinter.php'; +require_once 'PHPUnit/Util/TestDox/ResultPrinter.php'; +require_once 'PHPUnit/Util/Configuration.php'; +require_once 'PHPUnit/Util/PDO.php'; +require_once 'PHPUnit/Util/Filter.php'; +require_once 'PHPUnit/Util/Report.php'; +require_once 'PHPUnit/Util/Timer.php'; +require_once 'PHPUnit/Util/Log/CodeCoverage/Database.php'; +require_once 'PHPUnit/Util/Log/CodeCoverage/XML.php'; +require_once 'PHPUnit/Util/Log/CPD.php'; +require_once 'PHPUnit/Util/Log/Database.php'; +require_once 'PHPUnit/Util/Log/GraphViz.php'; +require_once 'PHPUnit/Util/Log/JSON.php'; +require_once 'PHPUnit/Util/Log/Metrics.php'; +require_once 'PHPUnit/Util/Log/TAP.php'; +require_once 'PHPUnit/Util/Log/PMD.php'; +require_once 'PHPUnit/Util/Log/XML.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * A TestRunner for the Command Line Interface (CLI) + * PHP SAPI Module. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class PHPUnit_TextUI_TestRunner extends PHPUnit_Runner_BaseTestRunner +{ + const SUCCESS_EXIT = 0; + const FAILURE_EXIT = 1; + const EXCEPTION_EXIT = 2; + + /** + * @var PHPUnit_Runner_TestSuiteLoader + * @access protected + * @static + */ + protected static $loader = NULL; + + /** + * @var PHPUnit_TextUI_ResultPrinter + * @access protected + */ + protected $printer = NULL; + + /** + * @var boolean + * @access protected + * @static + */ + protected static $versionStringPrinted = FALSE; + + /** + * @param mixed $test + * @param array $arguments + * @throws InvalidArgumentException + * @access public + * @static + */ + public static function run($test, array $arguments = array()) + { + if ($test instanceof ReflectionClass) { + $test = new PHPUnit_Framework_TestSuite($test); + } + + if ($test instanceof PHPUnit_Framework_Test) { + $aTestRunner = new PHPUnit_TextUI_TestRunner; + + return $aTestRunner->doRun( + $test, + $arguments + ); + } else { + throw new InvalidArgumentException( + 'No test case or test suite found.' + ); + } + } + + /** + * Runs a single test and waits until the user types RETURN. + * + * @param PHPUnit_Framework_Test $suite + * @access public + * @static + */ + public static function runAndWait(PHPUnit_Framework_Test $suite) + { + $aTestRunner = new PHPUnit_TextUI_TestRunner; + + $aTestRunner->doRun( + $suite, + array( + 'wait' => TRUE + ) + ); + + } + + /** + * @return PHPUnit_Framework_TestResult + * @access protected + */ + protected function createTestResult() + { + return new PHPUnit_Framework_TestResult; + } + + /** + * @param PHPUnit_Framework_Test $suite + * @param array $arguments + * @return PHPUnit_Framework_TestResult + * @access public + */ + public function doRun(PHPUnit_Framework_Test $suite, array $arguments = array()) + { + $this->handleConfiguration($arguments); + + if (is_integer($arguments['repeat'])) { + $suite = new PHPUnit_Extensions_RepeatedTest( + $suite, + $arguments['repeat'], + $arguments['filter'], + $arguments['groups'], + $arguments['excludeGroups'] + ); + } + + $result = $this->createTestResult(); + + if ($arguments['stopOnFailure']) { + $result->stopOnFailure(TRUE); + } + + if ($this->printer === NULL) { + if (isset($arguments['printer']) && + $arguments['printer'] instanceof PHPUnit_Util_Printer) { + $this->printer = $arguments['printer']; + } else { + $this->printer = new PHPUnit_TextUI_ResultPrinter( + NULL, $arguments['verbose'] + ); + } + } + + $this->printer->write( + PHPUnit_Runner_Version::getVersionString() . "\n\n" + ); + + foreach ($arguments['listeners'] as $listener) { + $result->addListener($listener); + } + + $result->addListener($this->printer); + + if (isset($arguments['testdoxHTMLFile'])) { + $result->addListener( + new PHPUnit_Util_TestDox_ResultPrinter_HTML( + $arguments['testdoxHTMLFile'] + ) + ); + } + + if (isset($arguments['testdoxTextFile'])) { + $result->addListener( + new PHPUnit_Util_TestDox_ResultPrinter_Text( + $arguments['testdoxTextFile'] + ) + ); + } + + if (isset($arguments['graphvizLogfile'])) { + if (class_exists('Image_GraphViz', FALSE)) { + $result->addListener( + new PHPUnit_Util_Log_GraphViz($arguments['graphvizLogfile']) + ); + } + } + + if ((isset($arguments['coverageXML']) || + isset($arguments['metricsXML']) || + isset($arguments['pmdXML'])) && + extension_loaded('xdebug')) { + $result->collectCodeCoverageInformation(TRUE); + } + + if (isset($arguments['reportDirectory']) && + extension_loaded('xdebug')) { + $result->collectCodeCoverageInformation(TRUE); + } + + if (isset($arguments['jsonLogfile'])) { + $result->addListener( + new PHPUnit_Util_Log_JSON($arguments['jsonLogfile']) + ); + } + + if (isset($arguments['tapLogfile'])) { + $result->addListener( + new PHPUnit_Util_Log_TAP($arguments['tapLogfile']) + ); + } + + if (isset($arguments['xmlLogfile'])) { + $result->addListener( + new PHPUnit_Util_Log_XML( + $arguments['xmlLogfile'], $arguments['logIncompleteSkipped'] + ) + ); + } + + if (isset($arguments['testDatabaseDSN']) && + isset($arguments['testDatabaseLogRevision']) && + extension_loaded('pdo')) { + $writeToTestDatabase = TRUE; + } else { + $writeToTestDatabase = FALSE; + } + + if ($writeToTestDatabase) { + $dbh = PHPUnit_Util_PDO::factory($arguments['testDatabaseDSN']); + + $dbListener = PHPUnit_Util_Log_Database::getInstance( + $dbh, + $arguments['testDatabaseLogRevision'], + isset($arguments['testDatabaseLogInfo']) ? $arguments['testDatabaseLogInfo'] : '' + ); + + $result->addListener($dbListener); + $result->collectCodeCoverageInformation(TRUE); + } + + $suite->run( + $result, + $arguments['filter'], + $arguments['groups'], + $arguments['excludeGroups'] + ); + + $result->flushListeners(); + + if ($this->printer instanceof PHPUnit_TextUI_ResultPrinter) { + $this->printer->printResult($result); + } + + if (isset($arguments['coverageXML']) && + extension_loaded('tokenizer') && + extension_loaded('xdebug')) { + $this->printer->write("\nWriting code coverage data to XML file, this may take a moment."); + + $writer = new PHPUnit_Util_Log_CodeCoverage_XML( + $arguments['coverageXML'] + ); + + $writer->process($result); + $this->printer->write("\n"); + } + + if ($writeToTestDatabase && + extension_loaded('tokenizer') && + extension_loaded('xdebug')) { + $this->printer->write("\nStoring code coverage and software metrics data in database.\nThis may take a moment."); + + $testDb = new PHPUnit_Util_Log_CodeCoverage_Database($dbh); + $testDb->storeCodeCoverage( + $result, + $dbListener->getRunId(), + $arguments['testDatabaseLogRevision'], + $arguments['testDatabasePrefix'] + ); + + $this->printer->write("\n"); + } + + if (isset($arguments['metricsXML']) && + extension_loaded('tokenizer') && + extension_loaded('xdebug')) { + $this->printer->write("\nWriting metrics report XML file, this may take a moment."); + + $writer = new PHPUnit_Util_Log_Metrics( + $arguments['metricsXML'] + ); + + $writer->process($result); + $this->printer->write("\n"); + } + + if (isset($arguments['pmdXML']) && + extension_loaded('tokenizer') && + extension_loaded('xdebug')) { + $writer = new PHPUnit_Util_Log_PMD( + $arguments['pmdXML'], $arguments['pmd'] + ); + + $this->printer->write("\nWriting violations report XML file, this may take a moment."); + $writer->process($result); + + $writer = new PHPUnit_Util_Log_CPD( + str_replace('.xml', '-cpd.xml', $arguments['pmdXML']) + ); + + $writer->process( + $result, $arguments['cpdMinLines'], $arguments['cpdMinMatches'] + ); + + $this->printer->write("\n"); + } + + if (isset($arguments['reportDirectory']) && + extension_loaded('xdebug')) { + $this->printer->write("\nGenerating code coverage report, this may take a moment."); + + PHPUnit_Util_Report::render( + $result, + $arguments['reportDirectory'], + $arguments['reportCharset'], + $arguments['reportYUI'], + $arguments['reportHighlight'], + $arguments['reportLowUpperBound'], + $arguments['reportHighLowerBound'] + ); + + $this->printer->write("\n"); + } + + $this->pause($arguments['wait']); + + return $result; + } + + /** + * @param boolean $wait + * @access protected + */ + protected function pause($wait) + { + if (!$wait) { + return; + } + + if ($this->printer instanceof PHPUnit_TextUI_ResultPrinter) { + $this->printer->printWaitPrompt(); + } + + fgets(STDIN); + } + + /** + * @param PHPUnit_TextUI_ResultPrinter $resultPrinter + * @access public + */ + public function setPrinter(PHPUnit_TextUI_ResultPrinter $resultPrinter) + { + $this->printer = $resultPrinter; + } + + /** + * A test started. + * + * @param string $testName + * @access public + */ + public function testStarted($testName) + { + } + + /** + * A test ended. + * + * @param string $testName + * @access public + */ + public function testEnded($testName) + { + } + + /** + * A test failed. + * + * @param integer $status + * @param PHPUnit_Framework_Test $test + * @param PHPUnit_Framework_AssertionFailedError $e + * @access public + */ + public function testFailed($status, PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e) + { + } + + /** + * Override to define how to handle a failed loading of + * a test suite. + * + * @param string $message + * @access protected + */ + protected function runFailed($message) + { + self::printVersionString(); + self::write($message); + exit(self::FAILURE_EXIT); + } + + /** + * @param string $directory + * @return string + * @throws RuntimeException + * @access protected + * @since Method available since Release 3.0.0 + */ + protected function getDirectory($directory) + { + if (substr($directory, -1, 1) != DIRECTORY_SEPARATOR) { + $directory .= DIRECTORY_SEPARATOR; + } + + if (is_dir($directory) || mkdir($directory, 0777, TRUE)) { + return $directory; + } else { + throw new RuntimeException( + sprintf( + 'Directory "%s" does not exist.', + $directory + ) + ); + } + } + + /** + * @param string $buffer + * @access protected + * @since Method available since Release 3.1.0 + */ + protected static function write($buffer) + { + if (php_sapi_name() != 'cli') { + $buffer = htmlentities($buffer); + } + + print $buffer; + } + + /** + * Returns the loader to be used. + * + * @return PHPUnit_Runner_TestSuiteLoader + * @access public + * @since Method available since Release 2.2.0 + */ + public function getLoader() + { + if (self::$loader === NULL) { + self::$loader = new PHPUnit_Runner_StandardTestSuiteLoader; + } + + return self::$loader; + } + + /** + * Sets the loader to be used. + * + * @param PHPUnit_Runner_TestSuiteLoader $loader + * @access public + * @static + * @since Method available since Release 3.0.0 + */ + public static function setLoader(PHPUnit_Runner_TestSuiteLoader $loader) + { + self::$loader = $loader; + } + + /** + * @access public + */ + public static function showError($message) + { + self::printVersionString(); + self::write($message . "\n"); + + exit(self::FAILURE_EXIT); + } + + + /** + * @access public + * @static + */ + public static function printVersionString() + { + if (!self::$versionStringPrinted) { + self::write(PHPUnit_Runner_Version::getVersionString() . "\n\n"); + self::$versionStringPrinted = TRUE; + } + } + + /** + * @param array $arguments + * @access protected + * @since Method available since Release 3.2.1 + */ + protected function handleConfiguration(array &$arguments) + { + if (isset($arguments['configuration'])) { + $arguments['configuration'] = new PHPUnit_Util_Configuration( + $arguments['configuration'] + ); + + $arguments['pmd'] = $arguments['configuration']->getPMDConfiguration(); + } else { + $arguments['pmd'] = array(); + } + + $arguments['filter'] = isset($arguments['filter']) ? $arguments['filter'] : FALSE; + $arguments['listeners'] = isset($arguments['listeners']) ? $arguments['listeners'] : array(); + $arguments['repeat'] = isset($arguments['repeat']) ? $arguments['repeat'] : FALSE; + $arguments['stopOnFailure'] = isset($arguments['stopOnFailure']) ? $arguments['stopOnFailure'] : FALSE; + $arguments['testDatabasePrefix'] = isset($arguments['testDatabasePrefix']) ? $arguments['testDatabasePrefix'] : ''; + $arguments['verbose'] = isset($arguments['verbose']) ? $arguments['verbose'] : FALSE; + $arguments['wait'] = isset($arguments['wait']) ? $arguments['wait'] : FALSE; + + if (isset($arguments['configuration'])) { + $filterConfiguration = $arguments['configuration']->getFilterConfiguration(); + + PHPUnit_Util_Filter::$addUncoveredFilesFromWhitelist = $filterConfiguration['whitelist']['addUncoveredFilesFromWhitelist']; + + foreach ($filterConfiguration['blacklist']['include']['directory'] as $dir) { + PHPUnit_Util_Filter::addDirectoryToFilter( + $dir['path'], $dir['suffix'] + ); + } + + foreach ($filterConfiguration['blacklist']['include']['file'] as $file) { + PHPUnit_Util_Filter::addFileToFilter($file); + } + + foreach ($filterConfiguration['blacklist']['exclude']['directory'] as $dir) { + PHPUnit_Util_Filter::removeDirectoryFromFilter( + $dir['path'], $dir['suffix'] + ); + } + + foreach ($filterConfiguration['blacklist']['exclude']['file'] as $file) { + PHPUnit_Util_Filter::removeFileFromFilter($file); + } + + foreach ($filterConfiguration['whitelist']['include']['directory'] as $dir) { + PHPUnit_Util_Filter::addDirectoryToWhitelist( + $dir['path'], $dir['suffix'] + ); + } + + foreach ($filterConfiguration['whitelist']['include']['file'] as $file) { + PHPUnit_Util_Filter::addFileToWhitelist($file); + } + + foreach ($filterConfiguration['whitelist']['exclude']['directory'] as $dir) { + PHPUnit_Util_Filter::removeDirectoryFromWhitelist( + $dir['path'], $dir['suffix'] + ); + } + + foreach ($filterConfiguration['whitelist']['exclude']['file'] as $file) { + PHPUnit_Util_Filter::removeFileFromWhitelist($file); + } + + $phpConfiguration = $arguments['configuration']->getPHPConfiguration(); + + foreach ($phpConfiguration['ini'] as $name => $value) { + ini_set($name, $value); + } + + foreach ($phpConfiguration['var'] as $name => $value) { + $GLOBALS[$name] = $value; + } + + $groupConfiguration = $arguments['configuration']->getGroupConfiguration(); + + if (!empty($groupConfiguration['include']) && !isset($arguments['groups'])) { + $arguments['groups'] = $groupConfiguration['include']; + } + + if (!empty($groupConfiguration['exclude']) && !isset($arguments['excludeGroups'])) { + $arguments['excludeGroups'] = $groupConfiguration['exclude']; + } + + $loggingConfiguration = $arguments['configuration']->getLoggingConfiguration(); + + if (isset($loggingConfiguration['coverage-html']) && !isset($arguments['reportDirectory'])) { + if (isset($loggingConfiguration['charset']) && !isset($arguments['reportCharset'])) { + $arguments['reportCharset'] = $loggingConfiguration['charset']; + } + + if (isset($loggingConfiguration['yui']) && !isset($arguments['reportYUI'])) { + $arguments['reportYUI'] = $loggingConfiguration['yui']; + } + + if (isset($loggingConfiguration['highlight']) && !isset($arguments['reportHighlight'])) { + $arguments['reportHighlight'] = $loggingConfiguration['highlight']; + } + + if (isset($loggingConfiguration['lowUpperBound']) && !isset($arguments['reportLowUpperBound'])) { + $arguments['reportLowUpperBound'] = $loggingConfiguration['lowUpperBound']; + } + + if (isset($loggingConfiguration['highLowerBound']) && !isset($arguments['reportHighLowerBound'])) { + $arguments['reportHighLowerBound'] = $loggingConfiguration['highLowerBound']; + } + + $arguments['reportDirectory'] = $loggingConfiguration['coverage-html']; + } + + if (isset($loggingConfiguration['coverage-xml']) && !isset($arguments['coverageXML'])) { + $arguments['coverageXML'] = $loggingConfiguration['coverage-xml']; + } + + if (isset($loggingConfiguration['graphviz']) && !isset($arguments['graphvizLogfile'])) { + $arguments['graphvizLogfile'] = $loggingConfiguration['graphviz']; + } + + if (isset($loggingConfiguration['json']) && !isset($arguments['jsonLogfile'])) { + $arguments['jsonLogfile'] = $loggingConfiguration['json']; + } + + if (isset($loggingConfiguration['metrics-xml']) && !isset($arguments['metricsXML'])) { + $arguments['metricsXML'] = $loggingConfiguration['metrics-xml']; + } + + if (isset($loggingConfiguration['plain'])) { + $arguments['listeners'][] = new PHPUnit_TextUI_ResultPrinter($loggingConfiguration['plain'], TRUE); + } + + if (isset($loggingConfiguration['pmd-xml']) && !isset($arguments['pmdXML'])) { + if (isset($loggingConfiguration['cpdMinLines']) && !isset($arguments['cpdMinLines'])) { + $arguments['cpdMinLines'] = $loggingConfiguration['cpdMinLines']; + } + + if (isset($loggingConfiguration['cpdMinMatches']) && !isset($arguments['cpdMinMatches'])) { + $arguments['cpdMinMatches'] = $loggingConfiguration['cpdMinMatches']; + } + + $arguments['pmdXML'] = $loggingConfiguration['pmd-xml']; + } + + if (isset($loggingConfiguration['tap']) && !isset($arguments['tapLogfile'])) { + $arguments['tapLogfile'] = $loggingConfiguration['tap']; + } + + if (isset($loggingConfiguration['test-xml']) && !isset($arguments['xmlLogfile'])) { + $arguments['xmlLogfile'] = $loggingConfiguration['test-xml']; + + if (isset($loggingConfiguration['logIncompleteSkipped']) && !isset($arguments['logIncompleteSkipped'])) { + $arguments['logIncompleteSkipped'] = $loggingConfiguration['logIncompleteSkipped']; + } + } + + if (isset($loggingConfiguration['testdox-html']) && !isset($arguments['testdoxHTMLFile'])) { + $arguments['testdoxHTMLFile'] = $loggingConfiguration['testdox-html']; + } + + if (isset($loggingConfiguration['testdox-text']) && !isset($arguments['testdoxTextFile'])) { + $arguments['testdoxTextFile'] = $loggingConfiguration['testdox-text']; + } + + $browsers = $arguments['configuration']->getSeleniumBrowserConfiguration(); + + if (!empty($browsers)) { + require_once 'PHPUnit/Extensions/SeleniumTestCase.php'; + PHPUnit_Extensions_SeleniumTestCase::$browsers = $browsers; + } + } + + $arguments['cpdMinLines'] = isset($arguments['cpdMinLines']) ? $arguments['cpdMinLines'] : 5; + $arguments['cpdMinMatches'] = isset($arguments['cpdMinMatches']) ? $arguments['cpdMinMatches'] : 70; + $arguments['groups'] = isset($arguments['groups']) ? $arguments['groups'] : array(); + $arguments['excludeGroups'] = isset($arguments['excludeGroups']) ? $arguments['excludeGroups'] : array(); + $arguments['logIncompleteSkipped'] = isset($arguments['logIncompleteSkipped']) ? $arguments['logIncompleteSkipped'] : FALSE; + $arguments['reportCharset'] = isset($arguments['reportCharset']) ? $arguments['reportCharset'] : 'ISO-8859-1'; + $arguments['reportYUI'] = isset($arguments['reportYUI']) ? $arguments['reportYUI'] : TRUE; + $arguments['reportHighlight'] = isset($arguments['reportHighlight']) ? $arguments['reportHighlight'] : FALSE; + $arguments['reportLowUpperBound'] = isset($arguments['reportLowUpperBound']) ? $arguments['reportLowUpperBound'] : 35; + $arguments['reportHighLowerBound'] = isset($arguments['reportHighLowerBound']) ? $arguments['reportHighLowerBound'] : 70; + + if (isset($arguments['reportDirectory'])) { + $arguments['reportDirectory'] = $this->getDirectory($arguments['reportDirectory']); + } + } +} +?> Property changes on: test/PHPUnit/TextUI/TestRunner.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/TextUI/Command.php =================================================================== --- test/PHPUnit/TextUI/Command.php (revision 0) +++ test/PHPUnit/TextUI/Command.php (revision 0) @@ -0,0 +1,529 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: Command.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/TextUI/TestRunner.php'; +require_once 'PHPUnit/Util/Log/PMD.php'; +require_once 'PHPUnit/Util/Log/TAP.php'; +require_once 'PHPUnit/Util/Configuration.php'; +require_once 'PHPUnit/Util/Fileloader.php'; +require_once 'PHPUnit/Util/Filter.php'; +require_once 'PHPUnit/Util/Getopt.php'; +require_once 'PHPUnit/Util/Skeleton.php'; +require_once 'PHPUnit/Util/TestDox/ResultPrinter/Text.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * A TestRunner for the Command Line Interface (CLI) + * PHP SAPI Module. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class PHPUnit_TextUI_Command +{ + /** + * @access public + * @static + */ + public static function main() + { + $arguments = self::handleArguments(); + $runner = new PHPUnit_TextUI_TestRunner; + + if (is_object($arguments['test']) && $arguments['test'] instanceof PHPUnit_Framework_Test) { + $suite = $arguments['test']; + } else { + $suite = $runner->getTest( + $arguments['test'], + $arguments['testFile'], + $arguments['syntaxCheck'] + ); + } + + if ($suite->testAt(0) instanceof PHPUnit_Framework_Warning && + strpos($suite->testAt(0)->getMessage(), 'No tests found in class') !== FALSE) { + $skeleton = new PHPUnit_Util_Skeleton( + $arguments['test'], + $arguments['testFile'] + ); + + $result = $skeleton->generate(TRUE); + + if (!$result['incomplete']) { + eval(str_replace(array(''), '', $result['code'])); + $suite = new PHPUnit_Framework_TestSuite($arguments['test'] . 'Test'); + } + } + + try { + $result = $runner->doRun( + $suite, + $arguments + ); + } + + catch (Exception $e) { + throw new RuntimeException( + 'Could not create and run test suite: ' . $e->getMessage() + ); + } + + if ($result->wasSuccessful()) { + exit(PHPUnit_TextUI_TestRunner::SUCCESS_EXIT); + } + + else if($result->errorCount() > 0) { + exit(PHPUnit_TextUI_TestRunner::EXCEPTION_EXIT); + } + + else { + exit(PHPUnit_TextUI_TestRunner::FAILURE_EXIT); + } + } + + /** + * @access protected + * @static + */ + protected static function handleArguments() + { + $arguments = array('syntaxCheck' => TRUE); + + $longOptions = array( + 'configuration=', + 'exclude-group=', + 'filter=', + 'group=', + 'help', + 'loader=', + 'log-json=', + 'log-tap=', + 'log-xml=', + 'repeat=', + 'skeleton', + 'stop-on-failure', + 'tap', + 'testdox', + 'testdox-html=', + 'testdox-text=', + 'no-syntax-check', + 'verbose', + 'version', + 'wait' + ); + + if (class_exists('Image_GraphViz', FALSE)) { + $longOptions[] = 'log-graphviz='; + } + + if (extension_loaded('pdo')) { + $longOptions[] = 'test-db-dsn='; + $longOptions[] = 'test-db-log-rev='; + $longOptions[] = 'test-db-log-prefix='; + $longOptions[] = 'test-db-log-info='; + } + + if (extension_loaded('xdebug')) { + $longOptions[] = 'coverage-html='; + $longOptions[] = 'coverage-xml='; + $longOptions[] = 'log-metrics='; + $longOptions[] = 'log-pmd='; + $longOptions[] = 'report='; + } + + try { + $options = PHPUnit_Util_Getopt::getopt( + $_SERVER['argv'], + 'd:', + $longOptions + ); + } + + catch (RuntimeException $e) { + PHPUnit_TextUI_TestRunner::showError($e->getMessage()); + } + + if (isset($options[1][0])) { + $arguments['test'] = $options[1][0]; + } + + if (isset($options[1][1])) { + $arguments['testFile'] = $options[1][1]; + } else { + $arguments['testFile'] = ''; + } + + foreach ($options[0] as $option) { + switch ($option[0]) { + case '--configuration': { + $arguments['configuration'] = $option[1]; + } + break; + + case '--coverage-xml': { + $arguments['coverageXML'] = $option[1]; + } + break; + + case 'd': { + $ini = explode('=', $option[1]); + + if (isset($ini[0])) { + if (isset($ini[1])) { + ini_set($ini[0], $ini[1]); + } else { + ini_set($ini[0], TRUE); + } + } + } + break; + + case '--help': { + self::showHelp(); + exit(PHPUnit_TextUI_TestRunner::SUCCESS_EXIT); + } + break; + + case '--filter': { + if (preg_match('/^[a-zA-Z0-9_]/', $option[1])) { + $arguments['filter'] = '/^' . $option[1] . '$/'; + } else { + $arguments['filter'] = $option[1]; + } + } + break; + + case '--group': { + $arguments['groups'] = explode(',', $option[1]); + } + break; + + case '--exclude-group': { + $arguments['excludeGroups'] = explode(',', $option[1]); + } + break; + + case '--loader': { + self::handleLoader($option[1]); + } + break; + + case '--log-json': { + $arguments['jsonLogfile'] = $option[1]; + } + break; + + case '--log-graphviz': { + $arguments['graphvizLogfile'] = $option[1]; + } + break; + + case '--log-tap': { + $arguments['tapLogfile'] = $option[1]; + } + break; + + case '--log-xml': { + $arguments['xmlLogfile'] = $option[1]; + } + break; + + case '--log-pmd': { + $arguments['pmdXML'] = $option[1]; + } + break; + + case '--log-metrics': { + $arguments['metricsXML'] = $option[1]; + } + break; + + case '--repeat': { + $arguments['repeat'] = (int)$option[1]; + } + break; + + case '--stop-on-failure': { + $arguments['stopOnFailure'] = TRUE; + } + break; + + case '--test-db-dsn': { + $arguments['testDatabaseDSN'] = $option[1]; + } + break; + + case '--test-db-log-rev': { + $arguments['testDatabaseLogRevision'] = $option[1]; + } + break; + + case '--test-db-prefix': { + $arguments['testDatabasePrefix'] = $option[1]; + } + break; + + case '--test-db-log-info': { + $arguments['testDatabaseLogInfo'] = $option[1]; + } + break; + + case '--coverage-html': + case '--report': { + $arguments['reportDirectory'] = $option[1]; + } + break; + + case '--skeleton': { + if (isset($arguments['test']) && isset($arguments['testFile'])) { + self::doSkeleton($arguments['test'], $arguments['testFile']); + } else { + self::showHelp(); + exit(PHPUnit_TextUI_TestRunner::EXCEPTION_EXIT); + } + } + break; + + case '--tap': { + $arguments['printer'] = new PHPUnit_Util_Log_TAP; + } + break; + + case '--testdox': { + $arguments['printer'] = new PHPUnit_Util_TestDox_ResultPrinter_Text; + } + break; + + case '--testdox-html': { + $arguments['testdoxHTMLFile'] = $option[1]; + } + break; + + case '--testdox-text': { + $arguments['testdoxTextFile'] = $option[1]; + } + break; + + case '--no-syntax-check': { + $arguments['syntaxCheck'] = FALSE; + } + break; + + case '--verbose': { + $arguments['verbose'] = TRUE; + } + break; + + case '--version': { + PHPUnit_TextUI_TestRunner::printVersionString(); + exit(PHPUnit_TextUI_TestRunner::SUCCESS_EXIT); + } + break; + + case '--wait': { + $arguments['wait'] = TRUE; + } + break; + } + } + + if (!isset($arguments['test']) && isset($arguments['configuration'])) { + $configuration = new PHPUnit_Util_Configuration( + $arguments['configuration'] + ); + + $testSuite = $configuration->getTestSuiteConfiguration(); + + if ($testSuite !== NULL) { + $arguments['test'] = $testSuite; + } + } + + if (!isset($arguments['test']) || + (isset($arguments['testDatabaseLogRevision']) && !isset($arguments['testDatabaseDSN']))) { + self::showHelp(); + exit(PHPUnit_TextUI_TestRunner::EXCEPTION_EXIT); + } + + return $arguments; + } + + /** + * @param string $test + * @param string $testFile + * @access protected + * @static + */ + protected static function doSkeleton($test, $testFile) + { + if ($test !== FALSE) { + PHPUnit_TextUI_TestRunner::printVersionString(); + + try { + $skeleton = new PHPUnit_Util_Skeleton($test, $testFile); + $skeleton->write(); + } + + catch (Exception $e) { + print $e->getMessage() . "\n"; + + printf( + 'Could not write test class skeleton for "%s" to "%s".' . "\n", + $test, + $testFile + ); + + exit(PHPUnit_TextUI_TestRunner::FAILURE_EXIT); + } + + printf( + 'Wrote test class skeleton for "%s" to "%s".' . "\n", + $test, + $skeleton->getTestSourceFile() + ); + + exit(PHPUnit_TextUI_TestRunner::SUCCESS_EXIT); + } + } + + /** + * @param string $loaderName + * @access protected + * @static + */ + protected static function handleLoader($loaderName) + { + if (!class_exists($loaderName, FALSE)) { + PHPUnit_Util_Fileloader::checkAndLoad( + str_replace('_', '/', $loaderName) . '.php' + ); + } + + if (class_exists($loaderName, FALSE)) { + $class = new ReflectionClass($loaderName); + + if ($class->implementsInterface('PHPUnit_Runner_TestSuiteLoader') && + $class->isInstantiable()) { + $loader = $class->newInstance(); + } + } + + if (!isset($loader)) { + PHPUnit_TextUI_TestRunner::showError( + sprintf( + 'Could not use "%s" as loader.', + + $loaderName + ) + ); + } + + PHPUnit_TextUI_TestRunner::setLoader($loader); + } + + /** + * @access public + * @static + */ + public static function showHelp() + { + PHPUnit_TextUI_TestRunner::printVersionString(); + + print "Usage: phpunit [switches] UnitTest [UnitTest.php]\n\n"; + + if (class_exists('Image_GraphViz', FALSE)) { + print " --log-graphviz Log test execution in GraphViz markup.\n"; + } + + print " --log-json Log test execution in JSON format.\n" . + " --log-tap Log test execution in TAP format to file.\n" . + " --log-xml Log test execution in XML format to file.\n"; + + if (extension_loaded('xdebug')) { + print " --log-metrics Write metrics report in XML format.\n" . + " --log-pmd Write violations report in PMD XML format.\n\n" . + " --coverage-html Generate code coverage report in HTML format.\n" . + " --coverage-xml Write code coverage information in XML format.\n\n"; + } + + if (extension_loaded('pdo')) { + print " --test-db-dsn DSN for the test database.\n" . + " --test-db-log-rev Revision information for database logging.\n" . + " --test-db-prefix ... Prefix that should be stripped from filenames.\n" . + " --test-db-log-info ... Additional information for database logging.\n\n"; + } + + print " --testdox-html Write agile documentation in HTML format to file.\n" . + " --testdox-text Write agile documentation in Text format to file.\n\n" . + " --filter Filter which tests to run.\n" . + " --group ... Only runs tests from the specified group(s).\n" . + " --exclude-group ... Exclude tests from the specified group(s).\n\n" . + " --loader TestSuiteLoader implementation to use.\n" . + " --repeat Runs the test(s) repeatedly.\n\n" . + " --tap Report test execution progress in TAP format.\n" . + " --testdox Report test execution progress in TestDox format.\n\n" . + " --no-syntax-check Disable syntax check of test source files.\n" . + " --stop-on-failure Stop execution upon first error or failure.\n" . + " --verbose Output more verbose information.\n" . + " --wait Waits for a keystroke after each test.\n\n" . + " --skeleton Generate skeleton UnitTest class for Unit in Unit.php.\n\n" . + " --help Prints this usage information.\n" . + " --version Prints the version and exits.\n\n" . + " --configuration Read configuration from XML file.\n" . + " -d key[=value] Sets a php.ini value.\n"; + } +} + +define('PHPUnit_MAIN_METHOD', 'PHPUnit_TextUI_Command::main'); +PHPUnit_TextUI_Command::main(); +?> Property changes on: test/PHPUnit/TextUI/Command.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/TextUI/ResultPrinter.php =================================================================== --- test/PHPUnit/TextUI/ResultPrinter.php (revision 0) +++ test/PHPUnit/TextUI/ResultPrinter.php (revision 0) @@ -0,0 +1,567 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: ResultPrinter.php 1985 2007-12-26 18:11:55Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; +require_once 'PHPUnit/Util/Printer.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Prints the result of a TextUI TestRunner run. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class PHPUnit_TextUI_ResultPrinter extends PHPUnit_Util_Printer implements PHPUnit_Framework_TestListener +{ + const EVENT_TEST_START = 0; + const EVENT_TEST_END = 1; + const EVENT_TESTSUITE_START = 2; + const EVENT_TESTSUITE_END = 3; + + /** + * @var integer + * @access protected + */ + protected $column = 0; + + /** + * @var array + * @access protected + */ + protected $numberOfTests = array(); + + /** + * @var array + * @access protected + */ + protected $testSuiteSize = array(); + + /** + * @var integer + * @access protected + */ + protected $lastEvent = -1; + + /** + * @var boolean + * @access protected + */ + protected $lastTestFailed = FALSE; + + /** + * @var boolean + * @access protected + */ + protected $verbose = FALSE; + + /** + * Constructor. + * + * @param mixed $out + * @param boolean $verbose + * @throws InvalidArgumentException + * @access public + * @since Method available since Release 3.0.0 + */ + public function __construct($out = NULL, $verbose = FALSE) + { + parent::__construct($out); + + if (is_bool($verbose)) { + $this->verbose = $verbose; + } else { + throw new InvalidArgumentException; + } + } + + /** + * @param PHPUnit_Framework_TestResult $result + * @access public + */ + public function printResult(PHPUnit_Framework_TestResult $result) + { + $this->printHeader($result->time()); + + if ($result->errorCount() > 0) { + $this->printErrors($result); + } + + if ($result->failureCount() > 0) { + if ($result->errorCount() > 0) { + print "\n--\n\n"; + } + + $this->printFailures($result); + } + + if ($this->verbose) { + if ($result->notImplementedCount() > 0) { + if ($result->failureCount() > 0) { + print "\n--\n\n"; + } + + $this->printIncompletes($result); + } + + if ($result->skippedCount() > 0) { + if ($result->notImplementedCount() > 0) { + print "\n--\n\n"; + } + + $this->printSkipped($result); + } + } + + $this->printFooter($result); + } + + /** + * @param array $defects + * @param integer $count + * @param string $type + * @access protected + */ + protected function printDefects(array $defects, $count, $type) + { + if ($count == 0) { + return; + } + + $this->write( + sprintf( + "There %s %d %s%s:\n", + + ($count == 1) ? 'was' : 'were', + $count, + $type, + ($count == 1) ? '' : 's' + ) + ); + + $i = 1; + + foreach ($defects as $defect) { + $this->printDefect($defect, $i++); + } + } + + /** + * @param PHPUnit_Framework_TestFailure $defect + * @param integer $count + * @access protected + */ + protected function printDefect(PHPUnit_Framework_TestFailure $defect, $count) + { + $this->printDefectHeader($defect, $count); + $this->printDefectTrace($defect); + } + + /** + * @param PHPUnit_Framework_TestFailure $defect + * @param integer $count + * @access protected + */ + protected function printDefectHeader(PHPUnit_Framework_TestFailure $defect, $count) + { + $failedTest = $defect->failedTest(); + + if ($failedTest instanceof PHPUnit_Framework_SelfDescribing) { + $testName = $failedTest->toString(); + } else { + $testName = get_class($failedTest); + } + + $this->write( + sprintf( + "\n%d) %s\n", + + $count, + $testName + ) + ); + } + + /** + * @param PHPUnit_Framework_TestFailure $defect + * @access protected + */ + protected function printDefectTrace(PHPUnit_Framework_TestFailure $defect) + { + $this->write( + $defect->toStringVerbose($this->verbose) . + PHPUnit_Util_Filter::getFilteredStacktrace( + $defect->thrownException(), + FALSE + ) + ); + } + + /** + * @param PHPUnit_Framework_TestResult $result + * @access protected + */ + protected function printErrors(PHPUnit_Framework_TestResult $result) + { + $this->printDefects($result->errors(), $result->errorCount(), 'error'); + } + + /** + * @param PHPUnit_Framework_TestResult $result + * @access protected + */ + protected function printFailures(PHPUnit_Framework_TestResult $result) + { + $this->printDefects($result->failures(), $result->failureCount(), 'failure'); + } + + /** + * @param PHPUnit_Framework_TestResult $result + * @access protected + */ + protected function printIncompletes(PHPUnit_Framework_TestResult $result) + { + $this->printDefects($result->notImplemented(), $result->notImplementedCount(), 'incomplete test'); + } + + /** + * @param PHPUnit_Framework_TestResult $result + * @access protected + * @since Method available since Release 3.0.0 + */ + protected function printSkipped(PHPUnit_Framework_TestResult $result) + { + $this->printDefects($result->skipped(), $result->skippedCount(), 'skipped test'); + } + + /** + * @param float $timeElapsed + * @access protected + */ + protected function printHeader($timeElapsed) + { + $this->write("\n\nTime: " . PHPUnit_Util_Timer::secondsToTimeString($timeElapsed) . "\n\n"); + } + + /** + * @param PHPUnit_Framework_TestResult $result + * @access protected + */ + protected function printFooter(PHPUnit_Framework_TestResult $result) + { + if ($result->wasSuccessful() && + $result->allCompletlyImplemented() && + $result->noneSkipped()) { + $this->write( + sprintf( + "\nOK (%d test%s)\n", + + count($result), + (count($result) == 1) ? '' : 's' + ) + ); + } + + else if ((!$result->allCompletlyImplemented() || + !$result->noneSkipped())&& + $result->wasSuccessful()) { + $this->write( + sprintf( + "\nOK, but incomplete or skipped tests!\n" . + "Tests: %d%s%s.\n", + + count($result), + $this->getCountString($result->notImplementedCount(), 'Incomplete'), + $this->getCountString($result->skippedCount(), 'Skipped') + ) + ); + } + + else { + $this->write( + sprintf( + "\nFAILURES!\n" . + "Tests: %d%s%s%s%s.\n", + + count($result), + $this->getCountString($result->failureCount(), 'Failures'), + $this->getCountString($result->errorCount(), 'Errors'), + $this->getCountString($result->notImplementedCount(), 'Incomplete'), + $this->getCountString($result->skippedCount(), 'Skipped') + ) + ); + } + } + + /** + * @param integer $count + * @param string $name + * @return string + * @access protected + * @since Method available since Release 3.0.0 + */ + protected function getCountString($count, $name) + { + $string = ''; + + if ($count > 0) { + $string = sprintf( + ', %s: %d', + + $name, + $count + ); + } + + return $string; + } + + /** + * @access public + */ + public function printWaitPrompt() + { + $this->write("\n to continue\n"); + } + + /** + * An error occurred. + * + * @param PHPUnit_Framework_Test $test + * @param Exception $e + * @param float $time + * @access public + */ + public function addError(PHPUnit_Framework_Test $test, Exception $e, $time) + { + $this->writeProgress('E'); + $this->lastTestFailed = TRUE; + } + + /** + * A failure occurred. + * + * @param PHPUnit_Framework_Test $test + * @param PHPUnit_Framework_AssertionFailedError $e + * @param float $time + * @access public + */ + public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) + { + $this->writeProgress('F'); + $this->lastTestFailed = TRUE; + } + + /** + * Incomplete test. + * + * @param PHPUnit_Framework_Test $test + * @param Exception $e + * @param float $time + * @access public + */ + public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time) + { + $this->writeProgress('I'); + $this->lastTestFailed = TRUE; + } + + /** + * Skipped test. + * + * @param PHPUnit_Framework_Test $test + * @param Exception $e + * @param float $time + * @access public + * @since Method available since Release 3.0.0 + */ + public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time) + { + $this->writeProgress('S'); + $this->lastTestFailed = TRUE; + } + + /** + * A testsuite started. + * + * @param PHPUnit_Framework_TestSuite $suite + * @access public + * @since Method available since Release 2.2.0 + */ + public function startTestSuite(PHPUnit_Framework_TestSuite $suite) + { + if ($this->verbose) { + $name = $suite->getName(); + + if (empty($name)) { + $name = 'Test Suite'; + } + + $this->write( + sprintf( + "%s%s%s\n", + + $this->lastEvent == self::EVENT_TESTSUITE_END ? "\n" : '', + str_repeat(' ', count($this->testSuiteSize)), + $name + ) + ); + + array_push($this->numberOfTests, 0); + array_push($this->testSuiteSize, count($suite)); + } + + else if (empty($this->numberOfTests)) { + array_push($this->numberOfTests, 0); + array_push($this->testSuiteSize, count($suite)); + } + + $this->lastEvent = self::EVENT_TESTSUITE_START; + } + + /** + * A testsuite ended. + * + * @param PHPUnit_Framework_TestSuite $suite + * @access public + * @since Method available since Release 2.2.0 + */ + public function endTestSuite(PHPUnit_Framework_TestSuite $suite) + { + if ($this->verbose) { + array_pop($this->numberOfTests); + array_pop($this->testSuiteSize); + + $this->column = 0; + + if ($this->lastEvent != self::EVENT_TESTSUITE_END) { + $this->write("\n"); + } + } + + $this->lastEvent = self::EVENT_TESTSUITE_END; + } + + /** + * A test started. + * + * @param PHPUnit_Framework_Test $test + * @access public + */ + public function startTest(PHPUnit_Framework_Test $test) + { + if ($this->verbose) { + $this->numberOfTests[count($this->numberOfTests)-1]++; + } else { + $this->numberOfTests[0]++; + } + + $this->lastEvent = self::EVENT_TEST_START; + } + + /** + * A test ended. + * + * @param PHPUnit_Framework_Test $test + * @param float $time + * @access public + */ + public function endTest(PHPUnit_Framework_Test $test, $time) + { + if (!$this->lastTestFailed) { + $this->writeProgress('.'); + } + + $this->lastEvent = self::EVENT_TEST_END; + $this->lastTestFailed = FALSE; + } + + /** + * @param string $progress + * @access protected + */ + protected function writeProgress($progress) + { + $indent = max(0, count($this->testSuiteSize) - 1); + + if ($this->column == 0) { + $this->write(str_repeat(' ', $indent)); + } + + $this->write($progress); + + if ($this->column++ == 60 - 1 - $indent) { + if ($this->verbose) { + $numberOfTests = $this->numberOfTests[count($this->numberOfTests)-1]; + $testSuiteSize = $this->testSuiteSize[count($this->testSuiteSize)-1]; + } else { + $numberOfTests = $this->numberOfTests[0]; + $testSuiteSize = $this->testSuiteSize[0]; + } + + $width = strlen((string)$testSuiteSize); + + $this->write( + sprintf( + ' %' . $width . 'd / %' . $width . "d\n", + + $numberOfTests, + $testSuiteSize + ) + ); + + $this->column = 0; + } + } +} +?> Property changes on: test/PHPUnit/TextUI/ResultPrinter.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework.php =================================================================== --- test/PHPUnit/Framework.php (revision 0) +++ test/PHPUnit/Framework.php (revision 0) @@ -0,0 +1,71 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: Framework.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/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +require 'PHPUnit/Framework/SelfDescribing.php'; +require 'PHPUnit/Framework/AssertionFailedError.php'; +require 'PHPUnit/Framework/Assert.php'; +require 'PHPUnit/Framework/Error.php'; +require 'PHPUnit/Framework/Notice.php'; +require 'PHPUnit/Framework/IncompleteTest.php'; +require 'PHPUnit/Framework/SkippedTest.php'; +require 'PHPUnit/Framework/Test.php'; +require 'PHPUnit/Framework/TestFailure.php'; +require 'PHPUnit/Framework/TestListener.php'; +require 'PHPUnit/Framework/TestResult.php'; +require 'PHPUnit/Framework/ExpectationFailedException.php'; +require 'PHPUnit/Framework/IncompleteTestError.php'; +require 'PHPUnit/Framework/SkippedTestError.php'; +require 'PHPUnit/Framework/SkippedTestSuiteError.php'; +require 'PHPUnit/Framework/TestCase.php'; +require 'PHPUnit/Framework/TestSuite.php'; +require 'PHPUnit/Framework/Warning.php'; +require 'PHPUnit/Framework/Constraint.php'; +require 'PHPUnit/Framework/ComparisonFailure.php'; +?> Property changes on: test/PHPUnit/Framework.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Runner/TestSuiteLoader.php =================================================================== --- test/PHPUnit/Runner/TestSuiteLoader.php (revision 0) +++ test/PHPUnit/Runner/TestSuiteLoader.php (revision 0) @@ -0,0 +1,80 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: TestSuiteLoader.php 1985 2007-12-26 18:11:55Z 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'); + +/** + * An interface to define how a test suite should be loaded. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: 3.2.9 + * @link http://www.phpunit.de/ + * @since Interface available since Release 2.0.0 + */ +interface PHPUnit_Runner_TestSuiteLoader +{ + /** + * @param string $suiteClassName + * @param string $suiteClassFile + * @return ReflectionClass + * @access public + */ + public function load($suiteClassName, $suiteClassFile = ''); + + /** + * @param ReflectionClass $aClass + * @return ReflectionClass + * @access public + */ + public function reload(ReflectionClass $aClass); +} +?> Property changes on: test/PHPUnit/Runner/TestSuiteLoader.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Runner/StandardTestSuiteLoader.php =================================================================== --- test/PHPUnit/Runner/StandardTestSuiteLoader.php (revision 0) +++ test/PHPUnit/Runner/StandardTestSuiteLoader.php (revision 0) @@ -0,0 +1,124 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: StandardTestSuiteLoader.php 2085 2008-01-14 16:03:31Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit/Util/Filter.php'; +require_once 'PHPUnit/Runner/TestSuiteLoader.php'; +require_once 'PHPUnit/Util/Fileloader.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * The standard test suite loader. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class PHPUnit_Runner_StandardTestSuiteLoader implements PHPUnit_Runner_TestSuiteLoader +{ + /** + * @param string $suiteClassName + * @param string $suiteClassFile + * @param boolean $syntaxCheck + * @return ReflectionClass + * @throws RuntimeException + * @access public + */ + public function load($suiteClassName, $suiteClassFile = '', $syntaxCheck = TRUE) + { + $suiteClassName = str_replace('.php', '', $suiteClassName); + + if (empty($suiteClassFile)) { + $suiteClassFile = str_replace(array('_', '::'), DIRECTORY_SEPARATOR, $suiteClassName) . '.php'; + } + + if (!class_exists($suiteClassName, FALSE)) { + if(!file_exists($suiteClassFile)) { + $includePaths = explode(PATH_SEPARATOR, get_include_path()); + + foreach ($includePaths as $includePath) { + $file = $includePath . DIRECTORY_SEPARATOR . $suiteClassFile; + + if (file_exists($file)) { + $suiteClassFile = $file; + break; + } + } + } + + PHPUnit_Util_Fileloader::checkAndLoad($suiteClassFile, $syntaxCheck); + } + + if (class_exists($suiteClassName, FALSE)) { + return new ReflectionClass($suiteClassName); + } else { + throw new RuntimeException( + sprintf( + 'Class %s could not be found in %s.', + + $suiteClassName, + $suiteClassFile + ) + ); + } + } + + /** + * @param ReflectionClass $aClass + * @return ReflectionClass + * @access public + */ + public function reload(ReflectionClass $aClass) + { + return $aClass; + } +} +?> Property changes on: test/PHPUnit/Runner/StandardTestSuiteLoader.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Runner/BaseTestRunner.php =================================================================== --- test/PHPUnit/Runner/BaseTestRunner.php (revision 0) +++ test/PHPUnit/Runner/BaseTestRunner.php (revision 0) @@ -0,0 +1,313 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: BaseTestRunner.php 1985 2007-12-26 18:11:55Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; +require_once 'PHPUnit/Runner/StandardTestSuiteLoader.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Base class for all test runners. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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_Runner_BaseTestRunner implements PHPUnit_Framework_TestListener +{ + const STATUS_PASSED = 0; + const STATUS_SKIPPED = 1; + const STATUS_INCOMPLETE = 2; + const STATUS_FAILURE = 3; + const STATUS_ERROR = 4; + const SUITE_METHODNAME = 'suite'; + + /** + * An error occurred. + * + * @param PHPUnit_Framework_Test $test + * @param Exception $e + * @param float $time + * @access public + */ + public function addError(PHPUnit_Framework_Test $test, Exception $e, $time) + { + $this->testFailed(self::STATUS_ERROR, $test, $e); + } + + /** + * A failure occurred. + * + * @param PHPUnit_Framework_Test $test + * @param PHPUnit_Framework_AssertionFailedError $e + * @param float $time + * @access public + */ + public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) + { + $this->testFailed(self::STATUS_FAILURE, $test, $e); + } + + /** + * Incomplete test. + * + * @param PHPUnit_Framework_Test $test + * @param Exception $e + * @param float $time + * @access public + */ + public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time) + { + $this->testFailed(self::STATUS_INCOMPLETE, $test, $e); + } + + /** + * Skipped test. + * + * @param PHPUnit_Framework_Test $test + * @param Exception $e + * @param float $time + * @access public + * @since Method available since Release 3.0.0 + */ + public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time) + { + $this->testFailed(self::STATUS_SKIPPED, $test, $e); + } + + /** + * A testsuite started. + * + * @param PHPUnit_Framework_TestSuite $suite + * @access public + * @since Method available since Release 2.2.0 + */ + public function startTestSuite(PHPUnit_Framework_TestSuite $suite) + { + } + + /** + * A testsuite ended. + * + * @param PHPUnit_Framework_TestSuite $suite + * @access public + * @since Method available since Release 2.2.0 + */ + public function endTestSuite(PHPUnit_Framework_TestSuite $suite) + { + } + + /** + * A test started. + * + * @param PHPUnit_Framework_Test $test + * @access public + */ + public function startTest(PHPUnit_Framework_Test $test) + { + $this->testStarted($test->getName()); + } + + /** + * A test ended. + * + * @param PHPUnit_Framework_Test $test + * @param float $time + * @access public + */ + public function endTest(PHPUnit_Framework_Test $test, $time) + { + $this->testEnded($test->getName()); + } + + /** + * Returns the loader to be used. + * + * @return PHPUnit_Runner_TestSuiteLoader + * @access public + */ + public function getLoader() + { + return new PHPUnit_Runner_StandardTestSuiteLoader; + } + + /** + * Returns the Test corresponding to the given suite. + * This is a template method, subclasses override + * the runFailed() and clearStatus() methods. + * + * @param string $suiteClassName + * @param string $suiteClassFile + * @param boolean $syntaxCheck + * @return PHPUnit_Framework_Test + * @access public + */ + public function getTest($suiteClassName, $suiteClassFile = '', $syntaxCheck = TRUE) + { + try { + $testClass = $this->loadSuiteClass( + $suiteClassName, $suiteClassFile, $syntaxCheck + ); + } + + catch (Exception $e) { + $this->runFailed($e->getMessage()); + return NULL; + } + + try { + $suiteMethod = $testClass->getMethod(self::SUITE_METHODNAME); + + if (!$suiteMethod->isStatic()) { + $this->runFailed( + 'suite() method must be static.' + ); + + return NULL; + } + + try { + $test = $suiteMethod->invoke(NULL, $testClass->getName()); + } + + catch (ReflectionException $e) { + $this->runFailed( + sprintf( + "Failed to invoke suite() method.\n%s", + + $e->getMessage() + ) + ); + + return NULL; + } + } + + catch (ReflectionException $e) { + $test = new PHPUnit_Framework_TestSuite($testClass); + } + + $this->clearStatus(); + + return $test; + } + + /** + * Override to define how to handle a failed loading of + * a test suite. + * + * @param string $message + * @access protected + * @abstract + */ + abstract protected function runFailed($message); + + /** + * Returns the loaded ReflectionClass for a suite name. + * + * @param string $suiteClassName + * @param string $suiteClassFile + * @param boolean $syntaxCheck + * @return ReflectionClass + * @access protected + */ + protected function loadSuiteClass($suiteClassName, $suiteClassFile = '', $syntaxCheck = TRUE) + { + $loader = $this->getLoader(); + + if ($loader instanceof PHPUnit_Runner_StandardTestSuiteLoader) { + return $loader->load($suiteClassName, $suiteClassFile, $syntaxCheck); + } else { + return $loader->load($suiteClassName, $suiteClassFile); + } + } + + /** + * Clears the status message. + * + * @access protected + */ + protected function clearStatus() + { + } + + /** + * A test started. + * + * @param string $testName + * @access public + * @abstract + */ + abstract public function testStarted($testName); + + /** + * A test ended. + * + * @param string $testName + * @access public + * @abstract + */ + abstract public function testEnded($testName); + + /** + * A test failed. + * + * @param integer $status + * @param PHPUnit_Framework_Test $test + * @param PHPUnit_Framework_AssertionFailedError $e + * @access public + * @abstract + */ + abstract public function testFailed($status, PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e); +} +?> Property changes on: test/PHPUnit/Runner/BaseTestRunner.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Runner/Version.php =================================================================== --- test/PHPUnit/Runner/Version.php (revision 0) +++ test/PHPUnit/Runner/Version.php (revision 0) @@ -0,0 +1,87 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: Version.php 1985 2007-12-26 18:11:55Z 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'); + +/** + * This class defines the current version of PHPUnit. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class PHPUnit_Runner_Version +{ + /** + * Returns the current version of PHPUnit. + * + * @return string + * @access public + * @static + */ + public static function id() + { + return '3.2.9'; + } + + /** + * @return string + * @access public + * @static + */ + public static function getVersionString() + { + return 'PHPUnit 3.2.9 by Sebastian Bergmann.'; + } +} +?> Property changes on: test/PHPUnit/Runner/Version.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Runner/TestCollector.php =================================================================== --- test/PHPUnit/Runner/TestCollector.php (revision 0) +++ test/PHPUnit/Runner/TestCollector.php (revision 0) @@ -0,0 +1,72 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: TestCollector.php 1985 2007-12-26 18:11:55Z 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'); + +/** + * Collects Test class names to be presented + * by the TestSelector. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: 3.2.9 + * @link http://www.phpunit.de/ + * @since Interface available since Release 2.0.0 + */ +interface PHPUnit_Runner_TestCollector +{ + /** + * @return array + * @access public + */ + public function collectTests(); +} +?> Property changes on: test/PHPUnit/Runner/TestCollector.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Runner/IncludePathTestCollector.php =================================================================== --- test/PHPUnit/Runner/IncludePathTestCollector.php (revision 0) +++ test/PHPUnit/Runner/IncludePathTestCollector.php (revision 0) @@ -0,0 +1,166 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: IncludePathTestCollector.php 1985 2007-12-26 18:11:55Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 2.1.0 + */ + +require_once 'PHPUnit/Util/Filter.php'; +require_once 'PHPUnit/Runner/TestCollector.php'; +require_once 'PHPUnit/Util/FilterIterator.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * A test collector that collects tests from one or more directories + * recursively. If no directories are specified, the include_path is searched. + * + * + * $testCollector = new PHPUnit_Runner_IncludePathTestCollector( + * array('/path/to/*Test.php files') + * ); + * + * $suite = new PHPUnit_Framework_TestSuite('My Test Suite'); + * $suite->addTestFiles($testCollector->collectTests()); + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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.1.0 + */ +class PHPUnit_Runner_IncludePathTestCollector implements PHPUnit_Runner_TestCollector +{ + /** + * @var string + * @access protected + */ + protected $filterIterator; + + /** + * @var array + * @access protected + */ + protected $paths; + + /** + * @var string + * @access protected + */ + protected $suffix; + + /** + * @param array $paths + * @param string $suffix + * @access public + */ + public function __construct(array $paths = array(), $suffix = 'Test.php') + { + if (!empty($paths)) { + $this->paths = $paths; + } else { + $this->paths = explode(PATH_SEPARATOR, get_include_path()); + } + + $this->suffix = $suffix; + } + + /** + * @return array + * @access public + */ + public function collectTests() + { + $pathIterator = new AppendIterator; + $result = array(); + + foreach ($this->paths as $path) { + $pathIterator->append( + new RecursiveIteratorIterator( + new RecursiveDirectoryIterator($path) + ) + ); + } + + $filterIterator = new PHPUnit_Util_FilterIterator( + $pathIterator, $this->suffix + ); + + if ($this->filterIterator !== NULL) { + $class = new ReflectionClass($this->filterIterator); + $filterIterator = $class->newInstance($filterIterator); + } + + return $filterIterator; + } + + /** + * Adds a FilterIterator to filter the source files to be collected. + * + * @param string $filterIterator + * @throws InvalidArgumentException + * @access public + */ + public function setFilterIterator($filterIterator) + { + if (is_string($filterIterator) && class_exists($filterIterator)) { + try { + $class = new ReflectionClass($filterIterator); + + if ($class->isSubclassOf('FilterIterator')) { + $this->filterIterator = $filterIterator; + } + } + + catch (ReflectionException $e) { + throw new InvalidArgumentException; + } + } else { + throw new InvalidArgumentException; + } + } +} +?> Property changes on: test/PHPUnit/Runner/IncludePathTestCollector.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/TestSuite.php =================================================================== --- test/PHPUnit/Framework/TestSuite.php (revision 0) +++ test/PHPUnit/Framework/TestSuite.php (revision 0) @@ -0,0 +1,877 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: TestSuite.php 2157 2008-01-17 13:06:52Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit/Framework.php'; +require_once 'PHPUnit/Extensions/PhptTestCase.php'; +require_once 'PHPUnit/Runner/BaseTestRunner.php'; +require_once 'PHPUnit/Util/Class.php'; +require_once 'PHPUnit/Util/Fileloader.php'; +require_once 'PHPUnit/Util/Filter.php'; +require_once 'PHPUnit/Util/Test.php'; +require_once 'PHPUnit/Util/TestSuiteIterator.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +if (!class_exists('PHPUnit_Framework_TestSuite', FALSE)) { + +/** + * A TestSuite is a composite of Tests. It runs a collection of test cases. + * + * Here is an example using the dynamic test definition. + * + * + * addTest(new MathTest('testPass')); + * ?> + * + * + * Alternatively, a TestSuite can extract the tests to be run automatically. + * To do so you pass a ReflectionClass instance for your + * PHPUnit_Framework_TestCase class to the PHPUnit_Framework_TestSuite + * constructor. + * + * + * + * + * + * This constructor creates a suite with all the methods starting with + * "test" that take no arguments. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class PHPUnit_Framework_TestSuite implements PHPUnit_Framework_Test, PHPUnit_Framework_SelfDescribing, IteratorAggregate +{ + /** + * Fixture that is shared between the tests of this test suite. + * + * @var mixed + * @access protected + */ + protected $sharedFixture; + + /** + * The name of the test suite. + * + * @var string + * @access protected + */ + protected $name = ''; + + /** + * The test groups of the test suite. + * + * @var array + * @access protected + */ + protected $groups = array(); + + /** + * The tests in the test suite. + * + * @var array + * @access protected + */ + protected $tests = array(); + + /** + * The number of tests in the test suite. + * + * @var integer + * @access protected + */ + protected $numTests = -1; + + /** + * Constructs a new TestSuite: + * + * - PHPUnit_Framework_TestSuite() constructs an empty TestSuite. + * + * - PHPUnit_Framework_TestSuite(ReflectionClass) constructs a + * TestSuite from the given class. + * + * - PHPUnit_Framework_TestSuite(ReflectionClass, String) + * constructs a TestSuite from the given class with the given + * name. + * + * - PHPUnit_Framework_TestSuite(String) either constructs a + * TestSuite from the given class (if the passed string is the + * name of an existing class) or constructs an empty TestSuite + * with the given name. + * + * @param mixed $theClass + * @param string $name + * @throws InvalidArgumentException + * @access public + */ + public function __construct($theClass = '', $name = '') + { + $argumentsValid = FALSE; + + if (is_object($theClass) && + $theClass instanceof ReflectionClass) { + $argumentsValid = TRUE; + } + + else if (is_string($theClass) && $theClass !== '' + && class_exists($theClass, FALSE)) { + $argumentsValid = TRUE; + + if ($name == '') { + $name = $theClass; + } + + $theClass = new ReflectionClass($theClass); + } + + else if (is_string($theClass)) { + $this->setName($theClass); + return; + } + + if (!$argumentsValid) { + throw new InvalidArgumentException; + } + + PHPUnit_Util_Filter::addFileToFilter( + realpath($theClass->getFilename()), + 'TESTS' + ); + + if ($name != '') { + $this->setName($name); + } else { + $this->setName($theClass->getName()); + } + + $constructor = $theClass->getConstructor(); + + if ($constructor !== NULL && + !$constructor->isPublic()) { + $this->addTest( + self::warning( + sprintf( + 'Class "%s" has no public constructor.', + + $theClass->getName() + ) + ) + ); + + return; + } + + $className = $theClass->getName(); + $names = array(); + $classGroups = PHPUnit_Util_Test::getGroups($theClass); + + foreach ($theClass->getMethods() as $method) { + if (strpos($method->getDeclaringClass()->getName(), 'PHPUnit_') !== 0) { + $this->addTestMethod( + $method, + PHPUnit_Util_Test::getGroups($method, $classGroups), + $names, + $theClass + ); + } + } + + if (empty($this->tests)) { + $this->addTest( + self::warning( + sprintf( + 'No tests found in class "%s".', + + $theClass->getName() + ) + ) + ); + } + } + + /** + * Returns a string representation of the test suite. + * + * @return string + * @access public + */ + public function toString() + { + return $this->getName(); + } + + /** + * Adds a test to the suite. + * + * @param PHPUnit_Framework_Test $test + * @param array $groups + * @access public + */ + public function addTest(PHPUnit_Framework_Test $test, $groups = array()) + { + $this->tests[] = $test; + $this->numTests = -1; + + if ($test instanceof PHPUnit_Framework_TestSuite && empty($groups)) { + $groups = $test->getGroups(); + } + + if (empty($groups)) { + $groups = array('__nogroup__'); + } + + foreach ($groups as $group) { + if (!isset($this->groups[$group])) { + $this->groups[$group] = array($test); + } else { + $this->groups[$group][] = $test; + } + } + } + + /** + * Adds the tests from the given class to the suite. + * + * @param mixed $testClass + * @throws InvalidArgumentException + * @access public + */ + public function addTestSuite($testClass) + { + if (is_string($testClass) && class_exists($testClass)) { + $testClass = new ReflectionClass($testClass); + } + + if (!is_object($testClass)) { + throw new InvalidArgumentException; + } + + if ($testClass instanceof PHPUnit_Framework_TestSuite) { + $this->addTest($testClass); + } + + else if ($testClass instanceof ReflectionClass) { + $suiteMethod = FALSE; + + if (!$testClass->isAbstract()) { + if ($testClass->hasMethod(PHPUnit_Runner_BaseTestRunner::SUITE_METHODNAME)) { + $method = $testClass->getMethod( + PHPUnit_Runner_BaseTestRunner::SUITE_METHODNAME + ); + + if ($method->isStatic()) { + $this->addTest($method->invoke(NULL, $testClass->getName())); + $suiteMethod = TRUE; + } + } + } + + if (!$suiteMethod) { + $this->addTest(new PHPUnit_Framework_TestSuite($testClass)); + } + } + + else { + throw new InvalidArgumentException; + } + } + + /** + * Wraps both addTest() and addTestSuite + * as well as the separate import statements for the user's convenience. + * + * If the named file cannot be read or there are no new tests that can be + * added, a PHPUnit_Framework_Warning will be created instead, + * leaving the current test run untouched. + * + * @param string $filename + * @param boolean $syntaxCheck + * @param array $phptOptions Array with ini settings for the php instance + * run, key being the name if the setting, + * value the ini value. + * @throws InvalidArgumentException + * @access public + * @since Method available since Release 2.3.0 + * @author Stefano F. Rausch + */ + public function addTestFile($filename, $syntaxCheck = TRUE, $phptOptions = array()) + { + if (!is_string($filename)) { + throw new InvalidArgumentException; + } + + if (file_exists($filename) && substr($filename, -5) == '.phpt') { + $this->addTest( + new PHPUnit_Extensions_PhptTestCase($filename, $phptOptions) + ); + + return; + } + + if (!file_exists($filename)) { + $includePaths = explode(PATH_SEPARATOR, get_include_path()); + + foreach ($includePaths as $includePath) { + $file = $includePath . DIRECTORY_SEPARATOR . $filename; + + if (file_exists($file)) { + $filename = $file; + break; + } + } + } + + PHPUnit_Util_Class::collectStart(); + PHPUnit_Util_Fileloader::checkAndLoad($filename, $syntaxCheck); + $newClasses = PHPUnit_Util_Class::collectEnd(); + + $testsFound = FALSE; + + foreach ($newClasses as $className) { + $class = new ReflectionClass($className); + + if (!$class->isAbstract()) { + if ($class->hasMethod(PHPUnit_Runner_BaseTestRunner::SUITE_METHODNAME)) { + $method = $class->getMethod( + PHPUnit_Runner_BaseTestRunner::SUITE_METHODNAME + ); + + if ($method->isStatic()) { + $this->addTest($method->invoke(NULL, $className)); + + $testsFound = TRUE; + } + } + + else if ($class->implementsInterface('PHPUnit_Framework_Test')) { + $this->addTestSuite($class); + + $testsFound = TRUE; + } + } + } + + if (!$testsFound) { + $this->addTest( + new PHPUnit_Framework_Warning( + 'No tests found in file "' . $filename . '".' + ) + ); + } + + $this->numTests = -1; + } + + /** + * Wrapper for addTestFile() that adds multiple test files. + * + * @param array|Iterator $filenames + * @throws InvalidArgumentException + * @access public + * @since Method available since Release 2.3.0 + */ + public function addTestFiles($filenames) + { + if (!(is_array($filenames) || + (is_object($filenames) && $filenames instanceof Iterator))) { + throw new InvalidArgumentException; + } + + foreach ($filenames as $filename) { + $this->addTestFile((string)$filename); + } + } + + /** + * Counts the number of test cases that will be run by this test. + * + * @return integer + * @access public + */ + public function count() + { + if ($this->numTests > -1) { + return $this->numTests; + } + + $this->numTests = 0; + + foreach ($this->tests as $test) { + $this->numTests += count($test); + } + + return $this->numTests; + } + + /** + * @param ReflectionClass $theClass + * @param string $name + * @return PHPUnit_Framework_Test + * @access public + * @static + */ + public static function createTest(ReflectionClass $theClass, $name) + { + $className = $theClass->getName(); + $method = new ReflectionMethod($className, $name); + $docComment = $method->getDocComment(); + + if (!$theClass->isInstantiable()) { + return self::warning( + sprintf('Cannot instantiate class "%s".', $className) + ); + } + + // @expectedException ExceptionClass on TestCase::testMethod() + // @expectedException ExceptionClass message on TestCase::testMethod() + // @expectedException ExceptionClass message code on TestCase::testMethod() + if (preg_match('(@expectedException\s+([:.\w]+)(?:[\t ]+(\S*))?(?:[\t ]+(\S*))?[\t ]*$)m', $docComment, $matches)) { + $expectedException = $matches[1]; + + if (isset($matches[2])) { + $expectedExceptionMessage = trim($matches[2]); + } else { + $expectedExceptionMessage = ''; + } + + if (isset($matches[3])) { + $expectedExceptionCode = (int)$matches[3]; + } else { + $expectedExceptionCode = 0; + } + } + + $constructor = $theClass->getConstructor(); + + if ($constructor !== NULL) { + $parameters = $constructor->getParameters(); + + // TestCase() or TestCase($name) + if (count($parameters) < 2) { + $test = new $className; + } + + // TestCase($name, $data) + else { + $data = PHPUnit_Util_Test::getProvidedData($className, $name); + + if (is_array($data) || $data instanceof Iterator) { + $test = new PHPUnit_Framework_TestSuite( + $className . '::' . $name + ); + + foreach ($data as $_dataName => $_data) { + $_test = new $className($name, $_data, $_dataName); + + if ($_test instanceof PHPUnit_Framework_TestCase && + isset($expectedException)) { + $_test->setExpectedException( + $expectedException, + $expectedExceptionMessage, + $expectedExceptionCode + ); + } + + $test->addTest($_test); + } + } else { + $test = new $className; + } + } + } + + if ($test instanceof PHPUnit_Framework_TestCase) { + $test->setName($name); + + if (isset($expectedException)) { + $test->setExpectedException( + $expectedException, + $expectedExceptionMessage, + $expectedExceptionCode + ); + } + } + + return $test; + } + + /** + * Creates a default TestResult object. + * + * @return PHPUnit_Framework_TestResult + * @access protected + */ + protected function createResult() + { + return new PHPUnit_Framework_TestResult; + } + + /** + * Returns the name of the suite. + * + * @return string + * @access public + */ + public function getName() + { + return $this->name; + } + + /** + * Returns the test groups of the suite. + * + * @return array + * @access public + * @since Method available since Release 3.2.0 + */ + public function getGroups() + { + return array_keys($this->groups); + } + + /** + * Runs the tests and collects their result in a TestResult. + * + * @param PHPUnit_Framework_TestResult $result + * @param mixed $filter + * @param array $groups + * @param array $excludeGroups + * @return PHPUnit_Framework_TestResult + * @throws InvalidArgumentException + * @access public + */ + public function run(PHPUnit_Framework_TestResult $result = NULL, $filter = FALSE, array $groups = array(), array $excludeGroups = array()) + { + if ($result === NULL) { + $result = $this->createResult(); + } + + try { + $this->setUp(); + } + + catch (PHPUnit_Framework_SkippedTestSuiteError $e) { + $numTests = count($this); + + for ($i = 0; $i < $numTests; $i++) { + $result->addFailure($this, $e, 0); + } + + return $result; + } + + $result->startTestSuite($this); + + $tests = array(); + + if (empty($excludeGroups)) { + if (empty($groups)) { + $tests = $this->tests; + } else { + foreach ($groups as $group) { + if (isset($this->groups[$group])) { + $tests = array_merge($tests, $this->groups[$group]); + } + } + } + } else { + foreach ($this->groups as $_group => $_tests) { + if (!in_array($_group, $excludeGroups)) { + $tests = array_merge($tests, $_tests); + } + } + } + + foreach ($tests as $test) { + if ($result->shouldStop()) { + break; + } + + if ($test instanceof PHPUnit_Framework_TestSuite) { + $test->setSharedFixture($this->sharedFixture); + $test->run($result, $filter, $groups, $excludeGroups); + } else { + $runTest = TRUE; + + if ($filter !== FALSE ) { + $name = $test->getName(); + + if ($name !== NULL && preg_match($filter, $name) == 0) { + $runTest = FALSE; + } + } + + if ($runTest) { + if ($test instanceof PHPUnit_Framework_TestCase) { + $test->setSharedFixture($this->sharedFixture); + } + + $this->runTest($test, $result); + } + } + } + + $result->endTestSuite($this); + $this->tearDown(); + + return $result; + } + + /** + * Runs a test. + * + * @param PHPUnit_Framework_Test $test + * @param PHPUnit_Framework_TestResult $testResult + * @access public + */ + public function runTest(PHPUnit_Framework_Test $test, PHPUnit_Framework_TestResult $result) + { + $test->run($result); + } + + /** + * Sets the name of the suite. + * + * @param string + * @access public + */ + public function setName($name) + { + $this->name = $name; + } + + /** + * Returns the test at the given index. + * + * @param integer + * @return PHPUnit_Framework_Test + * @access public + */ + public function testAt($index) + { + if (isset($this->tests[$index])) { + return $this->tests[$index]; + } else { + return FALSE; + } + } + + /** + * Returns the number of tests in this suite. + * + * @return integer + * @access public + */ + public function testCount() + { + return count($this->tests); + } + + /** + * Returns the tests as an enumeration. + * + * @return array + * @access public + */ + public function tests() + { + return $this->tests; + } + + /** + * Mark the test suite as skipped. + * + * @param string $message + * @throws PHPUnit_Framework_SkippedTestSuiteError + * @access public + * @since Method available since Release 3.0.0 + */ + public function markTestSuiteSkipped($message = '') + { + throw new PHPUnit_Framework_SkippedTestSuiteError($message); + } + + /** + * @param ReflectionMethod $method + * @param string $groups + * @param array $names + * @param ReflectionClass $theClass + * @access protected + */ + protected function addTestMethod(ReflectionMethod $method, $groups, Array &$names, ReflectionClass $theClass) + { + $name = $method->getName(); + + if (in_array($name, $names)) { + return; + } + + if ($this->isPublicTestMethod($method)) { + $names[] = $name; + + $this->addTest( + self::createTest( + $theClass, + $name + ), + $groups + ); + } + + else if ($this->isTestMethod($method)) { + $this->addTest( + self::warning( + sprintf( + 'Test method "%s" is not public.', + + $name + ) + ) + ); + } + } + + /** + * @param ReflectionMethod $method + * @return boolean + * @access public + * @static + */ + public static function isPublicTestMethod(ReflectionMethod $method) + { + return (self::isTestMethod($method) && $method->isPublic()); + } + + /** + * @param ReflectionMethod $method + * @return boolean + * @access public + * @static + */ + public static function isTestMethod(ReflectionMethod $method) + { + if (strpos($method->name, 'test') === 0) { + return TRUE; + } + + // @story on TestCase::testMethod() + // @test on TestCase::testMethod() + return strpos($method->getDocComment(), '@test') !== FALSE || + strpos($method->getDocComment(), '@story') !== FALSE; + } + + /** + * @param string $message + * @return PHPUnit_Framework_Warning + * @access protected + */ + protected static function warning($message) + { + return new PHPUnit_Framework_Warning($message); + } + + /** + * Sets the shared fixture for the tests of this test suite. + * + * @param mixed $sharedFixture + * @access public + * @since Method available since Release 3.1.0 + */ + public function setSharedFixture($sharedFixture) + { + $this->sharedFixture = $sharedFixture; + } + + /** + * Returns an iterator for this test suite. + * + * @return RecursiveIteratorIterator + * @access public + * @since Method available since Release 3.1.0 + */ + public function getIterator() + { + return new RecursiveIteratorIterator( + new PHPUnit_Util_TestSuiteIterator($this) + ); + } + + /** + * Template Method that is called before the tests + * of this test suite are run. + * + * @access protected + * @since Method available since Release 3.1.0 + */ + protected function setUp() + { + } + + /** + * Template Method that is called after the tests + * of this test suite have finished running. + * + * @access protected + * @since Method available since Release 3.1.0 + */ + protected function tearDown() + { + } +} + +} +?> Property changes on: test/PHPUnit/Framework/TestSuite.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/Error.php =================================================================== --- test/PHPUnit/Framework/Error.php (revision 0) +++ test/PHPUnit/Framework/Error.php (revision 0) @@ -0,0 +1,88 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: Error.php 1985 2007-12-26 18:11:55Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 2.2.0 + */ + +require_once 'PHPUnit/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +if (!class_exists('PHPUnit_Framework_Error', FALSE)) { + +/** + * Wrapper for PHP errors. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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.2.0 + */ +class PHPUnit_Framework_Error extends Exception +{ + /** + * Constructor. + * + * @param string $message + * @param integer $code + * @param string $file + * @param integer $line + * @param array $trace + * @access public + */ + public function __construct($message, $code, $file, $line, $trace) + { + parent::__construct($message, $code); + + $this->file = $file; + $this->line = $line; + $this->trace = $trace; + } +} + +} +?> Property changes on: test/PHPUnit/Framework/Error.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/MockObject/Invocation.php =================================================================== --- test/PHPUnit/Framework/MockObject/Invocation.php (revision 0) +++ test/PHPUnit/Framework/MockObject/Invocation.php (revision 0) @@ -0,0 +1,138 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: Invocation.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'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Encapsulates information on a method invocation which can be passed to matchers. + * + * The invocation consists of the object it occured from, the class name, the + * method name and all the parameters. The mock object must instantiate this + * class with the values from the mocked method and pass it to an object of + * PHPUnit_Framework_MockObject_Invokable. + * + * @category Testing + * @package PHPUnit + * @author Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class PHPUnit_Framework_MockObject_Invocation implements PHPUnit_Framework_SelfDescribing +{ + public $object; + + public $className; + + public $methodName; + + public $parameters; + + public function __construct($object, $className, $methodName, $parameters) + { + $this->object = $object; + $this->className = $className; + $this->methodName = $methodName; + $this->parameters = $parameters; + + foreach ($this->parameters as $key => $value) { + if (is_object($value)) { + $this->parameters[$key] = $this->cloneObject($value); + } + } + } + + public function toString() + { + return sprintf( + "%s::%s(%s)", + + $this->className, + $this->methodName, + join( + ', ', + array_map( + create_function( + '$a', + 'return PHPUnit_Util_Type::shortenedExport($a);' + ), + $this->parameters + ) + ) + ); + } + + protected function cloneObject($original) + { + $object = new ReflectionObject($original); + + if ($object->hasMethod('__clone')) { + $method = $object->getMethod('__clone'); + + if (!$method->isPublic()) { + return $original; + } + + try { + return clone $original; + } + + catch (Exception $e) { + return $original; + } + } + + return clone $original; + } +} +?> Property changes on: test/PHPUnit/Framework/MockObject/Invocation.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/MockObject/Mock.php =================================================================== --- test/PHPUnit/Framework/MockObject/Mock.php (revision 0) +++ test/PHPUnit/Framework/MockObject/Mock.php (revision 0) @@ -0,0 +1,428 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: Mock.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/Util/Class.php'; +require_once 'PHPUnit/Util/Filter.php'; +require_once 'PHPUnit/Framework/MockObject/Matcher.php'; +require_once 'PHPUnit/Framework/MockObject/Invocation.php'; +require_once 'PHPUnit/Framework/MockObject/MockObject.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Provides generation of mock classes and objects from existing classes. + * + * The mocked class will contain all the methods of the original class but with + * a different implementation which will call the current + * PHPUnit_Framework_MockObject_InvocationMocker object, this objects takes + * care of checking expectations and stubs. + * It is also possible to define which methods are mocked by passing an array + * of method names. + * + * The simplest way to define a mock object is to do: + * + * + * PHPUnit_Framework_MockObject_Mock::generate('MyClass'); + * $o = new Mock_MyClass; + * + * + * The generate() method returns an object which can be queried. + * + * + * $m = PHPUnit_Framework_MockObject::generate('MyClass'); + * $o = new $m->mockClassName; + * print "original class was: . $m->className; + * + * + * @category Testing + * @package PHPUnit + * @author Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class PHPUnit_Framework_MockObject_Mock +{ + public $mockClassName; + public $className; + public $fullClassName; + public $namespaceName; + public $methods; + protected $callOriginalConstructor; + protected $callOriginalClone; + protected $callAutoload; + + public function __construct($className, array $methods = array(), $mockClassName = '', $callOriginalConstructor = TRUE, $callOriginalClone = TRUE, $callAutoload = TRUE) + { + $classNameParts = explode('::', $className); + + if (count($classNameParts) > 1) { + $className = array_pop($classNameParts); + $namespaceName = join('::', $classNameParts); + $this->fullClassName = $namespaceName . '::' . $className; + } else { + $namespaceName = ''; + $this->fullClassName = $className; + } + + if ($mockClassName === '') { + do { + $mockClassName = 'Mock_' . $className . '_' . substr(md5(microtime()), 0, 8); + } + while (class_exists($mockClassName, FALSE)); + } + + else if (class_exists($mockClassName, FALSE)) { + throw new RuntimeException( + sprintf( + 'Class "%s" already exists.', + $mockClassName + ) + ); + } + + $isClass = class_exists($className, $callAutoload); + $isInterface = interface_exists($className, $callAutoload); + + if (empty($methods) && ($isClass || $isInterface)) { + $methods = get_class_methods($className); + } + + if ($isInterface) { + $callOriginalConstructor = FALSE; + } + + $this->mockClassName = $mockClassName; + $this->className = $className; + $this->namespaceName = $namespaceName; + $this->methods = $methods; + $this->callOriginalConstructor = $callOriginalConstructor; + $this->callOriginalClone = $callOriginalClone; + $this->callAutoload = $callAutoload; + } + + public static function generate($className, array $methods = array(), $mockClassName = '', $callOriginalConstructor = TRUE, $callOriginalClone = TRUE, $callAutoload = TRUE) + { + $mock = new PHPUnit_Framework_MockObject_Mock( + $className, + $methods, + $mockClassName, + $callOriginalConstructor, + $callOriginalClone, + $callAutoload + ); + + $mock->generateClass(); + + return $mock; + } + + protected function generateClass() + { + if (!class_exists($this->fullClassName, $this->callAutoload) && !interface_exists($this->fullClassName, $this->callAutoload)) { + $code = 'class ' . $this->className . ' {}'; + + if (!empty($this->namespaceName)) { + $code = 'namespace ' . $this->namespaceName . ';' . $code; + } + + eval($code); + } + + try { + $class = new ReflectionClass($this->fullClassName); + + if ($class->isFinal()) { + throw new RuntimeException( + sprintf( + 'Class "%s" is declared "final" and cannot be mocked.', + $this->fullClassName + ) + ); + } + + $code = $this->generateClassDefinition($class); + + eval($code); + } + + catch (Exception $e) { + throw new RuntimeException( + sprintf( + 'Failed to generate mock class "%s" for class "%s".\n%s', + $this->mockClassName, + $this->fullClassName, + $e->getMessage() + ) + ); + } + } + + protected function generateClassDefinition(ReflectionClass $class) + { + $code = 'class '; + + if ($class->isInterface()) { + $code .= sprintf( + "%s implements %s%s, PHPUnit_Framework_MockObject_MockObject {\n", + $this->mockClassName, + !empty($this->namespaceName) ? $this->namespaceName . '::' : '', + $this->className + ); + } else { + $code .= sprintf( + "%s extends %s%s implements PHPUnit_Framework_MockObject_MockObject {\n", + $this->mockClassName, + !empty($this->namespaceName) ? $this->namespaceName . '::' : '', + $this->className + ); + } + + $code .= $this->generateMockApi($class); + + foreach ($this->methods as $methodName) { + try { + $method = $class->getMethod($methodName); + + if ($this->canMockMethod($method)) { + $code .= $this->generateMethodDefinitionFromExisting($method); + } + } + + catch (ReflectionException $e) { + $code .= $this->generateMethodDefinition($class->getName(), $methodName, 'public'); + } + } + + $code .= "}\n"; + + return $code; + } + + protected function canMockMethod(ReflectionMethod $method) + { + $className = $method->getDeclaringClass()->getName(); + $methodName = $method->getName(); + + if ($method->isFinal() || + $methodName == '__construct' || $methodName == $className || + $methodName == '__destruct' || $method->getName() == '__clone') { + return FALSE; + } + + return TRUE; + } + + protected function generateMethodDefinitionFromExisting(ReflectionMethod $method) + { + if ($method->isPrivate()) { + $modifier = 'private'; + } + + else if ($method->isProtected()) { + $modifier = 'protected'; + } + + else { + $modifier = 'public'; + } + + if ($method->isStatic()) { + $modifier .= ' static'; + } + + if ($method->returnsReference()) { + $reference = '&'; + } else { + $reference = ''; + } + + return $this->generateMethodDefinition( + $method->getDeclaringClass()->getName(), + $method->getName(), + $modifier, + $reference, + PHPUnit_Util_Class::getMethodParameters($method) + ); + } + + protected function generateMethodDefinition($className, $methodName, $modifier, $reference = '', $parameters = '') + { + return sprintf( + "\n %s function %s%s(%s) {\n" . + " \$args = func_get_args();\n" . + " \$result = \$this->invocationMocker->invoke(\n" . + " new PHPUnit_Framework_MockObject_Invocation(\$this, \"%s\", \"%s\", \$args)\n" . + " );\n\n" . + " return \$result;\n" . + " }\n", + + $modifier, + $reference, + $methodName, + $parameters, + $className, + $methodName + ); + } + + protected function generateMockApi(ReflectionClass $class) + { + if ($this->callOriginalConstructor) { + $constructorCode = $this->generateConstructorCodeWithParentCall($class); + } else { + $constructorCode = $this->generateConstructorCode($class); + } + + if ($this->callOriginalClone && $class->hasMethod('__clone')) { + $cloneCode = $this->generateCloneCodeWithParentCall(); + } else { + $cloneCode = $this->generateCloneCode(); + } + + return sprintf( + " private \$invocationMocker;\n\n" . + "%s" . + "%s" . + " public function getInvocationMocker() {\n" . + " return \$this->invocationMocker;\n" . + " }\n\n" . + " public function expects(PHPUnit_Framework_MockObject_Matcher_Invocation \$matcher) {\n" . + " return \$this->invocationMocker->expects(\$matcher);\n" . + " }\n\n" . + " public function verify() {\n" . + " \$this->invocationMocker->verify();\n" . + " }\n", + + $constructorCode, + $cloneCode + ); + } + + protected function generateConstructorCode(ReflectionClass $class) + { + if (!$this->callOriginalConstructor) { + return " public function __construct() {\n" . + " \$this->invocationMocker = new PHPUnit_Framework_MockObject_InvocationMocker(\$this);\n" . + " }\n\n"; + } + + $className = $class->getName(); + $constructor = FALSE; + + if ($class->hasMethod('__construct')) { + $constructor = $class->getMethod('__construct'); + } + + else if ($class->hasMethod($className)) { + $constructor = $class->getMethod($className); + } + + return sprintf( + " public function __construct(%s) {\n" . + " \$this->invocationMocker = new PHPUnit_Framework_MockObject_InvocationMocker(\$this);\n" . + " }\n\n", + + $constructor !== FALSE ? PHPUnit_Util_Class::getMethodParameters($constructor) : '' + ); + } + + protected function generateConstructorCodeWithParentCall(ReflectionClass $class) + { + $constructor = $this->getConstructor($class); + + if ($constructor) { + return sprintf( + " public function __construct(%s) {\n" . + " \$args = func_get_args();\n" . + " \$this->invocationMocker = new PHPUnit_Framework_MockObject_InvocationMocker;\n" . + " \$class = new ReflectionClass(\$this);\n" . + " \$class->getParentClass()->getConstructor()->invokeArgs(\$this, \$args);\n" . + " }\n\n", + + PHPUnit_Util_Class::getMethodParameters($constructor) + ); + } else { + return $this->generateConstructorCode($class); + } + } + + protected function generateCloneCode() + { + return " public function __clone() {\n" . + " \$this->invocationMocker = clone \$this->invocationMocker;\n" . + " }\n\n"; + } + + protected function generateCloneCodeWithParentCall() + { + return " public function __clone() {\n" . + " \$this->invocationMocker = clone \$this->invocationMocker;\n" . + " parent::__clone();\n" . + " }\n\n"; + } + + protected function getConstructor(ReflectionClass $class) + { + $className = $class->getName(); + $constructor = NULL; + + if ($class->hasMethod('__construct')) { + $constructor = $class->getMethod('__construct'); + } + + else if ($class->hasMethod($className)) { + $constructor = $class->getMethod($className); + } + + return $constructor; + } +} +?> Property changes on: test/PHPUnit/Framework/MockObject/Mock.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/MockObject/InvocationMocker.php =================================================================== --- test/PHPUnit/Framework/MockObject/InvocationMocker.php (revision 0) +++ test/PHPUnit/Framework/MockObject/InvocationMocker.php (revision 0) @@ -0,0 +1,154 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: InvocationMocker.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/Util/Filter.php'; +require_once 'PHPUnit/Framework/MockObject/Builder/InvocationMocker.php'; +require_once 'PHPUnit/Framework/MockObject/Builder/Match.php'; +require_once 'PHPUnit/Framework/MockObject/Builder/Namespace.php'; +require_once 'PHPUnit/Framework/MockObject/Matcher.php'; +require_once 'PHPUnit/Framework/MockObject/Stub.php'; +require_once 'PHPUnit/Framework/MockObject/Invocation.php'; +require_once 'PHPUnit/Framework/MockObject/Invokable.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Mocker for invocations which are sent from + * PHPUnit_Framework_MockObject_MockObject objects. + * + * Keeps track of all expectations and stubs as well as registering + * identifications for builders. + * + * @category Testing + * @package PHPUnit + * @author Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class PHPUnit_Framework_MockObject_InvocationMocker implements PHPUnit_Framework_MockObject_Stub_MatcherCollection, PHPUnit_Framework_MockObject_Invokable, PHPUnit_Framework_MockObject_Builder_Namespace +{ + protected $matchers = array(); + + protected $builderMap = array(); + + public function addMatcher(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher) + { + $this->matchers[] = $matcher; + } + + public function lookupId($id) + { + if (isset($this->builderMap[$id])) { + return $this->builderMap[$id]; + } + + return NULL; + } + + public function registerId($id, PHPUnit_Framework_MockObject_Builder_Match $builder) + { + if (isset($this->builderMap[$id])) { + throw new RuntimeException("Match builder with id <{$id}> is already registered."); + } + + $this->builderMap[$id] = $builder; + } + + public function expects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher) + { + $builder = new PHPUnit_Framework_MockObject_Builder_InvocationMocker($this, $matcher); + + return $builder; + } + + public function invoke(PHPUnit_Framework_MockObject_Invocation $invocation) + { + $hasReturnValue = FALSE; + + if (strtolower($invocation->methodName) == '__tostring') { + $returnValue = ''; + } else { + $returnValue = NULL; + } + + foreach($this->matchers as $match) { + if ($match->matches($invocation)) { + $value = $match->invoked($invocation); + + if (!$hasReturnValue) { + $returnValue = $value; + $hasReturnValue = TRUE; + } + } + } + + return $returnValue; + } + + public function matches(PHPUnit_Framework_MockObject_Invocation $invocation) + { + foreach($this->matchers as $matcher) { + if (!$matcher->matches($invocation)) { + return FALSE; + } + } + + return TRUE; + } + + public function verify() + { + foreach($this->matchers as $matcher) { + $matcher->verify(); + } + } +} +?> Property changes on: test/PHPUnit/Framework/MockObject/InvocationMocker.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/MockObject/Invokable.php =================================================================== --- test/PHPUnit/Framework/MockObject/Invokable.php (revision 0) +++ test/PHPUnit/Framework/MockObject/Invokable.php (revision 0) @@ -0,0 +1,91 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: Invokable.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/Util/Filter.php'; +require_once 'PHPUnit/Framework/MockObject/Invocation.php'; +require_once 'PHPUnit/Framework/MockObject/Verifiable.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Interface for classes which can be invoked. + * + * The invocation will be taken from a mock object and passed to an object + * of this class. + * + * @category Testing + * @package PHPUnit + * @author Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: 3.2.9 + * @link http://www.phpunit.de/ + * @since Interface available since Release 3.0.0 + */ +interface PHPUnit_Framework_MockObject_Invokable extends PHPUnit_Framework_MockObject_Verifiable +{ + /** + * Invokes the invocation object $invocation so that it can be checked for + * expectations or matched against stubs. + * + * @return Object + * @param PHPUnit_Framework_MockObject_Invocation $invocation The invocation object passed from + * mock object. + */ + public function invoke(PHPUnit_Framework_MockObject_Invocation $invocation); + + /** + * Checks if the invocation matches. + * + * @return bool + * @param PHPUnit_Framework_MockObject_Invocation $invocation The invocation object passed from + * mock object. + */ + public function matches(PHPUnit_Framework_MockObject_Invocation $invocation); +} +?> Property changes on: test/PHPUnit/Framework/MockObject/Invokable.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/MockObject/Matcher/Invocation.php =================================================================== --- test/PHPUnit/Framework/MockObject/Matcher/Invocation.php (revision 0) +++ test/PHPUnit/Framework/MockObject/Matcher/Invocation.php (revision 0) @@ -0,0 +1,99 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: Invocation.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/Framework/MockObject/Invocation.php'; +require_once 'PHPUnit/Framework/MockObject/Verifiable.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Interface for classes which matches an invocation based on its + * method name, argument, order or call count. + * + * @category Testing + * @package PHPUnit + * @author Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: 3.2.9 + * @link http://www.phpunit.de/ + * @since Interface available since Release 3.0.0 + */ +interface PHPUnit_Framework_MockObject_Matcher_Invocation extends PHPUnit_Framework_SelfDescribing, PHPUnit_Framework_MockObject_Verifiable +{ + /** + * Registers the invocation $invocation in the object as being invoked. + * This will only occur after matches() returns true which means the + * current invocation is the correct one. + * + * The matcher can store information from the invocation which can later + * be checked in verify(), or it can check the values directly and throw + * and exception if an expectation is not met. + * + * If the matcher is a stub it will also have a return value. + * + * @param PHPUnit_Framework_MockObject_Invocation Object containing information on a mocked or + * stubbed method which was invoked. + * @return mixed + */ + public function invoked(PHPUnit_Framework_MockObject_Invocation $invocation); + + /** + * Checks if the invocation $invocation matches the current rules. If it does + * the matcher will get the invoked() method called which should check if an + * expectation is met. + * + * @param PHPUnit_Framework_MockObject_Invocation Object containing information on a mocked or + * stubbed method which was invoked. + * @return bool + */ + public function matches(PHPUnit_Framework_MockObject_Invocation $invocation); +} +?> Property changes on: test/PHPUnit/Framework/MockObject/Matcher/Invocation.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/MockObject/Matcher/AnyParameters.php =================================================================== --- test/PHPUnit/Framework/MockObject/Matcher/AnyParameters.php (revision 0) +++ test/PHPUnit/Framework/MockObject/Matcher/AnyParameters.php (revision 0) @@ -0,0 +1,79 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: AnyParameters.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/Util/Filter.php'; +require_once 'PHPUnit/Framework/MockObject/Matcher/StatelessInvocation.php'; +require_once 'PHPUnit/Framework/MockObject/Invocation.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Invocation matcher which allos any parameters to a method. + * + * @category Testing + * @package PHPUnit + * @author Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class PHPUnit_Framework_MockObject_Matcher_AnyParameters extends PHPUnit_Framework_MockObject_Matcher_StatelessInvocation +{ + public function toString() + { + return 'with any parameters'; + } + + public function matches(PHPUnit_Framework_MockObject_Invocation $invocation) + { + return TRUE; + } +} +?> Property changes on: test/PHPUnit/Framework/MockObject/Matcher/AnyParameters.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/MockObject/Matcher/InvokedAtIndex.php =================================================================== --- test/PHPUnit/Framework/MockObject/Matcher/InvokedAtIndex.php (revision 0) +++ test/PHPUnit/Framework/MockObject/Matcher/InvokedAtIndex.php (revision 0) @@ -0,0 +1,115 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: InvokedAtIndex.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/Framework/MockObject/Matcher/Invocation.php'; +require_once 'PHPUnit/Framework/MockObject/Invocation.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Invocation matcher which checks if a method was invoked at a certain index. + * + * If the expected index number does not match the current invocation index it + * will not match which means it skips all method and parameter matching. Only + * once the index is reached will the method and parameter start matching and + * verifying. + * + * If the index is never reached it will throw an exception in index. + * + * @category Testing + * @package PHPUnit + * @author Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class PHPUnit_Framework_MockObject_Matcher_InvokedAtIndex implements PHPUnit_Framework_MockObject_Matcher_Invocation +{ + protected $sequenceIndex; + + protected $currentIndex = -1; + + public function __construct($sequenceIndex) + { + $this->sequenceIndex = $sequenceIndex; + } + + public function toString() + { + return 'invoked at sequence index ' . $this->sequenceIndex; + } + + public function matches(PHPUnit_Framework_MockObject_Invocation $invocation) + { + $this->currentIndex++; + + return $this->currentIndex == $this->sequenceIndex; + } + + public function invoked(PHPUnit_Framework_MockObject_Invocation $invocation) + { + } + + public function verify() + { + if ($this->currentIndex < $this->sequenceIndex) { + throw new PHPUnit_Framework_ExpectationFailedException( + sprintf( + 'The expected invocation at index %s was never reached.', + + $this->sequenceIndex + ) + ); + } + } +} +?> Property changes on: test/PHPUnit/Framework/MockObject/Matcher/InvokedAtIndex.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/MockObject/Matcher/AnyInvokedCount.php =================================================================== --- test/PHPUnit/Framework/MockObject/Matcher/AnyInvokedCount.php (revision 0) +++ test/PHPUnit/Framework/MockObject/Matcher/AnyInvokedCount.php (revision 0) @@ -0,0 +1,79 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: AnyInvokedCount.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/Framework/MockObject/Matcher/InvokedRecorder.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Invocation matcher which checks if a method has been invoked zero or more + * times. This matcher will always match. + * + * @category Testing + * @package PHPUnit + * @author Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class PHPUnit_Framework_MockObject_Matcher_AnyInvokedCount extends PHPUnit_Framework_MockObject_Matcher_InvokedRecorder +{ + public function toString() + { + return 'invoked zero or more times'; + } + + public function verify() + { + } +} +?> Property changes on: test/PHPUnit/Framework/MockObject/Matcher/AnyInvokedCount.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/MockObject/Matcher/MethodName.php =================================================================== --- test/PHPUnit/Framework/MockObject/Matcher/MethodName.php (revision 0) +++ test/PHPUnit/Framework/MockObject/Matcher/MethodName.php (revision 0) @@ -0,0 +1,95 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: MethodName.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/Framework/MockObject/Matcher/StatelessInvocation.php'; +require_once 'PHPUnit/Framework/MockObject/Invocation.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Invocation matcher which looks for a specific method name in the invocations. + * + * Checks the method name all incoming invocations, the name is checked against + * the defined constraint $constraint. If the constraint is met it will return + * true in matches(). + * + * @category Testing + * @package PHPUnit + * @author Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class PHPUnit_Framework_MockObject_Matcher_MethodName extends PHPUnit_Framework_MockObject_Matcher_StatelessInvocation +{ + protected $constraint; + + public function __construct($constraint) + { + if (!($constraint instanceof PHPUnit_Framework_Constraint)) { + $constraint = new PHPUnit_Framework_Constraint_IsEqual($constraint); + } + + $this->constraint = $constraint; + } + + public function toString() + { + return 'method name ' . $this->constraint->toString(); + } + + public function matches(PHPUnit_Framework_MockObject_Invocation $invocation) + { + return $this->constraint->evaluate($invocation->methodName); + } +} +?> Property changes on: test/PHPUnit/Framework/MockObject/Matcher/MethodName.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/MockObject/Matcher/StatelessInvocation.php =================================================================== --- test/PHPUnit/Framework/MockObject/Matcher/StatelessInvocation.php (revision 0) +++ test/PHPUnit/Framework/MockObject/Matcher/StatelessInvocation.php (revision 0) @@ -0,0 +1,81 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: StatelessInvocation.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/Util/Filter.php'; +require_once 'PHPUnit/Framework/MockObject/Matcher/Invocation.php'; +require_once 'PHPUnit/Framework/MockObject/Invocation.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Invocation matcher which does not care about previous state from earlier invocations. + * + * This abstract class can be implemented by matchers which does not care about + * state but only the current run-time value of the invocation itself. + * + * @category Testing + * @package PHPUnit + * @author Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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_Framework_MockObject_Matcher_StatelessInvocation implements PHPUnit_Framework_MockObject_Matcher_Invocation +{ + public function invoked(PHPUnit_Framework_MockObject_Invocation $invocation) + { + } + + public function verify() + { + } +} +?> Property changes on: test/PHPUnit/Framework/MockObject/Matcher/StatelessInvocation.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/MockObject/Matcher/InvokedAtLeastOnce.php =================================================================== --- test/PHPUnit/Framework/MockObject/Matcher/InvokedAtLeastOnce.php (revision 0) +++ test/PHPUnit/Framework/MockObject/Matcher/InvokedAtLeastOnce.php (revision 0) @@ -0,0 +1,87 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: InvokedAtLeastOnce.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/Framework/MockObject/Matcher/InvokedRecorder.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Invocation matcher which checks if a method has been invoked at least one time. + * + * If the number of invocations is 0 it will throw an exception in verify. + * + * @category Testing + * @package PHPUnit + * @author Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class PHPUnit_Framework_MockObject_Matcher_InvokedAtLeastOnce extends PHPUnit_Framework_MockObject_Matcher_InvokedRecorder +{ + public function toString() + { + return 'invoked at least once'; + } + + public function verify() + { + $count = $this->getInvocationCount(); + + if ($count < 1) { + throw new PHPUnit_Framework_ExpectationFailedException( + 'Expected invocation at least once but it never occured.' + ); + } + } +} +?> Property changes on: test/PHPUnit/Framework/MockObject/Matcher/InvokedAtLeastOnce.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/MockObject/Matcher/Parameters.php =================================================================== --- test/PHPUnit/Framework/MockObject/Matcher/Parameters.php (revision 0) +++ test/PHPUnit/Framework/MockObject/Matcher/Parameters.php (revision 0) @@ -0,0 +1,145 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: Parameters.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/Framework/MockObject/Matcher/StatelessInvocation.php'; +require_once 'PHPUnit/Framework/MockObject/Invocation.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Invocation matcher which looks for specific parameters in the invocations. + * + * Checks the parameters of all incoming invocations, the parameter list is + * checked against the defined constraints in $parameters. If the constraint + * is met it will return true in matches(). + * + * @category Testing + * @package PHPUnit + * @author Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class PHPUnit_Framework_MockObject_Matcher_Parameters extends PHPUnit_Framework_MockObject_Matcher_StatelessInvocation +{ + protected $parameters = array(); + + protected $invocation; + + public function __construct($parameters) + { + foreach($parameters as $parameter) { + if (!($parameter instanceof PHPUnit_Framework_Constraint)) { + $parameter = new PHPUnit_Framework_Constraint_IsEqual($parameter); + } + + $this->parameters[] = $parameter; + } + } + + public function toString() + { + $text = 'with parameter'; + + foreach($this->parameters as $index => $parameter) { + if ($index > 0) { + $text .= ' and'; + } + + $text .= ' ' . $index . ' ' . $parameter->toString(); + } + + return $text; + } + + public function matches(PHPUnit_Framework_MockObject_Invocation $invocation) + { + $this->invocation = $invocation; + $this->verify(); + + return count($invocation->parameters) < count($this->parameters); + } + + public function verify() + { + if ($this->invocation === NULL) { + throw new PHPUnit_Framework_ExpectationFailedException( + 'Mocked method does not exist.' + ); + } + + if (count($this->invocation->parameters) < count($this->parameters)) { + throw new PHPUnit_Framework_ExpectationFailedException( + sprintf( + 'Parameter count for invocation %s is too low.', + + $this->invocation->toString() + ) + ); + } + + foreach ($this->parameters as $i => $parameter) { + if (!$parameter->evaluate($this->invocation->parameters[$i])) { + $parameter->fail( + $this->invocation->parameters[$i], + sprintf( + 'Parameter %s for invocation %s does not match expected value.', + + $i, + $this->invocation->toString() + ) + ); + } + } + } +} +?> Property changes on: test/PHPUnit/Framework/MockObject/Matcher/Parameters.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/MockObject/Matcher/InvokedRecorder.php =================================================================== --- test/PHPUnit/Framework/MockObject/Matcher/InvokedRecorder.php (revision 0) +++ test/PHPUnit/Framework/MockObject/Matcher/InvokedRecorder.php (revision 0) @@ -0,0 +1,100 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: InvokedRecorder.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/Util/Filter.php'; +require_once 'PHPUnit/Framework/MockObject/Matcher/Invocation.php'; +require_once 'PHPUnit/Framework/MockObject/Invocation.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Records invocations and provides convenience methods for checking them later on. + * + * This abstract class can be implemented by matchers which needs to check the + * number of times an invocation has occured. + * + * @category Testing + * @package PHPUnit + * @author Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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_Framework_MockObject_Matcher_InvokedRecorder implements PHPUnit_Framework_MockObject_Matcher_Invocation +{ + protected $invocations = array(); + + public function getInvocationCount() + { + return count($this->invocations); + } + + public function getInvocations() + { + return $this->invocations; + } + + public function hasBeenInvoked() + { + return count($this->invocations) > 0; + } + + public function invoked(PHPUnit_Framework_MockObject_Invocation $invocation) + { + $this->invocations[] = $invocation; + } + + public function matches(PHPUnit_Framework_MockObject_Invocation $invocation) + { + return TRUE; + } +} +?> Property changes on: test/PHPUnit/Framework/MockObject/Matcher/InvokedRecorder.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/MockObject/Matcher/InvokedCount.php =================================================================== --- test/PHPUnit/Framework/MockObject/Matcher/InvokedCount.php (revision 0) +++ test/PHPUnit/Framework/MockObject/Matcher/InvokedCount.php (revision 0) @@ -0,0 +1,134 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: InvokedCount.php 2095 2008-01-14 17:14:34Z 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/Framework/MockObject/Matcher/InvokedRecorder.php'; +require_once 'PHPUnit/Framework/MockObject/Invocation.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Invocation matcher which checks if a method has been invoked a certain amount of times. + * + * If the number of invocations exceeds the value it will immediately throw an exception, + * If the number is less it will later be checked in verify() and also throw an exception. + * + * @category Testing + * @package PHPUnit + * @author Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class PHPUnit_Framework_MockObject_Matcher_InvokedCount extends PHPUnit_Framework_MockObject_Matcher_InvokedRecorder +{ + protected $expectedCount; + + public function __construct($expectedCount) + { + $this->expectedCount = $expectedCount; + } + + public function toString() + { + return 'invoked ' . $this->expectedCount . ' time(s)'; + } + + public function invoked(PHPUnit_Framework_MockObject_Invocation $invocation) + { + parent::invoked($invocation); + + $count = $this->getInvocationCount(); + + if ($count > $this->expectedCount) { + $message = (string)$invocation; + + switch ($this->expectedCount == 0) { + case 0: { + $message .= ' was not expected to be called.'; + } + break; + + case 1: { + $message .= ' was not expected to be called more than once.'; + } + break; + + default: { + $message .= sprintf( + ' was not expected to be called more than %d times.', + + $this->expectedCount + ); + } + } + + throw new PHPUnit_Framework_ExpectationFailedException($message); + } + } + + public function verify() + { + $count = $this->getInvocationCount(); + + if ($count !== $this->expectedCount) { + throw new PHPUnit_Framework_ExpectationFailedException( + sprintf( + 'Method was expected to be called %d times, actually called %d times.', + + $this->expectedCount, + $count + ) + ); + } + } +} +?> Property changes on: test/PHPUnit/Framework/MockObject/Matcher/InvokedCount.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/MockObject/Stub.php =================================================================== --- test/PHPUnit/Framework/MockObject/Stub.php (revision 0) +++ test/PHPUnit/Framework/MockObject/Stub.php (revision 0) @@ -0,0 +1,88 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: Stub.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/Framework/MockObject/Invocation.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * An object that stubs the process of a normal method for a mock object. + * + * The stub object will replace the code for the stubbed method and return a + * specific value instead of the original value. + * + * @category Testing + * @package PHPUnit + * @author Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: 3.2.9 + * @link http://www.phpunit.de/ + * @since Interface available since Release 3.0.0 + */ +interface PHPUnit_Framework_MockObject_Stub extends PHPUnit_Framework_SelfDescribing +{ + /** + * Fakes the processesing of the invocation $invocation by returning a + * specific value. + * + * @return mixed + * @param PHPUnit_Framework_MockObject_Invocation $invocation The invocation which was mocked + * and matched by the current method + * and argument matchers. + */ + public function invoke(PHPUnit_Framework_MockObject_Invocation $invocation); +} + +require_once 'PHPUnit/Framework/MockObject/Stub/ConsecutiveCalls.php'; +require_once 'PHPUnit/Framework/MockObject/Stub/Exception.php'; +require_once 'PHPUnit/Framework/MockObject/Stub/MatcherCollection.php'; +require_once 'PHPUnit/Framework/MockObject/Stub/Return.php'; +?> Property changes on: test/PHPUnit/Framework/MockObject/Stub.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/MockObject/Builder/Identity.php =================================================================== --- test/PHPUnit/Framework/MockObject/Builder/Identity.php (revision 0) +++ test/PHPUnit/Framework/MockObject/Builder/Identity.php (revision 0) @@ -0,0 +1,80 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: Identity.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/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Builder interface for unique identifiers. + * + * Defines the interface for recording unique identifiers. The identifiers + * can be used to define the invocation order of expectations. The expectation + * is recorded using id() and then defined in order using + * PHPUnit_Framework_MockObject_Builder_Match::after(). + * + * @category Testing + * @package PHPUnit + * @author Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: 3.2.9 + * @link http://www.phpunit.de/ + * @since Interface available since Release 3.0.0 + */ +interface PHPUnit_Framework_MockObject_Builder_Identity +{ + /** + * Sets the identification of the expectation to $id. + * + * @note The identifier is unique per mock object. + * @param string $id Unique identifiation of expectation. + */ + public function id($id); +} +?> Property changes on: test/PHPUnit/Framework/MockObject/Builder/Identity.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/MockObject/Builder/InvocationMocker.php =================================================================== --- test/PHPUnit/Framework/MockObject/Builder/InvocationMocker.php (revision 0) +++ test/PHPUnit/Framework/MockObject/Builder/InvocationMocker.php (revision 0) @@ -0,0 +1,156 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: InvocationMocker.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/Util/Filter.php'; +require_once 'PHPUnit/Framework/MockObject/Builder/MethodNameMatch.php'; +require_once 'PHPUnit/Framework/MockObject/Matcher.php'; +require_once 'PHPUnit/Framework/MockObject/Stub.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Builder for mocked or stubbed invocations. + * + * Provides methods for building expectations without having to resort to + * instantiating the various matchers manually. These methods also form a + * more natural way of reading the expectation. This class should be together + * with the test case PHPUnit_Framework_MockObject_TestCase. + * + * @category Testing + * @package PHPUnit + * @author Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class PHPUnit_Framework_MockObject_Builder_InvocationMocker implements PHPUnit_Framework_MockObject_Builder_MethodNameMatch +{ + protected $collection; + + protected $matcher; + + public function __construct(PHPUnit_Framework_MockObject_Stub_MatcherCollection $collection, PHPUnit_Framework_MockObject_Matcher_Invocation $invocationMatcher) + { + $this->collection = $collection; + $this->matcher = new PHPUnit_Framework_MockObject_Matcher($invocationMatcher); + + $this->collection->addMatcher($this->matcher); + } + + public function getMatcher() + { + return $this->matcher; + } + + public function id($id) + { + $this->collection->registerId($id, $this); + + return $this; + } + + public function will(PHPUnit_Framework_MockObject_Stub $stub) + { + $this->matcher->stub = $stub; + + return $this; + } + + public function after($id) + { + $this->matcher->afterMatchBuilderId = $id; + + return $this; + } + + public function with() + { + $args = func_get_args(); + + if ($this->matcher->methodNameMatcher === NULL) { + throw new RuntimeException('Method name matcher is not defined, cannot define parameter matcher without one'); + } + + if ( $this->matcher->parametersMatcher !== NULL) { + throw new RuntimeException('Parameter matcher is already defined, cannot redefine'); + } + + $this->matcher->parametersMatcher = new PHPUnit_Framework_MockObject_Matcher_Parameters($args); + + return $this; + } + + public function withAnyParameters() + { + if ($this->matcher->methodNameMatcher === NULL) { + throw new RuntimeException('Method name matcher is not defined, cannot define parameter matcher without one'); + } + + if ($this->matcher->parametersMatcher !== NULL) { + throw new RuntimeException('Parameter matcher is already defined, cannot redefine'); + } + + $this->matcher->parametersMatcher = new PHPUnit_Framework_MockObject_Matcher_AnyParameters(); + + return $this; + } + + public function method($constraint) + { + if ($this->matcher->methodNameMatcher !== NULL) { + throw new RuntimeException('Method name matcher is already defined, cannot redefine'); + } + + $this->matcher->methodNameMatcher = new PHPUnit_Framework_MockObject_Matcher_MethodName($constraint); + + return $this; + } +} +?> Property changes on: test/PHPUnit/Framework/MockObject/Builder/InvocationMocker.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/MockObject/Builder/Match.php =================================================================== --- test/PHPUnit/Framework/MockObject/Builder/Match.php (revision 0) +++ test/PHPUnit/Framework/MockObject/Builder/Match.php (revision 0) @@ -0,0 +1,77 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: Match.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/Util/Filter.php'; +require_once 'PHPUnit/Framework/MockObject/Builder/Stub.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Builder interface for invocation order matches. + * + * @category Testing + * @package PHPUnit + * @author Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: 3.2.9 + * @link http://www.phpunit.de/ + * @since Interface available since Release 3.0.0 + */ +interface PHPUnit_Framework_MockObject_Builder_Match extends PHPUnit_Framework_MockObject_Builder_Stub +{ + /** + * Defines the expectation which must occur before the current is valid. + * + * @param string $id The identification of the expectation that should + * occur before this one. + * @return PHPUnit_Framework_MockObject_Builder_Stub + */ + public function after($id); +} +?> Property changes on: test/PHPUnit/Framework/MockObject/Builder/Match.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/MockObject/Builder/Namespace.php =================================================================== --- test/PHPUnit/Framework/MockObject/Builder/Namespace.php (revision 0) +++ test/PHPUnit/Framework/MockObject/Builder/Namespace.php (revision 0) @@ -0,0 +1,88 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: Namespace.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/Util/Filter.php'; +require_once 'PHPUnit/Framework/MockObject/Builder/Match.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Interface for builders which can register builders with a given identification. + * + * This interface relates to PHPUnit_Framework_MockObject_Builder_Identity. + * + * @category Testing + * @package PHPUnit + * @author Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: 3.2.9 + * @link http://www.phpunit.de/ + * @since Interface available since Release 3.0.0 + */ +interface PHPUnit_Framework_MockObject_Builder_Namespace +{ + /** + * Looks up the match builder with identification $id and returns it. + * + * @param string $id The identifiction of the match builder. + * @return PHPUnit_Framework_MockObject_Builder_Match + */ + public function lookupId($id); + + /** + * Registers the match builder $builder with the identification $id. The + * builder can later be looked up using lookupId() to figure out if it + * has been invoked. + * + * @param string $id The identification of the match builder. + * @param PHPUnit_Framework_MockObject_Builder_Match $builder The builder which is being registered. + */ + public function registerId($id, PHPUnit_Framework_MockObject_Builder_Match $builder); +} +?> Property changes on: test/PHPUnit/Framework/MockObject/Builder/Namespace.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/MockObject/Builder/Stub.php =================================================================== --- test/PHPUnit/Framework/MockObject/Builder/Stub.php (revision 0) +++ test/PHPUnit/Framework/MockObject/Builder/Stub.php (revision 0) @@ -0,0 +1,77 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: Stub.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/Util/Filter.php'; +require_once 'PHPUnit/Framework/MockObject/Builder/Identity.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Builder interface for stubs which are actions replacing an invocation. + * + * @category Testing + * @package PHPUnit + * @author Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: 3.2.9 + * @link http://www.phpunit.de/ + * @since Interface available since Release 3.0.0 + */ +interface PHPUnit_Framework_MockObject_Builder_Stub extends PHPUnit_Framework_MockObject_Builder_Identity +{ + /** + * Stubs the matching method with the stub object $stub. Any invocations of + * the matched method will now be handled by the stub instead. + * + * @param PHPUnit_Framework_MockObject_Stub $stub The stub object. + * @return PHPUnit_Framework_MockObject_Builder_Identity + */ + public function will(PHPUnit_Framework_MockObject_Stub $stub); +} +?> Property changes on: test/PHPUnit/Framework/MockObject/Builder/Stub.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/MockObject/Builder/MethodNameMatch.php =================================================================== --- test/PHPUnit/Framework/MockObject/Builder/MethodNameMatch.php (revision 0) +++ test/PHPUnit/Framework/MockObject/Builder/MethodNameMatch.php (revision 0) @@ -0,0 +1,79 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: MethodNameMatch.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/Util/Filter.php'; +require_once 'PHPUnit/Framework/MockObject/Builder/ParametersMatch.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Builder interface for matcher of method names. + * + * @category Testing + * @package PHPUnit + * @author Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: 3.2.9 + * @link http://www.phpunit.de/ + * @since Interface available since Release 3.0.0 + */ +interface PHPUnit_Framework_MockObject_Builder_MethodNameMatch extends PHPUnit_Framework_MockObject_Builder_ParametersMatch +{ + /** + * Adds a new method name match and returns the parameter match object for + * further matching possibilities. + * + * @param PHPUnit_Framework_Constraint $name Constraint for matching method, if a + * string is passed it will use the + * PHPUnit_Framework_Constraint_IsEqual. + * @return PHPUnit_Framework_MockObject_Builder_ParametersMatch + */ + public function method($name); +} +?> Property changes on: test/PHPUnit/Framework/MockObject/Builder/MethodNameMatch.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/MockObject/Builder/ParametersMatch.php =================================================================== --- test/PHPUnit/Framework/MockObject/Builder/ParametersMatch.php (revision 0) +++ test/PHPUnit/Framework/MockObject/Builder/ParametersMatch.php (revision 0) @@ -0,0 +1,100 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: ParametersMatch.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/Util/Filter.php'; +require_once 'PHPUnit/Framework/MockObject/Builder/Match.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Builder interface for parameter matchers. + * + * @category Testing + * @package PHPUnit + * @author Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: 3.2.9 + * @link http://www.phpunit.de/ + * @since Interface available since Release 3.0.0 + */ +interface PHPUnit_Framework_MockObject_Builder_ParametersMatch extends PHPUnit_Framework_MockObject_Builder_Match +{ + /** + * Sets the parameters to match for, each parameter to this funtion will + * be part of match. To perform specific matches or constraints create a + * new PHPUnit_Framework_Constraint and use it for the parameter. + * If the parameter value is not a constraint it will use the + * PHPUnit_Framework_Constraint_IsEqual for the value. + * + * Some examples: + * + * // match first parameter with value 2 + * $b->with(2); + * // match first parameter with value 'smock' and second identical to 42 + * $b->with('smock', new PHPUnit_Framework_Constraint_IsEqual(42)); + * + * + * @return PHPUnit_Framework_MockObject_Builder_ParametersMatch + */ + public function with(); + + /** + * Sets a matcher which allows any kind of parameters. + * + * Some examples: + * + * // match any number of parameters + * $b->withAnyParamers(); + * + * + * @return PHPUnit_Framework_MockObject_Matcher_AnyParameters + */ + public function withAnyParameters(); +} +?> Property changes on: test/PHPUnit/Framework/MockObject/Builder/ParametersMatch.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/MockObject/MockObject.php =================================================================== --- test/PHPUnit/Framework/MockObject/MockObject.php (revision 0) +++ test/PHPUnit/Framework/MockObject/MockObject.php (revision 0) @@ -0,0 +1,88 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: MockObject.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/Util/Filter.php'; +require_once 'PHPUnit/Framework/MockObject/Builder/MethodNameMatch.php'; +require_once 'PHPUnit/Framework/MockObject/Matcher.php'; +require_once 'PHPUnit/Framework/MockObject/InvocationMocker.php'; +require_once 'PHPUnit/Framework/MockObject/Verifiable.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Interface for all mock objects which are generated by + * PHPUnit_Framework_MockObject_Mock. + * + * @category Testing + * @package PHPUnit + * @author Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: 3.2.9 + * @link http://www.phpunit.de/ + * @since Interface available since Release 3.0.0 + */ +interface PHPUnit_Framework_MockObject_MockObject extends PHPUnit_Framework_MockObject_Verifiable +{ + /** + * Returns the current invocation mocker which keeps track of expecations + * and stubs. + * @return PHPUnit_Framework_MockObject_InvocationMocker + */ + public function getInvocationMocker(); + + /** + * Registers a new expectation in the mock object and returns the match + * object which can be infused with further details. + * + * @param PHPUnit_Framework_MockObject_Matcher_Invocation $invocation The invocation handler for the method calls. + * @return PHPUnit_Framework_MockObject_Builder_MethodNameMatch + */ + public function expects(PHPUnit_Framework_MockObject_Matcher_Invocation $invocation); +} +?> Property changes on: test/PHPUnit/Framework/MockObject/MockObject.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/MockObject/Matcher.php =================================================================== --- test/PHPUnit/Framework/MockObject/Matcher.php (revision 0) +++ test/PHPUnit/Framework/MockObject/Matcher.php (revision 0) @@ -0,0 +1,280 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: Matcher.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/Framework/MockObject/Matcher/Invocation.php'; +require_once 'PHPUnit/Framework/MockObject/Invocation.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Main matcher which defines a full expectation using method, parameter and invocation matchers. + * + * This matcher encapsulates all the other matchers and allows the builder to set + * the specific matchers when the appropriate methods are called (once(), where() + * etc.). + * + * All properties are public so that they can easily be accessed by the builder. + * + * @category Testing + * @package PHPUnit + * @author Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class PHPUnit_Framework_MockObject_Matcher implements PHPUnit_Framework_MockObject_Matcher_Invocation +{ + public $invocationMatcher; + + public $afterMatchBuilderId = NULL; + + public $afterMatchBuilderIsInvoked = FALSE; + + public $methodNameMatcher = NULL; + + public $parametersMatcher = NULL; + + public $stub = NULL; + + public function __construct(PHPUnit_Framework_MockObject_Matcher_Invocation $invocationMatcher) + { + $this->invocationMatcher = $invocationMatcher; + } + + public function toString() + { + $list = array(); + + if ($this->invocationMatcher !== NULL) { + $list[] = $this->invocationMatcher->toString(); + } + + if ($this->methodNameMatcher !== NULL) { + $list[] = 'where ' . $this->methodNameMatcher->toString(); + } + + if ($this->parametersMatcher !== NULL) { + $list[] = 'and ' . $this->parametersMatcher->toString(); + } + + if ($this->afterMatchBuilderId !== NULL) { + $list[] = 'after ' . $this->afterMatchBuilderId; + } + + if ($this->stub !== NULL) { + $list[] = 'will ' . $this->stub->toString(); + } + + return join(' ', $list); + } + + public function invoked(PHPUnit_Framework_MockObject_Invocation $invocation) + { + if ($this->invocationMatcher === NULL) { + throw new RuntimeException('No invocation matcher is set'); + } + + if ($this->methodNameMatcher === NULL) { + throw new RuntimeException('No method matcher is set'); + } + + if ($this->afterMatchBuilderId !== NULL) { + $builder = $invocation->object->getInvocationMocker()->lookupId($this->afterMatchBuilderId); + + if (!$builder) { + throw new RuntimeException( + sprintf( + 'No builder found for match builder identification <%s>', + + $this->afterMatchBuilderId + ) + ); + } + + $matcher = $builder->getMatcher(); + + if ($matcher && $matcher->invocationMatcher->hasBeenInvoked()) { + $this->afterMatchBuilderIsInvoked = TRUE; + } + } + + $this->invocationMatcher->invoked($invocation); + + try { + if ( $this->parametersMatcher !== NULL && + !$this->parametersMatcher->matches($invocation)) { + $this->parametersMatcher->verify(); + } + } + + catch (PHPUnit_Framework_ExpectationFailedException $e) { + throw new PHPUnit_Framework_ExpectationFailedException( + sprintf( + "Expectation failed for %s when %s\n%s", + + $this->methodNameMatcher->toString(), + $this->invocationMatcher->toString(), + $e->getDescription() + ), + $e->getComparisonFailure() + ); + } + + if ($this->stub) { + return $this->stub->invoke($invocation); + } + + return NULL; + } + + public function matches(PHPUnit_Framework_MockObject_Invocation $invocation) + { + if ($this->afterMatchBuilderId !== NULL) { + $builder = $invocation->object->getInvocationMocker()->lookupId($this->afterMatchBuilderId); + + if (!$builder) { + throw new RuntimeException( + sprintf( + 'No builder found for match builder identification <%s>', + + $this->afterMatchBuilderId + ) + ); + } + + $matcher = $builder->getMatcher(); + + if (!$matcher) { + return FALSE; + } + + if (!$matcher->invocationMatcher->hasBeenInvoked()) { + return FALSE; + } + } + + if ($this->invocationMatcher === NULL) { + throw new RuntimeException('No invocation matcher is set'); + } + + if ($this->methodNameMatcher === NULL) { + throw new RuntimeException('No method matcher is set'); + } + + if (!$this->invocationMatcher->matches($invocation)) { + return FALSE; + } + + try { + if (!$this->methodNameMatcher->matches($invocation)) { + return FALSE; + } + } + + catch (PHPUnit_Framework_ExpectationFailedException $e) { + throw new PHPUnit_Framework_ExpectationFailedException( + sprintf( + "Expectation failed for %s when %s\n%s", + + $this->methodNameMatcher->toString(), + $this->invocationMatcher->toString(), + $e->getDescription() + ), + $e->getComparisonFailure() + ); + } + + return TRUE; + } + + public function verify() + { + if ($this->invocationMatcher === NULL) { + throw new RuntimeException('No invocation matcher is set'); + } + + if ($this->methodNameMatcher === NULL) { + throw new RuntimeException('No method matcher is set'); + } + + try { + $this->invocationMatcher->verify(); + + if ($this->parametersMatcher !== NULL) { + $this->parametersMatcher->verify(); + } + } + + catch (PHPUnit_Framework_ExpectationFailedException $e) { + throw new PHPUnit_Framework_ExpectationFailedException( + sprintf( + "Expectation failed for %s when %s.\n%s", + + $this->methodNameMatcher->toString(), + $this->invocationMatcher->toString(), + $e->getDescription() + ) + ); + } + } +} + +require_once 'PHPUnit/Framework/MockObject/Matcher/AnyInvokedCount.php'; +require_once 'PHPUnit/Framework/MockObject/Matcher/AnyParameters.php'; +require_once 'PHPUnit/Framework/MockObject/Matcher/InvokedAtIndex.php'; +require_once 'PHPUnit/Framework/MockObject/Matcher/InvokedAtLeastOnce.php'; +require_once 'PHPUnit/Framework/MockObject/Matcher/InvokedCount.php'; +require_once 'PHPUnit/Framework/MockObject/Matcher/InvokedRecorder.php'; +require_once 'PHPUnit/Framework/MockObject/Matcher/MethodName.php'; +require_once 'PHPUnit/Framework/MockObject/Matcher/Parameters.php'; +require_once 'PHPUnit/Framework/MockObject/Matcher/StatelessInvocation.php'; +?> Property changes on: test/PHPUnit/Framework/MockObject/Matcher.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/MockObject/Stub/Exception.php =================================================================== --- test/PHPUnit/Framework/MockObject/Stub/Exception.php (revision 0) +++ test/PHPUnit/Framework/MockObject/Stub/Exception.php (revision 0) @@ -0,0 +1,90 @@ +. + * 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 Oliver Schlicht + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: Exception.php 1985 2007-12-26 18:11:55Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 3.1.0 + */ + +require_once 'PHPUnit/Util/Filter.php'; +require_once 'PHPUnit/Framework/MockObject/Invocation.php'; +require_once 'PHPUnit/Framework/MockObject/Stub.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Stubs a method by raising a user-defined exception. + * + * @category Testing + * @package PHPUnit + * @author Oliver Schlicht + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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.0 + */ +class PHPUnit_Framework_MockObject_Stub_Exception implements PHPUnit_Framework_MockObject_Stub +{ + protected $exception; + + public function __construct(Exception $exception) + { + $this->exception = $exception; + } + + public function invoke(PHPUnit_Framework_MockObject_Invocation $invocation) + { + throw $this->exception; + } + + public function toString() + { + return sprintf( + 'raise user-specified exception %s', + + PHPUnit_Util_Type::toString($this->exception) + ); + } +} +?> Property changes on: test/PHPUnit/Framework/MockObject/Stub/Exception.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/MockObject/Stub/MatcherCollection.php =================================================================== --- test/PHPUnit/Framework/MockObject/Stub/MatcherCollection.php (revision 0) +++ test/PHPUnit/Framework/MockObject/Stub/MatcherCollection.php (revision 0) @@ -0,0 +1,76 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: MatcherCollection.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/Util/Filter.php'; +require_once 'PHPUnit/Framework/MockObject/Matcher.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Stubs a method by returning a user-defined value. + * + * @category Testing + * @package PHPUnit + * @author Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: 3.2.9 + * @link http://www.phpunit.de/ + * @since Interface available since Release 3.0.0 + */ +interface PHPUnit_Framework_MockObject_Stub_MatcherCollection +{ + /** + * Adds a new matcher to the collection which can be used as an expectation + * or a stub. + * + * @param PHPUnit_Framework_MockObject_Matcher_Invocation $matcher Matcher for invocations to mock objects. + */ + public function addMatcher(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher); +} +?> Property changes on: test/PHPUnit/Framework/MockObject/Stub/MatcherCollection.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/MockObject/Stub/Return.php =================================================================== --- test/PHPUnit/Framework/MockObject/Stub/Return.php (revision 0) +++ test/PHPUnit/Framework/MockObject/Stub/Return.php (revision 0) @@ -0,0 +1,90 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: Return.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/Util/Filter.php'; +require_once 'PHPUnit/Framework/MockObject/Invocation.php'; +require_once 'PHPUnit/Framework/MockObject/Stub.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Stubs a method by returning a user-defined value. + * + * @category Testing + * @package PHPUnit + * @author Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class PHPUnit_Framework_MockObject_Stub_Return implements PHPUnit_Framework_MockObject_Stub +{ + protected $value; + + public function __construct($value) + { + $this->value = $value; + } + + public function invoke(PHPUnit_Framework_MockObject_Invocation $invocation) + { + return $this->value; + } + + public function toString() + { + return sprintf( + 'return user-specified value %s', + + PHPUnit_Util_Type::toString($this->value) + ); + } +} +?> Property changes on: test/PHPUnit/Framework/MockObject/Stub/Return.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/MockObject/Stub/ConsecutiveCalls.php =================================================================== --- test/PHPUnit/Framework/MockObject/Stub/ConsecutiveCalls.php (revision 0) +++ test/PHPUnit/Framework/MockObject/Stub/ConsecutiveCalls.php (revision 0) @@ -0,0 +1,97 @@ +. + * 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 Patrick Müller + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: ConsecutiveCalls.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/Util/Filter.php'; +require_once 'PHPUnit/Framework/MockObject/Invocation.php'; +require_once 'PHPUnit/Framework/MockObject/Stub.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Stubs a method by returning a user-defined stack of values. + * + * @category Testing + * @package PHPUnit + * @author Patrick Müller + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class PHPUnit_Framework_MockObject_Stub_ConsecutiveCalls implements PHPUnit_Framework_MockObject_Stub +{ + protected $stack; + protected $value; + + public function __construct($stack) + { + $this->stack = $stack; + } + + public function invoke(PHPUnit_Framework_MockObject_Invocation $invocation) + { + $this->value = array_shift($this->stack); + + if ($this->value instanceof PHPUnit_Framework_MockObject_Stub) { + $this->value = $this->value->invoke($invocation); + } + + return $this->value; + } + + public function toString() + { + return sprintf( + 'return user-specified value %s', + + PHPUnit_Util_Type::toString($this->value) + ); + } +} +?> Property changes on: test/PHPUnit/Framework/MockObject/Stub/ConsecutiveCalls.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/MockObject/Verifiable.php =================================================================== --- test/PHPUnit/Framework/MockObject/Verifiable.php (revision 0) +++ test/PHPUnit/Framework/MockObject/Verifiable.php (revision 0) @@ -0,0 +1,75 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: Verifiable.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/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Interface for classes which must verify a given expectation. + * + * @category Testing + * @package PHPUnit + * @author Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: 3.2.9 + * @link http://www.phpunit.de/ + * @since Interface available since Release 3.0.0 + */ +interface PHPUnit_Framework_MockObject_Verifiable +{ + /** + * Verifies that the current expectation is valid. If everything is OK the + * code should just return, if not it must throw an exception. + * + * @throw PHPUnit_Framework_ExpectationFailedException + */ + public function verify(); +} +?> Property changes on: test/PHPUnit/Framework/MockObject/Verifiable.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/ComparisonFailure/Array.php =================================================================== --- test/PHPUnit/Framework/ComparisonFailure/Array.php (revision 0) +++ test/PHPUnit/Framework/ComparisonFailure/Array.php (revision 0) @@ -0,0 +1,119 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: Array.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'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Thrown when an assertion for array equality failed. + * + * @category Testing + * @package PHPUnit + * @author Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class PHPUnit_Framework_ComparisonFailure_Array extends PHPUnit_Framework_ComparisonFailure +{ + /** + * Returns a string describing the difference between the expected and the + * actual array. + * + * @note Diffing is only done for one level. + */ + public function toString() + { + if ($this->hasDiff()) { + return $this->diff( + print_r($this->expected, TRUE), + print_r($this->actual, TRUE) + ); + } + + $expectedOnly = array(); + $actualOnly = array(); + $diff = ''; + + foreach($this->expected as $expectedKey => $expectedValue) { + if (!array_key_exists($expectedKey, $this->actual)) { + $expectedOnly[] = $expectedKey; + continue; + } + + if ($expectedValue === $this->actual[$expectedKey]) continue; + + $diffObject = PHPUnit_Framework_ComparisonFailure::diffIdentical($expectedValue, $this->actual[$expectedKey], $this->message . "array key <{$expectedKey}>: "); + $diff .= $diffObject->toString() . "\n"; + } + + foreach($this->actual as $actualKey => $actualValue) { + if (!array_key_exists($actualKey, $this->expected)) { + $actualOnly[] = $actualKey; + continue; + } + } + + foreach($expectedOnly as $expectedKey) { + $expectedValue = $this->expected[$expectedKey]; + $diff .= "array key <{$expectedKey}>: only in expected <{$expectedValue}>\n"; + } + + foreach($actualOnly as $actualKey) { + $actualValue = $this->actual[$actualKey]; + $diff .= "array key <{$actualKey}>: only in actual <{$actualValue}>\n"; + } + + return $diff; + } +} +?> Property changes on: test/PHPUnit/Framework/ComparisonFailure/Array.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/ComparisonFailure/Type.php =================================================================== --- test/PHPUnit/Framework/ComparisonFailure/Type.php (revision 0) +++ test/PHPUnit/Framework/ComparisonFailure/Type.php (revision 0) @@ -0,0 +1,82 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: Type.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'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Thrown when an assertion for type equality failed. + * + * @category Testing + * @package PHPUnit + * @author Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class PHPUnit_Framework_ComparisonFailure_Type extends PHPUnit_Framework_ComparisonFailure +{ + /** + * Returns a string describing the type difference between the expected + * and the actual value. + */ + public function toString() + { + return sprintf( + '%s does not match expected type "%s".', + + PHPUnit_Util_Type::toString($this->actual), + gettype($this->expected) + ); + } +} +?> Property changes on: test/PHPUnit/Framework/ComparisonFailure/Type.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/ComparisonFailure/Scalar.php =================================================================== --- test/PHPUnit/Framework/ComparisonFailure/Scalar.php (revision 0) +++ test/PHPUnit/Framework/ComparisonFailure/Scalar.php (revision 0) @@ -0,0 +1,108 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: Scalar.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'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Thrown when an assertion for scalar equality failed. + * + * @category Testing + * @package PHPUnit + * @author Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class PHPUnit_Framework_ComparisonFailure_Scalar extends PHPUnit_Framework_ComparisonFailure +{ + /** + * Returns a string describing the difference between the expected and the + * actual scalar value. + */ + public function toString() + { + if (is_int($this->expected) || is_float($this->expected)) { + $type = gettype($this->expected); + $expectedString = print_r($this->expected, TRUE); + $actualString = print_r($this->actual, TRUE); + $differenceString = print_r(abs($this->actual - $this->expected), TRUE); + + $expectedLen = strlen($expectedString); + $actualLen = strlen($actualString); + $differenceLen = strlen($differenceString); + $maxLen = max($expectedLen, $actualLen, $differenceLen); + + $expectedString = str_pad($expectedString, $maxLen, ' ', STR_PAD_LEFT); + $differenceString = str_pad($differenceString, $maxLen, ' ', STR_PAD_LEFT); + $actualString = str_pad($actualString, $maxLen, ' ', STR_PAD_LEFT); + + return sprintf( + "%s%sexpected %s <%s>\n" . + "%sdifference%s<%s>\n" . + '%sgot %s <%s>', + + $this->message, + ($this->message != '') ? ' ' : '', + $type, + $expectedString, + ($this->message != '') ? str_repeat(' ', strlen($this->message) + 1) : '', + str_repeat(' ', strlen($type)), + $differenceString, + ($this->message != '') ? str_repeat(' ', strlen($this->message) + 1) : '', + $type, + $actualString + ); + } + } +} +?> Property changes on: test/PHPUnit/Framework/ComparisonFailure/Scalar.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/ComparisonFailure/Object.php =================================================================== --- test/PHPUnit/Framework/ComparisonFailure/Object.php (revision 0) +++ test/PHPUnit/Framework/ComparisonFailure/Object.php (revision 0) @@ -0,0 +1,144 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: Object.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'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Thrown when an assertion for object equality failed. + * + * @category Testing + * @package PHPUnit + * @author Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class PHPUnit_Framework_ComparisonFailure_Object extends PHPUnit_Framework_ComparisonFailure +{ + /** + * Returns a string describing the difference between the expected and the + * actual object. + * + * @note Diffing is only done for one level. + */ + public function toString() + { + if ($this->hasDiff()) { + return $this->diff( + print_r($this->expected, TRUE), + print_r($this->actual, TRUE) + ); + } + + $expectedClass = get_class($this->expected); + $actualClass = get_class($this->actual); + + if ($expectedClass !== $actualClass) { + return sprintf( + "%s%sexpected class <%s>\n" . + '%sgot class <%s>', + + $this->message, + ($this->message != '') ? ' ' : '', + $expectedClass, + ($this->message != '') ? str_repeat(' ', strlen($this->message) + 1) : '', + $actualClass + ); + } else { + $expectedReflection = new ReflectionClass($expectedClass); + $actualReflection = new ReflectionClass($actualClass); + + $diff = "in object of class <{$expectedClass}>:\n"; + $i = 0; + + foreach($expectedReflection->getProperties() as $expectedAttribute) { + if ($expectedAttribute->isPrivate() || $expectedAttribute->isProtected()) continue; + + $actualAttribute = $actualReflection->getProperty($expectedAttribute->getName()); + $expectedValue = $expectedAttribute->getValue($this->expected); + $actualValue = $actualAttribute->getValue($this->actual); + + if ($expectedValue !== $actualValue) { + if ($i > 0) { + $diff .= "\n"; + } + + ++$i; + + $expectedType = gettype($expectedValue); + $actualType = gettype($actualValue); + + if ($expectedType !== $actualType) { + $diffObject = new PHPUnit_Framework_ComparisonFailure_Type($expectedValue, $actualValue, $this->message . 'attribute <' . $expectedAttribute->getName() . '>: '); + $diff .= $diffObject->toString(); + } + + elseif (is_object($expectedValue)) { + if (get_class($expectedValue) !== get_class($actualValue)) { + $diffObject = new PHPUnit_Framework_ComparisonFailure_Type($expectedValue, $actualValue, $this->message . 'attribute <' . $expectedAttribute->getName() . '>: '); + $diff .= $diffObject->toString(); + } else { + $diff .= 'attribute <' . $expectedAttribute->getName() . '> contains object <' . get_class($expectedValue) . '> with different attributes'; + } + } else { + $diffObject = PHPUnit_Framework_ComparisonFailure::diffIdentical($expectedValue, $actualValue, $this->message . 'attribute <' . $expectedAttribute->getName() . '>: '); + $diff .= $diffObject->toString(); + } + } + } + + return $diff; + } + } +} +?> Property changes on: test/PHPUnit/Framework/ComparisonFailure/Object.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/ComparisonFailure/String.php =================================================================== --- test/PHPUnit/Framework/ComparisonFailure/String.php (revision 0) +++ test/PHPUnit/Framework/ComparisonFailure/String.php (revision 0) @@ -0,0 +1,120 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: String.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'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Thrown when an assertion for string equality failed. + * + * @category Testing + * @package PHPUnit + * @author Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class PHPUnit_Framework_ComparisonFailure_String extends PHPUnit_Framework_ComparisonFailure +{ + /** + * Returns a string describing the difference between + * the expected and the actual string value. + */ + public function toString() + { + $expected = (string)$this->expected; + $actual = (string)$this->actual; + + if (strpos($expected, "\n") !== FALSE || strpos($actual, "\n") !== FALSE) { + if ($this->hasDiff()) { + return $this->diff($expected, $actual); + } else { + return ''; + } + } + + $expectedLen = strlen($expected); + $actualLen = strlen($actual); + $minLen = min($expectedLen, $actualLen); + $maxLen = max($expectedLen, $actualLen); + + for ($i = 0; $i < $minLen; ++$i) { + if ($expected[$i] != $actual[$i]) break; + } + + $startPos = $i; + $endPos = $minLen; + + if ($minLen > 0) { + for ($i = $minLen - 1; $i > $startPos; --$i) { + if ($expected[$i] != $actual[$i]) break; + } + + $endPos = $i + 1; + } + + return sprintf( + "%s%sexpected string <%s>\n" . + "%sdifference <%s>\n" . + '%sgot string <%s>', + + $this->message, + ($this->message != '') ? ' ' : '', + $expected, + ($this->message != '') ? str_repeat(' ', strlen($this->message) + 1) : '', + str_repeat(' ', $startPos) . str_repeat('x', $endPos - $startPos) . str_repeat('?', $maxLen - $minLen), + ($this->message != '') ? str_repeat(' ', strlen($this->message) + 1) : '', + $actual + ); + } +} +?> Property changes on: test/PHPUnit/Framework/ComparisonFailure/String.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/Constraint/ClassHasStaticAttribute.php =================================================================== --- test/PHPUnit/Framework/Constraint/ClassHasStaticAttribute.php (revision 0) +++ test/PHPUnit/Framework/Constraint/ClassHasStaticAttribute.php (revision 0) @@ -0,0 +1,90 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: ClassHasStaticAttribute.php 1985 2007-12-26 18:11:55Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 3.1.0 + */ + +require_once 'PHPUnit/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; +require_once 'PHPUnit/Util/Type.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Constraint that asserts that the class it is evaluated for has a given + * static attribute. + * + * The attribute name is passed in the constructor. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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.0 + */ +class PHPUnit_Framework_Constraint_ClassHasStaticAttribute extends PHPUnit_Framework_Constraint_ClassHasAttribute +{ + /** + * Evaluates the constraint for parameter $other. Returns TRUE if the + * constraint is met, FALSE otherwise. + * + * @param mixed $other Value or object to evaluate. + * @return bool + */ + public function evaluate($other) + { + $class = new ReflectionClass($other); + + if ($class->hasProperty($this->attributeName)) { + $attribute = $class->getProperty($this->attributeName); + + return $attribute->isStatic(); + } else { + return FALSE; + } + } +} +?> Property changes on: test/PHPUnit/Framework/Constraint/ClassHasStaticAttribute.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/Constraint/Not.php =================================================================== --- test/PHPUnit/Framework/Constraint/Not.php (revision 0) +++ test/PHPUnit/Framework/Constraint/Not.php (revision 0) @@ -0,0 +1,129 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: Not.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'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Logical NOT. + * + * @category Testing + * @package PHPUnit + * @author Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ + +class PHPUnit_Framework_Constraint_Not extends PHPUnit_Framework_Constraint +{ + protected $constraint; + + public function __construct($constraint) + { + if (!($constraint instanceof PHPUnit_Framework_Constraint)) { + $constraint = new PHPUnit_Framework_Constraint_IsEqual($constraint); + } + + $this->constraint = $constraint; + } + + /** + * Evaluates the constraint for parameter $other. Returns TRUE if the + * constraint is met, FALSE otherwise. + * + * @param mixed $other Value or object to evaluate. + * @return bool + */ + public function evaluate($other) + { + return !$this->constraint->evaluate($other); + } + + /** + * @param mixed $other The value passed to evaluate() which failed the + * constraint check. + * @param string $description A string with extra description of what was + * going on while the evaluation failed. + * @param boolean $not Flag to indicate negation. + * @throws PHPUnit_Framework_ExpectationFailedException + */ + public function fail($other, $description, $not = FALSE) + { + $this->constraint->fail($other, $description, TRUE); + } + + /** + * Returns a string representation of the constraint. + * + * @return string + * @access public + */ + public function toString() + { + switch (get_class($this->constraint)) { + case 'PHPUnit_Framework_Constraint_And': + case 'PHPUnit_Framework_Constraint_Not': + case 'PHPUnit_Framework_Constraint_Or': { + return 'not( ' . $this->constraint->toString() . ' )'; + } + break; + + default: { + return PHPUnit_Framework_Constraint::negate( + $this->constraint->toString() + ); + } + } + } +} +?> Property changes on: test/PHPUnit/Framework/Constraint/Not.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/Constraint/And.php =================================================================== --- test/PHPUnit/Framework/Constraint/And.php (revision 0) +++ test/PHPUnit/Framework/Constraint/And.php (revision 0) @@ -0,0 +1,142 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: And.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/Type.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Logical AND. + * + * @category Testing + * @package PHPUnit + * @author Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class PHPUnit_Framework_Constraint_And extends PHPUnit_Framework_Constraint +{ + protected $constraints = array(); + + protected $lastConstraint = NULL; + + public function setConstraints(array $constraints) + { + $this->constraints = array(); + + foreach($constraints as $key => $constraint) { + if (!($constraint instanceof PHPUnit_Framework_Constraint)) { + throw new InvalidArgumentException('All parameters to ' . __CLASS__ . ' must be a constraint object.'); + } + + $this->constraints[] = $constraint; + } + } + + /** + * Evaluates the constraint for parameter $other. Returns TRUE if the + * constraint is met, FALSE otherwise. + * + * @param mixed $other Value or object to evaluate. + * @return bool + */ + public function evaluate($other) + { + $this->lastConstraint = NULL; + + foreach($this->constraints as $constraint) { + $this->lastConstraint = $constraint; + + if (!$constraint->evaluate($other)) { + return FALSE; + } + } + + return TRUE; + } + + /** + * @param mixed $other The value passed to evaluate() which failed the + * constraint check. + * @param string $description A string with extra description of what was + * going on while the evaluation failed. + * @param boolean $not Flag to indicate negation. + * @throws PHPUnit_Framework_ExpectationFailedException + */ + public function fail($other, $description, $not = FALSE) + { + $this->lastConstraint->fail($other, $description, $not); + } + + /** + * Returns a string representation of the constraint. + * + * @return string + * @access public + */ + public function toString() + { + $text = ''; + + foreach($this->constraints as $key => $constraint) { + if ($key > 0) { + $text .= ' and '; + } + + $text .= $constraint->toString(); + } + + return $text; + } +} +?> Property changes on: test/PHPUnit/Framework/Constraint/And.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/Constraint/Attribute.php =================================================================== --- test/PHPUnit/Framework/Constraint/Attribute.php (revision 0) +++ test/PHPUnit/Framework/Constraint/Attribute.php (revision 0) @@ -0,0 +1,122 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: Attribute.php 1985 2007-12-26 18:11:55Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 3.1.0 + */ + +require_once 'PHPUnit/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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.0 + */ + +class PHPUnit_Framework_Constraint_Attribute extends PHPUnit_Framework_Constraint +{ + protected $attributeName; + protected $constraint; + + public function __construct(PHPUnit_Framework_Constraint $constraint, $attributeName) + { + $this->attributeName = $attributeName; + $this->constraint = $constraint; + } + + /** + * Evaluates the constraint for parameter $other. Returns TRUE if the + * constraint is met, FALSE otherwise. + * + * @param mixed $other Value or object to evaluate. + * @return bool + */ + public function evaluate($other) + { + return $this->constraint->evaluate( + PHPUnit_Framework_Assert::readAttribute( + $other, $this->attributeName + ) + ); + } + + /** + * @param mixed $other The value passed to evaluate() which failed the + * constraint check. + * @param string $description A string with extra description of what was + * going on while the evaluation failed. + * @param boolean $not Flag to indicate negation. + * @throws PHPUnit_Framework_ExpectationFailedException + */ + public function fail($other, $description, $not = FALSE) + { + parent::fail( + PHPUnit_Framework_Assert::readAttribute( + $other, $this->attributeName + ), + $description, + $not + ); + } + + /** + * Returns a string representation of the constraint. + * + * @return string + * @access public + */ + public function toString() + { + return $this->constraint->toString(); + } +} +?> Property changes on: test/PHPUnit/Framework/Constraint/Attribute.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/Constraint/IsEqual.php =================================================================== --- test/PHPUnit/Framework/Constraint/IsEqual.php (revision 0) +++ test/PHPUnit/Framework/Constraint/IsEqual.php (revision 0) @@ -0,0 +1,290 @@ +. + * 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 Kore Nordmann + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: IsEqual.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/Type.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Constraint that checks if one value is equal to another. + * + * Equality is checked with PHP's == operator, the operator is explained in detail + * at {@url http://www.php.net/manual/en/types.comparisons.php}. + * Two values are equal if they have the same value disregarding type. + * + * The expected value is passed in the constructor. + * + * @category Testing + * @package PHPUnit + * @author Kore Nordmann + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class PHPUnit_Framework_Constraint_IsEqual extends PHPUnit_Framework_Constraint +{ + protected $value; + protected $delta = 0; + protected $maxDepth = 10; + + public function __construct($value, $delta = 0, $maxDepth = 10) + { + $this->value = $value; + $this->delta = $delta; + $this->maxDepth = $maxDepth; + } + + /** + * Evaluates the constraint for parameter $other. Returns TRUE if the + * constraint is met, FALSE otherwise. + * + * @param mixed $other Value or object to evaluate. + * @return bool + */ + public function evaluate($other) + { + return $this->recursiveComparison($this->value, $other); + } + + /** + * @param mixed $other The value passed to evaluate() which failed the + * constraint check. + * @param string $description A string with extra description of what was + * going on while the evaluation failed. + * @param boolean $not Flag to indicate negation. + * @throws PHPUnit_Framework_ExpectationFailedException + */ + public function fail($other, $description, $not = FALSE) + { + $failureDescription = $this->failureDescription( + $other, + $description, + $not + ); + + if (!$not) { + if ($this->value instanceof DOMDocument) { + $value = $this->domToText($this->value); + } else { + $value = $this->value; + } + + if ($other instanceof DOMDocument) { + $other = $this->domToText($other); + } + + throw new PHPUnit_Framework_ExpectationFailedException( + $failureDescription, + PHPUnit_Framework_ComparisonFailure::diffEqual($value, $other), + $description + ); + } else { + throw new PHPUnit_Framework_ExpectationFailedException( + $failureDescription, + NULL + ); + } + } + + /** + * Returns a string representation of the constraint. + * + * @return string + * @access public + */ + public function toString() + { + $delta = ''; + + if (is_string($this->value)) { + if (strpos($this->value, "\n") !== FALSE) { + return 'is equal to '; + } else { + return sprintf( + 'is equal to ', + + $this->value + ); + } + } else { + if ($this->delta != 0) { + $delta = sprintf( + ' with delta <%F>', + + $this->delta + ); + } + + return sprintf( + 'is equal to %s%s', + + PHPUnit_Util_Type::toString($this->value), + $delta + ); + } + } + + /** + * Perform the actual recursive comparision of two values + * + * @param mixed $a First value + * @param mixed $b Second value + * @param int $depth Depth + * @return bool + */ + protected function recursiveComparison($a, $b, $depth = 0) + { + if ($a === $b) { + return TRUE; + } + + if ($depth >= $this->maxDepth) { + return TRUE; + } + + if (is_numeric($a) XOR is_numeric($b)) { + return FALSE; + } + + if (is_array($a) XOR is_array($b)) { + return FALSE; + } + + if (is_object($a) XOR is_object($b)) { + return FALSE; + } + + if ($a instanceof DOMDocument) { + $a = $this->domToText($a); + } + + if ($b instanceof DOMDocument) { + $b = $this->domToText($b); + } + + if (is_object($a) && is_object($b) && + (get_class($a) !== get_class($b))) { + return FALSE; + } + + // Normal comparision for scalar values. + if ((!is_array($a) && !is_object($a)) || + (!is_array($b) && !is_object($b))) { + if (is_numeric($a) && is_numeric($b)) { + // Optionally apply delta on numeric values. + return $this->numericComparison($a, $b); + } else { + return ($a == $b); + } + } + + if (is_object($a)) { + $a = (array) $a; + $b = (array) $b; + } + + foreach ($a as $key => $v) { + if (!array_key_exists($key, $b)) { + // Abort on missing key in $b. + return FALSE; + } + + if (!$this->recursiveComparison($a[$key], $b[$key], $depth + 1)) { + // FALSE, if child comparision fails. + return FALSE; + } + + // Unset key to check whether all keys of b are compared. + unset($b[$key]); + } + + if (count($b)) { + // There is something in $b, that is missing in $a. + return FALSE; + } + + return TRUE; + } + + /** + * Compares two numeric values - use delta if applieable + * + * @param mixed $a First value + * @param mixed $b Second value + * @return bool + */ + protected function numericComparison($a, $b) + { + if ($this->delta === FALSE) { + return ($a == $b); + } else { + return (abs($a - $b) <= $this->delta); + } + } + + /** + * Returns the normalized, whitespace-cleaned, and indented textual + * representation of a DOMDocument. + * + * @param DOMDocument $document + * @return string + */ + protected function domToText(DOMDocument $document) + { + $document->formatOutput = true; + $document->preserveWhiteSpace = false; + $document->normalizeDocument(); + + return $document->saveXML(); + } +} +?> Property changes on: test/PHPUnit/Framework/Constraint/IsEqual.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/Constraint/GreaterThan.php =================================================================== --- test/PHPUnit/Framework/Constraint/GreaterThan.php (revision 0) +++ test/PHPUnit/Framework/Constraint/GreaterThan.php (revision 0) @@ -0,0 +1,100 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: GreaterThan.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/Type.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Constraint that asserts that the value it is evaluated for is greater + * than a given value. + * + * @category Testing + * @package PHPUnit + * @author Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class PHPUnit_Framework_Constraint_GreaterThan extends PHPUnit_Framework_Constraint +{ + protected $value; + + public function __construct($value) + { + $this->value = $value; + } + + /** + * Evaluates the constraint for parameter $other. Returns TRUE if the + * constraint is met, FALSE otherwise. + * + * @param mixed $other Value or object to evaluate. + * @return bool + */ + public function evaluate($other) + { + return $this->value < $other; + } + + /** + * Returns a string representation of the constraint. + * + * @return string + * @access public + */ + public function toString() + { + return 'is greater than ' . PHPUnit_Util_Type::toString($this->value); + } +} +?> Property changes on: test/PHPUnit/Framework/Constraint/GreaterThan.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/Constraint/StringContains.php =================================================================== --- test/PHPUnit/Framework/Constraint/StringContains.php (revision 0) +++ test/PHPUnit/Framework/Constraint/StringContains.php (revision 0) @@ -0,0 +1,122 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: StringContains.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/Type.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Constraint that asserts that the string it is evaluated for contains + * a given string. + * + * Uses strpos() to find the position of the string in the input, if not found + * the evaluaton fails. + * + * The sub-string is passed in the constructor. + * + * @category Testing + * @package PHPUnit + * @author Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class PHPUnit_Framework_Constraint_StringContains extends PHPUnit_Framework_Constraint +{ + protected $string; + + protected $case; + + public function __construct($string, $case = TRUE) + { + $this->string = $string; + $this->case = $case; + } + + /** + * Evaluates the constraint for parameter $other. Returns TRUE if the + * constraint is met, FALSE otherwise. + * + * @param mixed $other Value or object to evaluate. + * @return bool + */ + public function evaluate($other) + { + if ($this->case) { + return strpos($other, $this->string) !== FALSE; + } else { + return stripos($other, $this->string) !== FALSE; + } + } + + /** + * Returns a string representation of the constraint. + * + * @return string + * @access public + */ + public function toString() + { + if ($this->case) { + $string = $this->string; + } else { + $string = strtolower($this->string); + } + + return sprintf( + 'contains "%s"', + + $string + ); + } +} +?> Property changes on: test/PHPUnit/Framework/Constraint/StringContains.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/Constraint/PCREMatch.php =================================================================== --- test/PHPUnit/Framework/Constraint/PCREMatch.php (revision 0) +++ test/PHPUnit/Framework/Constraint/PCREMatch.php (revision 0) @@ -0,0 +1,109 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: PCREMatch.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/Type.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Constraint that asserts that the string it is evaluated for matches + * a regular expression. + * + * Checks a given value using the Perl Compatible Regular Expression extension + * in PHP. The pattern is matched by executing preg_match(). + * + * The pattern string passed in the constructor. + * + * @category Testing + * @package PHPUnit + * @author Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class PHPUnit_Framework_Constraint_PCREMatch extends PHPUnit_Framework_Constraint +{ + protected $pattern; + + public function __construct($pattern) + { + $this->pattern = $pattern; + } + + /** + * Evaluates the constraint for parameter $other. Returns TRUE if the + * constraint is met, FALSE otherwise. + * + * @param mixed $other Value or object to evaluate. + * @return bool + */ + public function evaluate($other) + { + return preg_match($this->pattern, $other) > 0; + } + + /** + * Returns a string representation of the constraint. + * + * @return string + * @access public + */ + public function toString() + { + return sprintf( + 'matches PCRE pattern "%s"', + + $this->pattern + ); + } +} +?> Property changes on: test/PHPUnit/Framework/Constraint/PCREMatch.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/Constraint/Xor.php =================================================================== --- test/PHPUnit/Framework/Constraint/Xor.php (revision 0) +++ test/PHPUnit/Framework/Constraint/Xor.php (revision 0) @@ -0,0 +1,150 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: Xor.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/Type.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Logical XOR. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class PHPUnit_Framework_Constraint_Xor extends PHPUnit_Framework_Constraint +{ + protected $constraints = array(); + + public function setConstraints(array $constraints) + { + $this->constraints = array(); + + foreach($constraints as $key => $constraint) { + if (!($constraint instanceof PHPUnit_Framework_Constraint)) { + $constraint = new PHPUnit_Framework_Constraint_IsEqual($constraint); + } + + $this->constraints[] = $constraint; + } + } + + /** + * Evaluates the constraint for parameter $other. Returns TRUE if the + * constraint is met, FALSE otherwise. + * + * @param mixed $other Value or object to evaluate. + * @return bool + */ + public function evaluate($other) + { + $result = FALSE; + + foreach($this->constraints as $constraint) { + if ($constraint->evaluate($other)) { + if ( $result ) + { + return FALSE; + } + + $result = TRUE; + } + } + + return $result; + } + + /** + * @param mixed $other The value passed to evaluate() which failed the + * constraint check. + * @param string $description A string with extra description of what was + * going on while the evaluation failed. + * @param boolean $not Flag to indicate negation. + * @throws PHPUnit_Framework_ExpectationFailedException + */ + public function fail($other, $description, $not = FALSE) + { + throw new PHPUnit_Framework_ExpectationFailedException( + sprintf( + 'Failed asserting that %s.', + + $this->toString(), + NULL, + $description + ) + ); + } + + /** + * Returns a string representation of the constraint. + * + * @return string + * @access public + */ + public function toString() + { + $text = ''; + + foreach($this->constraints as $key => $constraint) { + if ($key > 0) { + $text .= ' xor '; + } + + $text .= $constraint->toString(); + } + + return $text; + } +} +?> Property changes on: test/PHPUnit/Framework/Constraint/Xor.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/Constraint/TraversableContains.php =================================================================== --- test/PHPUnit/Framework/Constraint/TraversableContains.php (revision 0) +++ test/PHPUnit/Framework/Constraint/TraversableContains.php (revision 0) @@ -0,0 +1,104 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: TraversableContains.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/Type.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Constraint that asserts that the Traversable it is applied to contains + * a given value. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class PHPUnit_Framework_Constraint_TraversableContains extends PHPUnit_Framework_Constraint +{ + protected $value; + + public function __construct($value) + { + $this->value = $value; + } + + /** + * Evaluates the constraint for parameter $other. Returns TRUE if the + * constraint is met, FALSE otherwise. + * + * @param mixed $other Value or object to evaluate. + * @return bool + */ + public function evaluate($other) + { + foreach ($other as $straw) { + if ($straw === $this->value) { + return TRUE; + } + } + + return FALSE; + } + + /** + * Returns a string representation of the constraint. + * + * @return string + * @access public + */ + public function toString() + { + return 'contains ' . PHPUnit_Util_Type::toString($this->value); + } +} +?> Property changes on: test/PHPUnit/Framework/Constraint/TraversableContains.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/Constraint/TraversableContainsOnly.php =================================================================== --- test/PHPUnit/Framework/Constraint/TraversableContainsOnly.php (revision 0) +++ test/PHPUnit/Framework/Constraint/TraversableContainsOnly.php (revision 0) @@ -0,0 +1,111 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: TraversableContainsOnly.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/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; +require_once 'PHPUnit/Util/Type.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Constraint that asserts that the Traversable it is applied to contains + * only values of a given type. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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_Framework_Constraint_TraversableContainsOnly extends PHPUnit_Framework_Constraint +{ + protected $constraint; + protected $type; + + public function __construct($type, $isNativeType = TRUE) + { + if ($isNativeType) { + $this->constraint = new PHPUnit_Framework_Constraint_IsType($type); + } else { + $this->constraint = new PHPUnit_Framework_Constraint_IsInstanceOf($type); + } + + $this->type = $type; + } + + /** + * Evaluates the constraint for parameter $other. Returns TRUE if the + * constraint is met, FALSE otherwise. + * + * @param mixed $other Value or object to evaluate. + * @return bool + */ + public function evaluate($other) + { + foreach ($other as $item) { + if (!$this->constraint->evaluate($item)) { + return FALSE; + } + } + + return TRUE; + } + + /** + * Returns a string representation of the constraint. + * + * @return string + * @access public + */ + public function toString() + { + return 'contains only values of type "' . $this->type . '"'; + } +} +?> Property changes on: test/PHPUnit/Framework/Constraint/TraversableContainsOnly.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/Constraint/IsAnything.php =================================================================== --- test/PHPUnit/Framework/Constraint/IsAnything.php (revision 0) +++ test/PHPUnit/Framework/Constraint/IsAnything.php (revision 0) @@ -0,0 +1,102 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: IsAnything.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'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Constraint that accepts any input value. + * + * @category Testing + * @package PHPUnit + * @author Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class PHPUnit_Framework_Constraint_IsAnything extends PHPUnit_Framework_Constraint +{ + /** + * Evaluates the constraint for parameter $other. Returns TRUE if the + * constraint is met, FALSE otherwise. + * + * @param mixed $other Value or object to evaluate. + * @return bool + */ + public function evaluate($other) + { + return TRUE; + } + + /** + * @param mixed $other The value passed to evaluate() which failed the + * constraint check. + * @param string $description A string with extra description of what was + * going on while the evaluation failed. + * @param boolean $not Flag to indicate negation. + */ + public function fail($other, $description, $not = FALSE) + { + } + + /** + * Returns a string representation of the constraint. + * + * @return string + * @access public + */ + public function toString() + { + return 'is anything'; + } +} +?> Property changes on: test/PHPUnit/Framework/Constraint/IsAnything.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/Constraint/IsType.php =================================================================== --- test/PHPUnit/Framework/Constraint/IsType.php (revision 0) +++ test/PHPUnit/Framework/Constraint/IsType.php (revision 0) @@ -0,0 +1,169 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: IsType.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'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Constraint that asserts that the value it is evaluated for is of a + * specified type. + * + * The expected value is passed in the constructor. + * + * @category Testing + * @package PHPUnit + * @author Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class PHPUnit_Framework_Constraint_IsType extends PHPUnit_Framework_Constraint +{ + protected $type; + + public function __construct($type) + { + switch ($type) { + case 'numeric': + case 'integer': + case 'int': + case 'float': + case 'string': + case 'boolean': + case 'bool': + case 'null': + case 'array': + case 'object': + case 'resource': { + break; + } + + default: { + throw new InvalidArgumentException( + sprintf( + 'Type specified for PHPUnit_Framework_Constraint_IsType <%s> is not a valid type.', + + $type + ) + ); + } + } + + $this->type = $type; + } + + /** + * Evaluates the constraint for parameter $other. Returns TRUE if the + * constraint is met, FALSE otherwise. + * + * @param mixed $other Value or object to evaluate. + * @return bool + */ + public function evaluate($other) + { + switch ($this->type) { + case 'numeric': { + return is_numeric($other); + } + + case 'integer': + case 'int': { + return is_integer($other); + } + + case 'float': { + return is_float($other); + } + + case 'string': { + return is_string($other); + } + + case 'boolean': + case 'bool': { + return is_bool($other); + } + + case 'null': { + return is_null($other); + } + + case 'array': { + return is_array($other); + } + + case 'object': { + return is_object($other); + } + + case 'resource': { + return is_resource($other); + } + } + } + + /** + * Returns a string representation of the constraint. + * + * @return string + * @access public + */ + public function toString() + { + return sprintf( + 'is of type "%s"', + + $this->type + ); + } +} +?> Property changes on: test/PHPUnit/Framework/Constraint/IsType.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/Constraint/FileExists.php =================================================================== --- test/PHPUnit/Framework/Constraint/FileExists.php (revision 0) +++ test/PHPUnit/Framework/Constraint/FileExists.php (revision 0) @@ -0,0 +1,122 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: FileExists.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'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Constraint that checks if the file(name) that it is evaluated for exists. + * + * The file path to check is passed as $other in evaluate(). + * + * @category Testing + * @package PHPUnit + * @author Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class PHPUnit_Framework_Constraint_FileExists extends PHPUnit_Framework_Constraint +{ + /** + * Evaluates the constraint for parameter $other. Returns TRUE if the + * constraint is met, FALSE otherwise. + * + * @param mixed $other Value or object to evaluate. + * @return bool + */ + public function evaluate($other) + { + return file_exists($other); + } + + /** + * @param mixed $other The value passed to evaluate() which failed the + * constraint check. + * @param string $description A string with extra description of what was + * going on while the evaluation failed. + * @param boolean $not Flag to indicate negation. + * @throws PHPUnit_Framework_ExpectationFailedException + */ + public function fail($other, $description, $not = FALSE) + { + $failureDescription = sprintf( + 'Failed asserting that file "%s" exists.', + + $other + ); + + if ($not) { + $failureDescription = self::negate($failureDescription); + } + + if (!empty($description)) { + $failureDescription = $description . "\n" . $failureDescription; + } + + throw new PHPUnit_Framework_ExpectationFailedException( + $failureDescription + ); + } + + /** + * Returns a string representation of the constraint. + * + * @return string + * @access public + */ + public function toString() + { + return 'file exists'; + } +} +?> Property changes on: test/PHPUnit/Framework/Constraint/FileExists.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/Constraint/Or.php =================================================================== --- test/PHPUnit/Framework/Constraint/Or.php (revision 0) +++ test/PHPUnit/Framework/Constraint/Or.php (revision 0) @@ -0,0 +1,145 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: Or.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/Type.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Logical OR. + * + * @category Testing + * @package PHPUnit + * @author Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class PHPUnit_Framework_Constraint_Or extends PHPUnit_Framework_Constraint +{ + protected $constraints = array(); + + public function setConstraints(array $constraints) + { + $this->constraints = array(); + + foreach($constraints as $key => $constraint) { + if (!($constraint instanceof PHPUnit_Framework_Constraint)) { + $constraint = new PHPUnit_Framework_Constraint_IsEqual($constraint); + } + + $this->constraints[] = $constraint; + } + } + + /** + * Evaluates the constraint for parameter $other. Returns TRUE if the + * constraint is met, FALSE otherwise. + * + * @param mixed $other Value or object to evaluate. + * @return bool + */ + public function evaluate($other) + { + foreach($this->constraints as $constraint) { + if ($constraint->evaluate($other)) { + return TRUE; + } + } + + return FALSE; + } + + /** + * @param mixed $other The value passed to evaluate() which failed the + * constraint check. + * @param string $description A string with extra description of what was + * going on while the evaluation failed. + * @param boolean $not Flag to indicate negation. + * @throws PHPUnit_Framework_ExpectationFailedException + */ + public function fail($other, $description, $not = FALSE) + { + throw new PHPUnit_Framework_ExpectationFailedException( + sprintf( + 'Failed asserting that %s %s.', + + PHPUnit_Util_Type::toString($other), + $this->toString() + ), + NULL, + $description + ); + } + + /** + * Returns a string representation of the constraint. + * + * @return string + * @access public + */ + public function toString() + { + $text = ''; + + foreach($this->constraints as $key => $constraint) { + if ($key > 0) { + $text .= ' or '; + } + + $text .= $constraint->toString(); + } + + return $text; + } +} +?> Property changes on: test/PHPUnit/Framework/Constraint/Or.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/Constraint/LessThan.php =================================================================== --- test/PHPUnit/Framework/Constraint/LessThan.php (revision 0) +++ test/PHPUnit/Framework/Constraint/LessThan.php (revision 0) @@ -0,0 +1,100 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: LessThan.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/Type.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Constraint that asserts that the value it is evaluated for is less than + * a given value. + * + * @category Testing + * @package PHPUnit + * @author Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class PHPUnit_Framework_Constraint_LessThan extends PHPUnit_Framework_Constraint +{ + protected $value; + + public function __construct($value) + { + $this->value = $value; + } + + /** + * Evaluates the constraint for parameter $other. Returns TRUE if the + * constraint is met, FALSE otherwise. + * + * @param mixed $other Value or object to evaluate. + * @return bool + */ + public function evaluate($other) + { + return $this->value > $other; + } + + /** + * Returns a string representation of the constraint. + * + * @return string + * @access public + */ + public function toString() + { + return 'is less than ' . PHPUnit_Util_Type::toString($this->value); + } +} +?> Property changes on: test/PHPUnit/Framework/Constraint/LessThan.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/Constraint/ArrayHasKey.php =================================================================== --- test/PHPUnit/Framework/Constraint/ArrayHasKey.php (revision 0) +++ test/PHPUnit/Framework/Constraint/ArrayHasKey.php (revision 0) @@ -0,0 +1,104 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: ArrayHasKey.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/Type.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Constraint that asserts that the array it is evaluated for has a given key. + * + * Uses array_key_exists() to check if the key is found in the input array, if not + * found the evaluaton fails. + * + * The array key is passed in the constructor. + * + * @category Testing + * @package PHPUnit + * @author Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class PHPUnit_Framework_Constraint_ArrayHasKey extends PHPUnit_Framework_Constraint +{ + protected $key; + + public function __construct($key) + { + $this->key = $key; + } + + /** + * Evaluates the constraint for parameter $other. Returns TRUE if the + * constraint is met, FALSE otherwise. + * + * @param mixed $other Value or object to evaluate. + * @return bool + */ + public function evaluate($other) + { + return array_key_exists($this->key, $other); + } + + /** + * Returns a string representation of the constraint. + * + * @return string + * @access public + */ + public function toString() + { + return 'has key ' . PHPUnit_Util_Type::toString($this->key); + } +} +?> Property changes on: test/PHPUnit/Framework/Constraint/ArrayHasKey.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/Constraint/IsInstanceOf.php =================================================================== --- test/PHPUnit/Framework/Constraint/IsInstanceOf.php (revision 0) +++ test/PHPUnit/Framework/Constraint/IsInstanceOf.php (revision 0) @@ -0,0 +1,132 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: IsInstanceOf.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/Type.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Constraint that asserts that the object it is evaluated for is an instance + * of a given class. + * + * The expected class name is passed in the constructor. + * + * @category Testing + * @package PHPUnit + * @author Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class PHPUnit_Framework_Constraint_IsInstanceOf extends PHPUnit_Framework_Constraint +{ + protected $className; + + public function __construct($className) + { + $this->className = $className; + } + + /** + * Evaluates the constraint for parameter $other. Returns TRUE if the + * constraint is met, FALSE otherwise. + * + * @param mixed $other Value or object to evaluate. + * @return bool + */ + public function evaluate($other) + { + return ($other instanceof $this->className); + } + + /** + * Creates the appropriate exception for the constraint which can be caught + * by the unit test system. This can be called if a call to evaluate() fails. + * + * @param mixed $other The value passed to evaluate() which failed the + * constraint check. + * @param string $description A string with extra description of what was + * going on while the evaluation failed. + * @param boolean $not Flag to indicate negation. + * @throws PHPUnit_Framework_ExpectationFailedException + */ + public function fail($other, $description, $not = FALSE) + { + throw new PHPUnit_Framework_ExpectationFailedException( + sprintf( + '%sFailed asserting that %s is %san instance of class "%s".', + + !empty($description) ? $description . "\n" : '', + PHPUnit_Util_Type::toString($other, TRUE), + $not ? 'not ' : '', + $this->className + ), + NULL + ); + } + + /** + * Returns a string representation of the constraint. + * + * @return string + * @access public + */ + public function toString() + { + return sprintf( + 'is instance of class "%s"', + + $this->className + ); + } +} +?> Property changes on: test/PHPUnit/Framework/Constraint/IsInstanceOf.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/Constraint/ClassHasAttribute.php =================================================================== --- test/PHPUnit/Framework/Constraint/ClassHasAttribute.php (revision 0) +++ test/PHPUnit/Framework/Constraint/ClassHasAttribute.php (revision 0) @@ -0,0 +1,106 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: ClassHasAttribute.php 1985 2007-12-26 18:11:55Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 3.1.0 + */ + +require_once 'PHPUnit/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; +require_once 'PHPUnit/Util/Type.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Constraint that asserts that the class it is evaluated for has a given + * attribute. + * + * The attribute name is passed in the constructor. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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.0 + */ +class PHPUnit_Framework_Constraint_ClassHasAttribute extends PHPUnit_Framework_Constraint +{ + protected $attributeName; + + public function __construct($attributeName) + { + $this->attributeName = $attributeName; + } + + /** + * Evaluates the constraint for parameter $other. Returns TRUE if the + * constraint is met, FALSE otherwise. + * + * @param mixed $other Value or object to evaluate. + * @return bool + */ + public function evaluate($other) + { + $class = new ReflectionClass($other); + + return $class->hasProperty($this->attributeName); + } + + /** + * Returns a string representation of the constraint. + * + * @return string + * @access public + */ + public function toString() + { + return sprintf( + 'has attribute "%s"', + + $this->attributeName + ); + } +} +?> Property changes on: test/PHPUnit/Framework/Constraint/ClassHasAttribute.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/Constraint/ObjectHasAttribute.php =================================================================== --- test/PHPUnit/Framework/Constraint/ObjectHasAttribute.php (revision 0) +++ test/PHPUnit/Framework/Constraint/ObjectHasAttribute.php (revision 0) @@ -0,0 +1,84 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: ObjectHasAttribute.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/Type.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Constraint that asserts that the object it is evaluated for has a given + * attribute. + * + * The attribute name is passed in the constructor. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class PHPUnit_Framework_Constraint_ObjectHasAttribute extends PHPUnit_Framework_Constraint_ClassHasAttribute +{ + /** + * Evaluates the constraint for parameter $other. Returns TRUE if the + * constraint is met, FALSE otherwise. + * + * @param mixed $other Value or object to evaluate. + * @return bool + */ + public function evaluate($other) + { + $object = new ReflectionObject($other); + + return $object->hasProperty($this->attributeName); + } +} +?> Property changes on: test/PHPUnit/Framework/Constraint/ObjectHasAttribute.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/Constraint/IsIdentical.php =================================================================== --- test/PHPUnit/Framework/Constraint/IsIdentical.php (revision 0) +++ test/PHPUnit/Framework/Constraint/IsIdentical.php (revision 0) @@ -0,0 +1,136 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: IsIdentical.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/Type.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Constraint that asserts that one value is identical to another. + * + * Identical check is performed with PHP's === operator, the operator is explained + * in detail at {@url http://www.php.net/manual/en/types.comparisons.php}. + * Two values are identical if they have the same value and are of the same type. + * + * The expected value is passed in the constructor. + * + * @category Testing + * @package PHPUnit + * @author Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class PHPUnit_Framework_Constraint_IsIdentical extends PHPUnit_Framework_Constraint +{ + protected $value; + + public function __construct($value) + { + $this->value = $value; + } + + /** + * Evaluates the constraint for parameter $other. Returns TRUE if the + * constraint is met, FALSE otherwise. + * + * @param mixed $other Value or object to evaluate. + * @return bool + */ + public function evaluate($other) + { + return $this->value === $other; + } + + /** + * @param mixed $other The value passed to evaluate() which failed the + * constraint check. + * @param string $description A string with extra description of what was + * going on while the evaluation failed. + * @param boolean $not Flag to indicate negation. + * @throws PHPUnit_Framework_ExpectationFailedException + */ + public function fail($other, $description, $not = FALSE) + { + $failureDescription = $this->failureDescription( + $other, + $description, + $not + ); + + if (!$not) { + throw new PHPUnit_Framework_ExpectationFailedException( + $failureDescription, + PHPUnit_Framework_ComparisonFailure::diffIdentical($this->value, $other), + $description + ); + } else { + throw new PHPUnit_Framework_ExpectationFailedException( + $failureDescription, + NULL, + $description + ); + } + } + + /** + * Returns a string representation of the constraint. + * + * @return string + * @access public + */ + public function toString() + { + return 'is identical to ' . PHPUnit_Util_Type::toString($this->value); + } +} +?> Property changes on: test/PHPUnit/Framework/Constraint/IsIdentical.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/IncompleteTest.php =================================================================== --- test/PHPUnit/Framework/IncompleteTest.php (revision 0) +++ test/PHPUnit/Framework/IncompleteTest.php (revision 0) @@ -0,0 +1,71 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: IncompleteTest.php 1985 2007-12-26 18:11:55Z 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'); + +if (!interface_exists('PHPUnit_Framework_IncompleteTest', FALSE)) { + +/** + * A marker interface for marking any exception/error as result of an unit + * test as incomplete implementation or currently not implemented. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: 3.2.9 + * @link http://www.phpunit.de/ + * @since Interface available since Release 2.0.0 + */ +interface PHPUnit_Framework_IncompleteTest +{ +} + +} +?> Property changes on: test/PHPUnit/Framework/IncompleteTest.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/SkippedTest.php =================================================================== --- test/PHPUnit/Framework/SkippedTest.php (revision 0) +++ test/PHPUnit/Framework/SkippedTest.php (revision 0) @@ -0,0 +1,70 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: SkippedTest.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/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +if (!interface_exists('PHPUnit_Framework_SkippedTest', FALSE)) { + +/** + * A marker interface for marking a unit test as being skipped. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: 3.2.9 + * @link http://www.phpunit.de/ + * @since Interface available since Release 3.0.0 + */ +interface PHPUnit_Framework_SkippedTest +{ +} + +} +?> Property changes on: test/PHPUnit/Framework/SkippedTest.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/Assert.php =================================================================== --- test/PHPUnit/Framework/Assert.php (revision 0) +++ test/PHPUnit/Framework/Assert.php (revision 0) @@ -0,0 +1,1678 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: Assert.php 1985 2007-12-26 18:11:55Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; +require_once 'PHPUnit/Util/Type.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +if (!class_exists('PHPUnit_Framework_Assert', FALSE)) { + +/** + * A set of assert methods. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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_Framework_Assert +{ + /** + * Asserts that an array has a specified key. + * + * @param mixed $key + * @param array $array + * @param string $message + * @access public + * @static + * @since Method available since Release 3.0.0 + */ + public static function assertArrayHasKey($key, array $array, $message = '') + { + if (!(is_integer($key) || is_string($key))) { + throw new InvalidArgumentException; + } + + $constraint = new PHPUnit_Framework_Constraint_ArrayHasKey($key); + + self::assertThat($array, $constraint, $message); + } + + /** + * Asserts that an array does not have a specified key. + * + * @param mixed $key + * @param array $array + * @param string $message + * @access public + * @static + * @since Method available since Release 3.0.0 + */ + public static function assertArrayNotHasKey($key, array $array, $message = '') + { + if (!(is_integer($key) || is_string($key))) { + throw new InvalidArgumentException; + } + + $constraint = new PHPUnit_Framework_Constraint_Not( + new PHPUnit_Framework_Constraint_ArrayHasKey($key) + ); + + self::assertThat($array, $constraint, $message); + } + + /** + * Asserts that a haystack contains a needle. + * + * @param mixed $needle + * @param mixed $haystack + * @param string $message + * @access public + * @static + * @since Method available since Release 2.1.0 + */ + public static function assertContains($needle, $haystack, $message = '') + { + if (is_array($haystack) || + is_object($haystack) && $haystack instanceof Iterator) { + $constraint = new PHPUnit_Framework_Constraint_TraversableContains($needle); + } + + else if (is_string($haystack)) { + $constraint = new PHPUnit_Framework_Constraint_StringContains($needle); + } + + else { + throw new InvalidArgumentException; + } + + self::assertThat($haystack, $constraint, $message); + } + + /** + * Asserts that a haystack that is stored in a static attribute of a class + * or an attribute of an object contains a needle. + * + * @param mixed $needle + * @param string $haystackAttributeName + * @param mixed $haystackClassOrObject + * @param string $message + * @access public + * @static + * @since Method available since Release 3.0.0 + */ + public static function assertAttributeContains($needle, $haystackAttributeName, $haystackClassOrObject, $message = '') + { + self::assertContains( + $needle, + self::readAttribute($haystackClassOrObject, $haystackAttributeName), + $message + ); + } + + /** + * Asserts that a haystack does not contain a needle. + * + * @param mixed $needle + * @param mixed $haystack + * @param string $message + * @access public + * @static + * @since Method available since Release 2.1.0 + */ + public static function assertNotContains($needle, $haystack, $message = '') + { + if (is_array($haystack) || + is_object($haystack) && $haystack instanceof Iterator) { + $constraint = new PHPUnit_Framework_Constraint_Not( + new PHPUnit_Framework_Constraint_TraversableContains($needle) + ); + } + + else if (is_string($haystack)) { + $constraint = new PHPUnit_Framework_Constraint_Not( + new PHPUnit_Framework_Constraint_StringContains($needle) + ); + } + + else { + throw new InvalidArgumentException; + } + + self::assertThat($haystack, $constraint, $message); + } + + /** + * Asserts that a haystack that is stored in a static attribute of a class + * or an attribute of an object does not contain a needle. + * + * @param mixed $needle + * @param string $haystackAttributeName + * @param mixed $haystackClassOrObject + * @param string $message + * @access public + * @static + * @since Method available since Release 3.0.0 + */ + public static function assertAttributeNotContains($needle, $haystackAttributeName, $haystackClassOrObject, $message = '') + { + self::assertNotContains( + $needle, + self::readAttribute($haystackClassOrObject, $haystackAttributeName), + $message + ); + } + + /** + * Asserts that a haystack contains only values of a given type. + * + * @param string $type + * @param mixed $haystack + * @param boolean $isNativeType + * @param string $message + * @access public + * @static + * @since Method available since Release 3.1.4 + */ + public static function assertContainsOnly($type, $haystack, $isNativeType = NULL, $message = '') + { + if (!(is_array($haystack) || + is_object($haystack) && $haystack instanceof Iterator)) { + throw new InvalidArgumentException; + } + + if ($isNativeType == NULL) { + $isNativeType = PHPUnit_Util_Type::isType($type); + } + + self::assertThat( + $haystack, + new PHPUnit_Framework_Constraint_TraversableContainsOnly( + $type, $isNativeType + ), + $message + ); + } + + /** + * Asserts that a haystack that is stored in a static attribute of a class + * or an attribute of an object contains only values of a given type. + * + * @param string $type + * @param string $haystackAttributeName + * @param mixed $haystackClassOrObject + * @param boolean $isNativeType + * @param string $message + * @access public + * @static + * @since Method available since Release 3.1.4 + */ + public static function assertAttributeContainsOnly($type, $haystackAttributeName, $haystackClassOrObject, $isNativeType = NULL, $message = '') + { + self::assertContainsOnly( + $type, + self::readAttribute($haystackClassOrObject, $haystackAttributeName), + $isNativeType, + $message + ); + } + + /** + * Asserts that a haystack does not contain only values of a given type. + * + * @param string $type + * @param mixed $haystack + * @param boolean $isNativeType + * @param string $message + * @access public + * @static + * @since Method available since Release 3.1.4 + */ + public static function assertNotContainsOnly($type, $haystack, $isNativeType = NULL, $message = '') + { + if (!(is_array($haystack) || + is_object($haystack) && $haystack instanceof Iterator)) { + throw new InvalidArgumentException; + } + + if ($isNativeType == NULL) { + $isNativeType = PHPUnit_Util_Type::isType($type); + } + + self::assertThat( + $haystack, + new PHPUnit_Framework_Constraint_Not( + new PHPUnit_Framework_Constraint_TraversableContainsOnly( + $type, $isNativeType + ) + ), + $message + ); + } + + /** + * Asserts that a haystack that is stored in a static attribute of a class + * or an attribute of an object does not contain only values of a given type. + * + * @param string $type + * @param string $haystackAttributeName + * @param mixed $haystackClassOrObject + * @param boolean $isNativeType + * @param string $message + * @access public + * @static + * @since Method available since Release 3.1.4 + */ + public static function assertAttributeNotContainsOnly($type, $haystackAttributeName, $haystackClassOrObject, $isNativeType = NULL, $message = '') + { + self::assertNotContainsOnly( + $type, + self::readAttribute($haystackClassOrObject, $haystackAttributeName), + $isNativeType, + $message + ); + } + + /** + * Asserts that two variables are equal. + * + * @param mixed $expected + * @param mixed $actual + * @param string $message + * @param float $delta + * @param integer $maxDepth + * @access public + * @static + */ + public static function assertEquals($expected, $actual, $message = '', $delta = 0, $maxDepth = 10) + { + $constraint = new PHPUnit_Framework_Constraint_IsEqual( + $expected, + $delta, + $maxDepth + ); + + self::assertThat($actual, $constraint, $message); + } + + /** + * Asserts that a variable is equal to an attribute of an object. + * + * @param mixed $expected + * @param string $actualAttributeName + * @param string $actualClassOrObject + * @param string $message + * @param float $delta + * @param integer $maxDepth + * @access public + * @static + */ + public static function assertAttributeEquals($expected, $actualAttributeName, $actualClassOrObject, $message = '', $delta = 0, $maxDepth = 10) + { + self::assertEquals( + $expected, + self::readAttribute($actualClassOrObject, $actualAttributeName), + $message, + $delta, + $maxDepth + ); + } + + /** + * Asserts that two variables are not equal. + * + * @param mixed $expected + * @param mixed $actual + * @param string $message + * @param float $delta + * @param integer $maxDepth + * @access public + * @static + * @since Method available since Release 2.3.0 + */ + public static function assertNotEquals($expected, $actual, $message = '', $delta = 0, $maxDepth = 10) + { + $constraint = new PHPUnit_Framework_Constraint_Not( + new PHPUnit_Framework_Constraint_IsEqual( + $expected, + $delta, + $maxDepth + ) + ); + + self::assertThat($actual, $constraint, $message); + } + + /** + * Asserts that a variable is not equal to an attribute of an object. + * + * @param mixed $expected + * @param string $actualAttributeName + * @param string $actualClassOrObject + * @param string $message + * @param float $delta + * @param integer $maxDepth + * @access public + * @static + */ + public static function assertAttributeNotEquals($expected, $actualAttributeName, $actualClassOrObject, $message = '', $delta = 0, $maxDepth = 10) + { + self::assertNotEquals( + $expected, + self::readAttribute($actualClassOrObject, $actualAttributeName), + $message, + $delta, + $maxDepth + ); + } + + /** + * Asserts that a value is greater than another value. + * + * @param mixed $expected + * @param mixed $actual + * @param string $message + * @access public + * @static + * @since Method available since Release 3.1.0 + */ + public static function assertGreaterThan($expected, $actual, $message = '') + { + self::assertThat($actual, self::greaterThan($expected), $message); + } + + /** + * Asserts that an attribute is greater than another value. + * + * @param mixed $expected + * @param string $actualAttributeName + * @param string $actualClassOrObject + * @param string $message + * @access public + * @static + * @since Method available since Release 3.1.0 + */ + public static function assertAttributeGreaterThan($expected, $actualAttributeName, $actualClassOrObject, $message = '') + { + self::assertGreaterThan( + $expected, + self::readAttribute($actualClassOrObject, $actualAttributeName), + $message + ); + } + + /** + * Asserts that a value is greater than or equal to another value. + * + * @param mixed $expected + * @param mixed $actual + * @param string $message + * @access public + * @static + * @since Method available since Release 3.1.0 + */ + public static function assertGreaterThanOrEqual($expected, $actual, $message = '') + { + self::assertThat($actual, self::greaterThanOrEqual($expected), $message); + } + + /** + * Asserts that an attribute is greater than or equal to another value. + * + * @param mixed $expected + * @param string $actualAttributeName + * @param string $actualClassOrObject + * @param string $message + * @access public + * @static + * @since Method available since Release 3.1.0 + */ + public static function assertAttributeGreaterThanOrEqual($expected, $actualAttributeName, $actualClassOrObject, $message = '') + { + self::assertGreaterThanOrEqual( + $expected, + self::readAttribute($actualClassOrObject, $actualAttributeName), + $message + ); + } + + /** + * Asserts that a value is smaller than another value. + * + * @param mixed $expected + * @param mixed $actual + * @param string $message + * @access public + * @static + * @since Method available since Release 3.1.0 + */ + public static function assertLessThan($expected, $actual, $message = '') + { + self::assertThat($actual, self::lessThan($expected), $message); + } + + /** + * Asserts that an attribute is smaller than another value. + * + * @param mixed $expected + * @param string $actualAttributeName + * @param string $actualClassOrObject + * @param string $message + * @access public + * @static + * @since Method available since Release 3.1.0 + */ + public static function assertAttributeLessThan($expected, $actualAttributeName, $actualClassOrObject, $message = '') + { + self::assertLessThan( + $expected, + self::readAttribute($actualClassOrObject, $actualAttributeName), + $message + ); + } + + /** + * Asserts that a value is smaller than or equal to another value. + * + * @param mixed $expected + * @param mixed $actual + * @param string $message + * @access public + * @static + * @since Method available since Release 3.1.0 + */ + public static function assertLessThanOrEqual($expected, $actual, $message = '') + { + self::assertThat($actual, self::lessThanOrEqual($expected), $message); + } + + /** + * Asserts that an attribute is smaller than or equal to another value. + * + * @param mixed $expected + * @param string $actualAttributeName + * @param string $actualClassOrObject + * @param string $message + * @access public + * @static + * @since Method available since Release 3.1.0 + */ + public static function assertAttributeLessThanOrEqual($expected, $actualAttributeName, $actualClassOrObject, $message = '') + { + self::assertLessThanOrEqual( + $expected, + self::readAttribute($actualClassOrObject, $actualAttributeName), + $message + ); + } + + /** + * Asserts that a file exists. + * + * @param string $filename + * @param string $message + * @access public + * @static + * @since Method available since Release 3.0.0 + */ + public static function assertFileExists($filename, $message = '') + { + if (!is_string($filename)) { + throw new InvalidArgumentException; + } + + $constraint = new PHPUnit_Framework_Constraint_FileExists; + + self::assertThat($filename, $constraint, $message); + } + + /** + * Asserts that a file does not exist. + * + * @param string $filename + * @param string $message + * @access public + * @static + * @since Method available since Release 3.0.0 + */ + public static function assertFileNotExists($filename, $message = '') + { + if (!is_string($filename)) { + throw new InvalidArgumentException; + } + + $constraint = new PHPUnit_Framework_Constraint_Not( + new PHPUnit_Framework_Constraint_FileExists + ); + + self::assertThat($filename, $constraint, $message); + } + + /** + * Asserts that a condition is true. + * + * @param boolean $condition + * @param string $message + * @throws PHPUnit_Framework_AssertionFailedError + * @access public + * @static + */ + public static function assertTrue($condition, $message = '') + { + if ($condition !== TRUE) { + throw new PHPUnit_Framework_ExpectationFailedException( + sprintf( + 'Failed asserting that %s is true.', + + PHPUnit_Util_Type::toString($condition) + ), + NULL, + $message + ); + } + } + + /** + * Asserts that a condition is false. + * + * @param boolean $condition + * @param string $message + * @throws PHPUnit_Framework_AssertionFailedError + * @access public + * @static + */ + public static function assertFalse($condition, $message = '') + { + if ($condition !== FALSE) { + throw new PHPUnit_Framework_ExpectationFailedException( + sprintf( + 'Failed asserting that %s is false.', + + PHPUnit_Util_Type::toString($condition) + ), + NULL, + $message + ); + } + } + + /** + * Asserts that a variable is not NULL. + * + * @param mixed $actual + * @param string $message + * @access public + * @static + */ + public static function assertNotNull($actual, $message = '') + { + $constraint = new PHPUnit_Framework_Constraint_Not( + new PHPUnit_Framework_Constraint_IsIdentical(NULL) + ); + + self::assertThat($actual, $constraint, $message); + } + + /** + * Asserts that a variable is NULL. + * + * @param mixed $actual + * @param string $message + * @access public + * @static + */ + public static function assertNull($actual, $message = '') + { + $constraint = new PHPUnit_Framework_Constraint_IsIdentical(NULL); + + self::assertThat($actual, $constraint, $message); + } + + /** + * Asserts that a class has a specified attribute. + * + * @param string $attributeName + * @param string $className + * @param string $message + * @access public + * @static + * @since Method available since Release 3.1.0 + */ + public static function assertClassHasAttribute($attributeName, $className, $message = '') + { + if (!is_string($attributeName) || !is_string($className) || !class_exists($className, FALSE)) { + throw new InvalidArgumentException; + } + + $constraint = new PHPUnit_Framework_Constraint_ClassHasAttribute($attributeName); + + self::assertThat($className, $constraint, $message); + } + + /** + * Asserts that a class does not have a specified attribute. + * + * @param string $attributeName + * @param string $className + * @param string $message + * @access public + * @static + * @since Method available since Release 3.1.0 + */ + public static function assertClassNotHasAttribute($attributeName, $className, $message = '') + { + if (!is_string($attributeName) || !is_string($className) || !class_exists($className)) { + throw new InvalidArgumentException; + } + + $constraint = new PHPUnit_Framework_Constraint_Not( + new PHPUnit_Framework_Constraint_ClassHasAttribute($attributeName) + ); + + self::assertThat($className, $constraint, $message); + } + + /** + * Asserts that a class has a specified static attribute. + * + * @param string $attributeName + * @param string $className + * @param string $message + * @access public + * @static + * @since Method available since Release 3.1.0 + */ + public static function assertClassHasStaticAttribute($attributeName, $className, $message = '') + { + if (!is_string($attributeName) || !is_string($className) || !class_exists($className)) { + throw new InvalidArgumentException; + } + + $constraint = new PHPUnit_Framework_Constraint_ClassHasStaticAttribute($attributeName); + + self::assertThat($className, $constraint, $message); + } + + /** + * Asserts that a class does not have a specified static attribute. + * + * @param string $attributeName + * @param string $className + * @param string $message + * @access public + * @static + * @since Method available since Release 3.1.0 + */ + public static function assertClassNotHasStaticAttribute($attributeName, $className, $message = '') + { + if (!is_string($attributeName) || !is_string($className) || !class_exists($className)) { + throw new InvalidArgumentException; + } + + $constraint = new PHPUnit_Framework_Constraint_Not( + new PHPUnit_Framework_Constraint_ClassHasStaticAttribute($attributeName) + ); + + self::assertThat($className, $constraint, $message); + } + + /** + * Asserts that an object has a specified attribute. + * + * @param string $attributeName + * @param object $object + * @param string $message + * @access public + * @static + * @since Method available since Release 3.0.0 + */ + public static function assertObjectHasAttribute($attributeName, $object, $message = '') + { + if (!is_string($attributeName) || !is_object($object)) { + throw new InvalidArgumentException; + } + + $constraint = new PHPUnit_Framework_Constraint_ObjectHasAttribute($attributeName); + + self::assertThat($object, $constraint, $message); + } + + /** + * Asserts that an object does not have a specified attribute. + * + * @param string $attributeName + * @param object $object + * @param string $message + * @access public + * @static + * @since Method available since Release 3.0.0 + */ + public static function assertObjectNotHasAttribute($attributeName, $object, $message = '') + { + if (!is_string($attributeName) || !is_object($object)) { + throw new InvalidArgumentException; + } + + $constraint = new PHPUnit_Framework_Constraint_Not( + new PHPUnit_Framework_Constraint_ObjectHasAttribute($attributeName) + ); + + self::assertThat($object, $constraint, $message); + } + + /** + * Asserts that two variables have the same type and value. + * Used on objects, it asserts that two variables reference + * the same object. + * + * @param mixed $expected + * @param mixed $actual + * @param string $message + * @access public + * @static + */ + public static function assertSame($expected, $actual, $message = '') + { + if (is_bool($expected) && is_bool($actual)) { + self::assertEquals($expected, $actual); + } else { + $constraint = new PHPUnit_Framework_Constraint_IsIdentical($expected); + + self::assertThat($actual, $constraint, $message); + } + } + + /** + * Asserts that a variable and an attribute of an object have the same type + * and value. + * + * @param mixed $expected + * @param string $actualAttributeName + * @param object $actualClassOrObject + * @param string $message + * @access public + * @static + */ + public static function assertAttributeSame($expected, $actualAttributeName, $actualClassOrObject, $message = '') + { + self::assertSame( + $expected, + self::readAttribute($actualClassOrObject, $actualAttributeName), + $message + ); + } + + /** + * Asserts that two variables do not have the same type and value. + * Used on objects, it asserts that two variables do not reference + * the same object. + * + * @param mixed $expected + * @param mixed $actual + * @param string $message + * @access public + * @static + */ + public static function assertNotSame($expected, $actual, $message = '') + { + if (is_bool($expected) && is_bool($actual)) { + self::assertNotEquals($expected, $actual); + } else { + $constraint = new PHPUnit_Framework_Constraint_Not( + new PHPUnit_Framework_Constraint_IsIdentical($expected) + ); + + self::assertThat($actual, $constraint, $message); + } + } + + /** + * Asserts that a variable and an attribute of an object do not have the + * same type and value. + * + * @param mixed $expected + * @param string $actualAttributeName + * @param object $actualClassOrObject + * @param string $message + * @access public + * @static + */ + public static function assertAttributeNotSame($expected, $actualAttributeName, $actualClassOrObject, $message = '') + { + self::assertNotSame( + $expected, + self::readAttribute($actualClassOrObject, $actualAttributeName), + $message + ); + } + + /** + * Asserts that a variable is of a given type. + * + * @param string $expected + * @param mixed $actual + * @param string $message + * @access public + * @static + */ + public static function assertType($expected, $actual, $message = '') + { + if (is_string($expected)) { + if (PHPUnit_Util_Type::isType($expected)) { + $constraint = new PHPUnit_Framework_Constraint_IsType($expected); + } + + else if (class_exists($expected) || interface_exists($expected)) { + $constraint = new PHPUnit_Framework_Constraint_IsInstanceOf( + $expected + ); + } + + else { + throw new InvalidArgumentException; + } + } else { + throw new InvalidArgumentException; + } + + self::assertThat($actual, $constraint, $message); + } + + /** + * Asserts that a variable is not of a given type. + * + * @param string $expected + * @param mixed $actual + * @param string $message + * @access public + * @static + * @since Method available since Release 2.2.0 + */ + public static function assertNotType($expected, $actual, $message = '') + { + if (is_string($expected)) { + if (PHPUnit_Util_Type::isType($expected)) { + $constraint = new PHPUnit_Framework_Constraint_Not( + new PHPUnit_Framework_Constraint_IsType($expected) + ); + } + + else if (class_exists($expected) || interface_exists($expected)) { + $constraint = new PHPUnit_Framework_Constraint_Not( + new PHPUnit_Framework_Constraint_IsInstanceOf($expected) + ); + } + + else { + throw new InvalidArgumentException; + } + } else { + throw new InvalidArgumentException; + } + + self::assertThat($actual, $constraint, $message); + } + + /** + * Asserts that a string matches a given regular expression. + * + * @param string $pattern + * @param string $string + * @param string $message + * @access public + * @static + */ + public static function assertRegExp($pattern, $string, $message = '') + { + if (!is_string($pattern) || !is_string($string)) { + throw new InvalidArgumentException; + } + + $constraint = new PHPUnit_Framework_Constraint_PCREMatch($pattern); + + self::assertThat($string, $constraint, $message); + } + + /** + * Asserts that a string does not match a given regular expression. + * + * @param string $pattern + * @param string $string + * @param string $message + * @access public + * @static + * @since Method available since Release 2.1.0 + */ + public static function assertNotRegExp($pattern, $string, $message = '') + { + if (!is_string($pattern) || !is_string($string)) { + throw new InvalidArgumentException; + } + + $constraint = new PHPUnit_Framework_Constraint_Not( + new PHPUnit_Framework_Constraint_PCREMatch($pattern) + ); + + self::assertThat($string, $constraint, $message); + } + + /** + * Asserts that two XML files are equal. + * + * @param string $expectedFile + * @param string $actualFile + * @param string $message + * @access public + * @static + * @since Method available since Release 3.1.0 + */ + public static function assertXmlFileEqualsXmlFile($expectedFile, $actualFile, $message = '') + { + self::assertFileExists($expectedFile); + self::assertFileExists($actualFile); + + $expected = new DOMDocument; + $expected->load($expectedFile); + + $actual = new DOMDocument; + $actual->load($actualFile); + + self::assertEquals($expected, $actual, $message); + } + + /** + * Asserts that two XML files are not equal. + * + * @param string $expectedFile + * @param string $actualFile + * @param string $message + * @access public + * @static + * @since Method available since Release 3.1.0 + */ + public static function assertXmlFileNotEqualsXmlFile($expectedFile, $actualFile, $message = '') + { + self::assertFileExists($expectedFile); + self::assertFileExists($actualFile); + + $expected = new DOMDocument; + $expected->load($expectedFile); + + $actual = new DOMDocument; + $actual->load($actualFile); + + self::assertNotEquals($expected, $actual, $message); + } + + /** + * Asserts that two XML documents are equal. + * + * @param string $expectedXml + * @param string $actualXml + * @param string $message + * @access public + * @static + * @since Method available since Release 3.1.0 + */ + public static function assertXmlStringEqualsXmlString($expectedXml, $actualXml, $message = '') + { + $expected = new DOMDocument; + $expected->loadXML($expectedXml); + + $actual = new DOMDocument; + $actual->loadXML($actualXml); + + self::assertEquals($expected, $actual, $message); + } + + /** + * Asserts that two XML documents are not equal. + * + * @param string $expectedXml + * @param string $actualXml + * @param string $message + * @access public + * @static + * @since Method available since Release 3.1.0 + */ + public static function assertXmlStringNotEqualsXmlString($expectedXml, $actualXml, $message = '') + { + $expected = new DOMDocument; + $expected->loadXML($expectedXml); + + $actual = new DOMDocument; + $actual->loadXML($actualXml); + + self::assertNotEquals($expected, $actual, $message); + } + + /** + * + * + * @param mixed $value + * @param PHPUnit_Framework_Constraint $constraint + * @param string $message + * @access public + * @static + * @since Method available since Release 3.0.0 + */ + public static function assertThat($value, PHPUnit_Framework_Constraint $constraint, $message = '') + { + if (!$constraint->evaluate($value)) { + $constraint->fail($value, $message); + } + } + + /** + * Logical AND. + * + * @return PHPUnit_Framework_Constraint_And + * @access public + * @since Method available since Release 3.0.0 + * @static + */ + public static function logicalAnd() + { + $constraints = func_get_args(); + + $constraint = new PHPUnit_Framework_Constraint_And; + $constraint->setConstraints($constraints); + + return $constraint; + } + + /** + * Logical OR. + * + * @return PHPUnit_Framework_Constraint_Or + * @access public + * @since Method available since Release 3.0.0 + * @static + */ + public static function logicalOr() + { + $constraints = func_get_args(); + + $constraint = new PHPUnit_Framework_Constraint_Or; + $constraint->setConstraints($constraints); + + return $constraint; + } + + /** + * Logical NOT. + * + * @param PHPUnit_Framework_Constraint $constraint + * @return PHPUnit_Framework_Constraint_Not + * @access public + * @since Method available since Release 3.0.0 + * @static + */ + public static function logicalNot(PHPUnit_Framework_Constraint $constraint) + { + return new PHPUnit_Framework_Constraint_Not($constraint); + } + + /** + * Logical XOR. + * + * @return PHPUnit_Framework_Constraint_Xor + * @access public + * @since Method available since Release 3.0.0 + * @static + */ + public static function logicalXor() + { + $constraints = func_get_args(); + + $constraint = new PHPUnit_Framework_Constraint_Xor; + $constraint->setConstraints($constraints); + + return $constraint; + } + + /** + * + * + * @return PHPUnit_Framework_Constraint_IsAnything + * @access public + * @since Method available since Release 3.0.0 + * @static + */ + public static function anything() + { + return new PHPUnit_Framework_Constraint_IsAnything; + } + + /** + * + * + * @param PHPUnit_Framework_Constraint $constraint + * @param string $attributeName + * @return PHPUnit_Framework_Constraint_Attribute + * @access public + * @since Method available since Release 3.1.0 + * @static + */ + public static function attribute(PHPUnit_Framework_Constraint $constraint, $attributeName) + { + return new PHPUnit_Framework_Constraint_Attribute( + $constraint, $attributeName + ); + } + + /** + * + * + * @param mixed $value + * @return PHPUnit_Framework_Constraint_TraversableContains + * @access public + * @since Method available since Release 3.0.0 + * @static + */ + public static function contains($value) + { + return new PHPUnit_Framework_Constraint_TraversableContains($value); + } + + /** + * + * + * @param string $type + * @return PHPUnit_Framework_Constraint_TraversableContainsOnly + * @access public + * @since Method available since Release 3.1.4 + * @static + */ + public static function containsOnly($type) + { + return new PHPUnit_Framework_Constraint_TraversableContainsOnly($type); + } + + /** + * + * + * @param mixed $key + * @return PHPUnit_Framework_Constraint_ArrayHasKey + * @access public + * @since Method available since Release 3.0.0 + * @static + */ + public static function arrayHasKey($key) + { + return new PHPUnit_Framework_Constraint_ArrayHasKey($key); + } + + /** + * + * + * @param mixed $value + * @param float $delta + * @param integer $maxDepth + * @return PHPUnit_Framework_Constraint_IsEqual + * @access public + * @since Method available since Release 3.0.0 + * @static + */ + public static function equalTo($value, $delta = 0, $maxDepth = 10) + { + return new PHPUnit_Framework_Constraint_IsEqual($value, $delta, $maxDepth); + } + + /** + * + * + * @param string $attributeName + * @param mixed $value + * @param float $delta + * @param integer $maxDepth + * @return PHPUnit_Framework_Constraint_Attribute + * @access public + * @since Method available since Release 3.1.0 + * @static + */ + public static function attributeEqualTo($attributeName, $value, $delta = 0, $maxDepth = 10) + { + return new PHPUnit_Framework_Constraint_Attribute( + new PHPUnit_Framework_Constraint_IsEqual($value, $delta, $maxDepth), + $attributeName + ); + } + + /** + * + * + * @return PHPUnit_Framework_Constraint_FileExists + * @access public + * @since Method available since Release 3.0.0 + * @static + */ + public static function fileExists() + { + return new PHPUnit_Framework_Constraint_FileExists; + } + + /** + * + * + * @param mixed $value + * @return PHPUnit_Framework_Constraint_GreaterThan + * @access public + * @since Method available since Release 3.0.0 + * @static + */ + public static function greaterThan($value) + { + return new PHPUnit_Framework_Constraint_GreaterThan($value); + } + + /** + * + * + * @param mixed $value + * @return PHPUnit_Framework_Constraint_Or + * @access public + * @since Method available since Release 3.1.0 + * @static + */ + public static function greaterThanOrEqual($value) + { + return self::logicalOr( + new PHPUnit_Framework_Constraint_IsEqual($value), + new PHPUnit_Framework_Constraint_GreaterThan($value) + ); + } + + /** + * + * + * @param string $attributeName + * @return PHPUnit_Framework_Constraint_ClassHasAttribute + * @access public + * @since Method available since Release 3.1.0 + * @static + */ + public static function classHasAttribute($attributeName) + { + return new PHPUnit_Framework_Constraint_ClassHasAttribute($attributeName); + } + + /** + * + * + * @param string $attributeName + * @return PHPUnit_Framework_Constraint_ClassHasStaticAttribute + * @access public + * @since Method available since Release 3.1.0 + * @static + */ + public static function classHasStaticAttribute($attributeName) + { + return new PHPUnit_Framework_Constraint_ClassHasStaticAttribute($attributeName); + } + + /** + * + * + * @param string $attributeName + * @return PHPUnit_Framework_Constraint_ObjectHasAttribute + * @access public + * @since Method available since Release 3.0.0 + * @static + */ + public static function objectHasAttribute($attributeName) + { + return new PHPUnit_Framework_Constraint_ObjectHasAttribute($attributeName); + } + + /** + * + * + * @param mixed $value + * @return PHPUnit_Framework_Constraint_IsIdentical + * @access public + * @since Method available since Release 3.0.0 + * @static + */ + public static function identicalTo($value) + { + return new PHPUnit_Framework_Constraint_IsIdentical($value); + } + + /** + * + * + * @param string $className + * @return PHPUnit_Framework_Constraint_IsInstanceOf + * @access public + * @since Method available since Release 3.0.0 + * @static + */ + public static function isInstanceOf($className) + { + return new PHPUnit_Framework_Constraint_IsInstanceOf($className); + } + + /** + * + * + * @param string $type + * @return PHPUnit_Framework_Constraint_IsType + * @access public + * @since Method available since Release 3.0.0 + * @static + */ + public static function isType($type) + { + return new PHPUnit_Framework_Constraint_IsType($type); + } + + /** + * + * + * @param mixed $value + * @return PHPUnit_Framework_Constraint_LessThan + * @access public + * @since Method available since Release 3.0.0 + * @static + */ + public static function lessThan($value) + { + return new PHPUnit_Framework_Constraint_LessThan($value); + } + + /** + * + * + * @param mixed $value + * @return PHPUnit_Framework_Constraint_Or + * @access public + * @since Method available since Release 3.1.0 + * @static + */ + public static function lessThanOrEqual($value) + { + return self::logicalOr( + new PHPUnit_Framework_Constraint_IsEqual($value), + new PHPUnit_Framework_Constraint_LessThan($value) + ); + } + + /** + * + * + * @param string $pattern + * @return PHPUnit_Framework_Constraint_PCREMatch + * @access public + * @since Method available since Release 3.0.0 + * @static + */ + public static function matchesRegularExpression($pattern) + { + return new PHPUnit_Framework_Constraint_PCREMatch($pattern); + } + + /** + * + * + * @param string $string + * @param boolean $case + * @return PHPUnit_Framework_Constraint_StringContains + * @access public + * @since Method available since Release 3.0.0 + * @static + */ + public static function stringContains($string, $case = TRUE) + { + return new PHPUnit_Framework_Constraint_StringContains($string, $case); + } + + + /** + * Fails a test with the given message. + * + * @param string $message + * @throws PHPUnit_Framework_AssertionFailedError + * @access public + * @static + */ + public static function fail($message = '') + { + throw new PHPUnit_Framework_AssertionFailedError($message); + } + + /** + * Returns the value of an attribute of a class or an object. + * This also works for attributes that are declared protected or private. + * + * @param mixed $classOrObject + * @param string $attributeName + * @return mixed + * @throws InvalidArgumentException + * @access protected + * @static + */ + public static function readAttribute($classOrObject, $attributeName) + { + if (!is_string($attributeName)) { + throw new InvalidArgumentException; + } + + if (is_string($classOrObject)) { + if (!class_exists($classOrObject)) { + throw new InvalidArgumentException; + } + + return self::getStaticAttribute( + $classOrObject, + $attributeName + ); + } + + else if (is_object($classOrObject)) { + return self::getObjectAttribute( + $classOrObject, + $attributeName + ); + } + + else { + throw new InvalidArgumentException; + } + } + + /** + * Returns the value of a static attribute. + * This also works for attributes that are declared protected or private. + * + * @param string $className + * @param string $attributeName + * @return mixed + * @throws InvalidArgumentException + * @access public + * @static + * @since Method available since Release 3.1.0 + */ + public static function getStaticAttribute($className, $attributeName) + { + if (!is_string($className) || !class_exists($className) || !is_string($attributeName)) { + throw new InvalidArgumentException; + } + + $class = new ReflectionClass($className); + $attributes = $class->getStaticProperties(); + + if (isset($attributes[$attributeName])) { + return $attributes[$attributeName]; + } + + if (version_compare(PHP_VERSION, '5.2', '<')) { + $protectedName = "\0*\0" . $attributeName; + } else { + $protectedName = '*' . $attributeName; + } + + if (isset($attributes[$protectedName])) { + return $attributes[$protectedName]; + } + + $classes = PHPUnit_Util_Class::getHierarchy($className); + + foreach ($classes as $class) { + $privateName = sprintf( + "\0%s\0%s", + + $class, + $attributeName + ); + + if (isset($attributes[$privateName])) { + return $attributes[$privateName]; + } + } + + throw new RuntimeException( + sprintf( + 'Attribute "%s" not found in class.', + + $attributeName + ) + ); + } + + /** + * Returns the value of an object's attribute. + * This also works for attributes that are declared protected or private. + * + * @param object $object + * @param string $attributeName + * @return mixed + * @throws InvalidArgumentException + * @access public + * @static + * @since Method available since Release 3.1.0 + */ + public static function getObjectAttribute($object, $attributeName) + { + if (!is_object($object) || !is_string($attributeName)) { + throw new InvalidArgumentException; + } + + self::assertObjectHasAttribute($attributeName, $object); + + if (property_exists($object, $attributeName)) { + return $object->$attributeName; + } else { + $array = (array) $object; + $protectedName = "\0*\0" . $attributeName; + + if (array_key_exists($protectedName, $array)) { + return $array[$protectedName]; + } else { + $classes = PHPUnit_Util_Class::getHierarchy(get_class($object)); + + foreach ($classes as $class) { + $privateName = sprintf( + "\0%s\0%s", + + $class, + $attributeName + ); + + if (array_key_exists($privateName, $array)) { + return $array[$privateName]; + } + } + } + } + + throw new RuntimeException( + sprintf( + 'Attribute "%s" not found in object.', + + $attributeName + ) + ); + } + + /** + * Mark the test as incomplete. + * + * @param string $message + * @throws PHPUnit_Framework_IncompleteTestError + * @access public + * @static + * @since Method available since Release 3.0.0 + */ + public static function markTestIncomplete($message = '') + { + throw new PHPUnit_Framework_IncompleteTestError($message); + } + + /** + * Mark the test as skipped. + * + * @param string $message + * @throws PHPUnit_Framework_SkippedTestError + * @access public + * @static + * @since Method available since Release 3.0.0 + */ + public static function markTestSkipped($message = '') + { + throw new PHPUnit_Framework_SkippedTestError($message); + } +} + +} +?> Property changes on: test/PHPUnit/Framework/Assert.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/Warning.php =================================================================== --- test/PHPUnit/Framework/Warning.php (revision 0) +++ test/PHPUnit/Framework/Warning.php (revision 0) @@ -0,0 +1,104 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: Warning.php 1985 2007-12-26 18:11:55Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +if (!class_exists('PHPUnit_Framework_Warning', FALSE)) { + +/** + * A warning. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class PHPUnit_Framework_Warning extends PHPUnit_Framework_TestCase +{ + /** + * @var string + * @access protected + */ + protected $message = ''; + + /** + * @param string $message + * @access public + */ + public function __construct($message = '') + { + $this->message = $message; + parent::__construct('Warning'); + } + + /** + * @access protected + */ + protected function runTest() + { + $this->fail($this->message); + } + + /** + * @return string + * @access public + * @since Method available since Release 3.0.0 + */ + public function getMessage() + { + return $this->message; + } +} + +} +?> Property changes on: test/PHPUnit/Framework/Warning.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/ExpectationFailedException.php =================================================================== --- test/PHPUnit/Framework/ExpectationFailedException.php (revision 0) +++ test/PHPUnit/Framework/ExpectationFailedException.php (revision 0) @@ -0,0 +1,99 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: ExpectationFailedException.php 2108 2008-01-15 09:10:37Z 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'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +if (!class_exists('PHPUnit_Framework_ExpectationFailedException', FALSE)) { + +/** + * Exception for expectations which failed their check. + * + * The exception contains the error message and optionally a + * PHPUnit_Framework_ComparisonFailure which is used to + * generate diff output of the failed expectations. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class PHPUnit_Framework_ExpectationFailedException extends PHPUnit_Framework_AssertionFailedError +{ + protected $comparisonFailure; + protected $description; + + public function __construct($description, PHPUnit_Framework_ComparisonFailure $comparisonFailure = NULL, $message = '') + { + $this->description = $description; + $this->comparisonFailure = $comparisonFailure; + + if (!empty($message)) { + $description .= "\n" . $message; + } + + parent::__construct($description); + } + + public function getComparisonFailure() + { + return $this->comparisonFailure; + } + + public function getDescription() + { + return $this->description; + } +} + +} +?> Property changes on: test/PHPUnit/Framework/ExpectationFailedException.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/IncompleteTestError.php =================================================================== --- test/PHPUnit/Framework/IncompleteTestError.php (revision 0) +++ test/PHPUnit/Framework/IncompleteTestError.php (revision 0) @@ -0,0 +1,72 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: IncompleteTestError.php 1985 2007-12-26 18:11:55Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +if (!class_exists('PHPUnit_Framework_IncompleteTestError', FALSE)) { + +/** + * Extension to PHPUnit_Framework_AssertionFailedError to mark the special + * case of an incomplete test. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class PHPUnit_Framework_IncompleteTestError extends PHPUnit_Framework_AssertionFailedError implements PHPUnit_Framework_IncompleteTest +{ +} + +} +?> Property changes on: test/PHPUnit/Framework/IncompleteTestError.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/SkippedTestError.php =================================================================== --- test/PHPUnit/Framework/SkippedTestError.php (revision 0) +++ test/PHPUnit/Framework/SkippedTestError.php (revision 0) @@ -0,0 +1,72 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: SkippedTestError.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'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +if (!class_exists('PHPUnit_Framework_SkippedTestError', FALSE)) { + +/** + * Extension to PHPUnit_Framework_AssertionFailedError to mark the special + * case of a skipped test. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class PHPUnit_Framework_SkippedTestError extends PHPUnit_Framework_AssertionFailedError implements PHPUnit_Framework_SkippedTest +{ +} + +} +?> Property changes on: test/PHPUnit/Framework/SkippedTestError.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/TestCase.php =================================================================== --- test/PHPUnit/Framework/TestCase.php (revision 0) +++ test/PHPUnit/Framework/TestCase.php (revision 0) @@ -0,0 +1,863 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: TestCase.php 2135 2008-01-17 10:45:15Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit/Framework.php'; +require_once 'PHPUnit/Framework/MockObject/Mock.php'; +require_once 'PHPUnit/Framework/MockObject/Matcher/InvokedAtLeastOnce.php'; +require_once 'PHPUnit/Framework/MockObject/Matcher/InvokedAtIndex.php'; +require_once 'PHPUnit/Framework/MockObject/Matcher/InvokedCount.php'; +require_once 'PHPUnit/Framework/MockObject/Stub.php'; +require_once 'PHPUnit/Runner/BaseTestRunner.php'; +require_once 'PHPUnit/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +if (!class_exists('PHPUnit_Framework_TestCase', FALSE)) { + +/** + * A TestCase defines the fixture to run multiple tests. + * + * To define a TestCase + * + * 1) Implement a subclass of PHPUnit_Framework_TestCase. + * 2) Define instance variables that store the state of the fixture. + * 3) Initialize the fixture state by overriding setUp(). + * 4) Clean-up after a test by overriding tearDown(). + * + * Each test runs in its own fixture so there can be no side effects + * among test runs. + * + * Here is an example: + * + * + * value1 = 2; + * $this->value2 = 3; + * } + * } + * ?> + * + * + * For each test implement a method which interacts with the fixture. + * Verify the expected results with assertions specified by calling + * assert with a boolean. + * + * + * assertTrue($this->value1 + $this->value2 == 5); + * } + * ?> + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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_Framework_TestCase extends PHPUnit_Framework_Assert implements PHPUnit_Framework_Test, PHPUnit_Framework_SelfDescribing +{ + /** + * Enable or disable the backup and restoration of the $GLOBALS array. + * Overwrite this attribute in a child class of TestCase. + * Setting this attribute in setUp() has no effect! + * + * @var boolean + * @access protected + */ + protected $backupGlobals = TRUE; + + /** + * Enable or disable creating the $GLOBALS reference that is required + * for the "global" keyword to work correctly. + * Overwrite this attribute in a child class of TestCase. + * Setting this attribute in setUp() has no effect! + * + * @var boolean + * @access protected + */ + protected $createGlobalsReference = FALSE; + + /** + * @var array + * @access protected + */ + protected $data = array(); + + /** + * @var string + * @access protected + */ + protected $dataName = ''; + + /** + * The name of the expected Exception. + * + * @var mixed + * @access protected + */ + protected $expectedException = NULL; + + /** + * The message of the expected Exception. + * + * @var string + * @access protected + */ + protected $expectedExceptionMessage = ''; + + /** + * Fixture that is shared between the tests of a test suite. + * + * @var mixed + * @access protected + */ + protected $sharedFixture; + + /** + * The name of the test case. + * + * @var string + * @access protected + */ + protected $name = NULL; + + /** + * @var Exception + * @access protected + */ + protected $exception = NULL; + + /** + * @var string + * @access protected + */ + protected $exceptionMessage = NULL; + + /** + * @var integer + * @access protected + */ + protected $exceptionCode = 0; + + /** + * @var Array + * @access protected + */ + protected $iniSettings = array(); + + /** + * @var Array + * @access protected + */ + protected $locale = array(); + + /** + * @var Array + * @access protected + */ + protected $mockObjects = array(); + + /** + * Constructs a test case with the given name. + * + * @param string $name + * @param array $data + * @param string $dataName + * @access public + */ + public function __construct($name = NULL, array $data = array(), $dataName = '') + { + if ($name !== NULL) { + $this->setName($name); + } + + $this->data = $data; + $this->dataName = $dataName; + } + + /** + * Returns a string representation of the test case. + * + * @return string + * @access public + */ + public function toString() + { + $class = new ReflectionClass($this); + + $buffer = sprintf( + '%s(%s)', + + $this->getName(), + $class->name + ); + + if (!empty($this->data)) { + if (is_string($this->dataName)) { + $buffer .= sprintf( + ' with data set "%s"', + + $this->dataName + ); + } else { + $buffer .= sprintf( + ' with data set #%d (%s)', + + $this->dataName, + $this->dataToString($this->data) + ); + } + } + + return $buffer; + } + + /** + * Counts the number of test cases executed by run(TestResult result). + * + * @return integer + * @access public + */ + public function count() + { + return 1; + } + + /** + * Gets the name of a TestCase. + * + * @return string + * @access public + */ + public function getName() + { + return $this->name; + } + + /** + * @return string + * @access public + * @since Method available since Release 3.2.0 + */ + public function getExpectedException() + { + return $this->expectedException; + } + + /** + * @param mixed $exceptionName + * @param string $exceptionMessage + * @param integer $exceptionCode + * @access public + * @since Method available since Release 3.2.0 + */ + public function setExpectedException($exceptionName, $exceptionMessage = '', $exceptionCode = 0) + { + $this->expectedException = $exceptionName; + $this->expectedExceptionMessage = $exceptionMessage; + $this->expectedExceptionCode = $exceptionCode; + } + + /** + * Returns the status of this test. + * + * @return integer + * @since Method available since Release 3.1.0 + */ + public function getStatus() + { + if ($this->exception === NULL) { + return PHPUnit_Runner_BaseTestRunner::STATUS_PASSED; + } + + if ($this->exception instanceof PHPUnit_Framework_IncompleteTest) { + return PHPUnit_Runner_BaseTestRunner::STATUS_INCOMPLETE; + } + + if ($this->exception instanceof PHPUnit_Framework_SkippedTest) { + return PHPUnit_Runner_BaseTestRunner::STATUS_SKIPPED; + } + + if ($this->exception instanceof PHPUnit_Framework_AssertionFailedError) { + return PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE; + } + + return PHPUnit_Runner_BaseTestRunner::STATUS_ERROR; + } + + /** + * Returns whether or not this test has failed. + * + * @return boolean + * @since Method available since Release 3.0.0 + */ + public function hasFailed() + { + $status = $this->getStatus(); + + return $status == PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE || + $status == PHPUnit_Runner_BaseTestRunner::STATUS_ERROR; + } + + /** + * Runs the test case and collects the results in a TestResult object. + * If no TestResult object is passed a new one will be created. + * + * @param PHPUnit_Framework_TestResult $result + * @return PHPUnit_Framework_TestResult + * @throws InvalidArgumentException + * @access public + */ + public function run(PHPUnit_Framework_TestResult $result = NULL) + { + if ($result === NULL) { + $result = $this->createResult(); + } + + $result->run($this); + + return $result; + } + + /** + * Runs the bare test sequence. + * + * @access public + */ + public function runBare() + { + // Backup the $GLOBALS array. + if ($this->backupGlobals === TRUE) { + $globalsBackup = serialize($GLOBALS); + } + + // Set up the fixture. + $this->setUp(); + + // Run the test. + try { + // Assert pre-conditions. + $this->assertPreConditions(); + + $this->runTest(); + + // Assert post-conditions. + $this->assertPostConditions(); + + // Verify Mock Object conditions. + foreach ($this->mockObjects as $mockObject) { + $mockObject->verify(); + } + + $this->mockObjects = array(); + } + + catch (Exception $e) { + $this->exception = $e; + } + + // Tear down the fixture. + $this->tearDown(); + + // Restore the $GLOBALS array. + if ($this->backupGlobals === TRUE) { + $GLOBALS = unserialize($globalsBackup); + + if ($this->createGlobalsReference) { + $GLOBALS['GLOBALS'] = &$GLOBALS; + } + } + + // Clean up INI settings. + foreach ($this->iniSettings as $varName => $oldValue) { + ini_set($varName, $oldValue); + } + + $this->iniSettings = array(); + + // Clean up locale settings. + foreach ($this->locale as $category => $locale) { + setlocale($category, $locale); + } + + // Clean up stat cache. + clearstatcache(); + + // Workaround for missing "finally". + if ($this->exception !== NULL) { + throw $this->exception; + } + } + + /** + * Override to run the test and assert its state. + * + * @throws RuntimeException + * @access protected + */ + protected function runTest() + { + if ($this->name === NULL) { + throw new RuntimeException( + 'PHPUnit_Framework_TestCase::$name must not be NULL.' + ); + } + + try { + $class = new ReflectionClass($this); + $method = $class->getMethod($this->name); + } + + catch (ReflectionException $e) { + $this->fail($e->getMessage()); + } + + try { + if (empty($this->data)) { + $method->invoke($this); + } else { + $method->invokeArgs($this, $this->data); + } + } + + catch (Exception $e) { + if (is_string($this->expectedException) && + $e instanceof $this->expectedException) { + if (is_string($this->expectedExceptionMessage) && + !empty($this->expectedExceptionMessage)) { + $this->assertContains( + $this->expectedExceptionMessage, + $e->getMessage() + ); + } + + if (is_int($this->expectedExceptionCode) && + $this->expectedExceptionCode !== 0) { + $this->assertEquals( + $this->expectedExceptionCode, $e->getCode() + ); + } + + return; + } else { + throw $e; + } + } + + if ($this->expectedException !== NULL) { + $this->fail('Expected exception ' . $this->expectedException); + } + } + + /** + * Sets the name of a TestCase. + * + * @param string + * @access public + */ + public function setName($name) + { + $this->name = $name; + } + + /** + * Sets the shared fixture. + * + * @param mixed $sharedFixture + * @access public + * @since Method available since Release 3.1.0 + */ + public function setSharedFixture($sharedFixture) + { + $this->sharedFixture = $sharedFixture; + } + + /** + * This method is a wrapper for the ini_set() function that automatically + * resets the modified php.ini setting to its original value after the + * test is run. + * + * @param string $varName + * @param string $newValue + * @throws InvalidArgumentException + * @throws RuntimeException + * @access protected + * @since Method available since Release 3.0.0 + */ + protected function iniSet($varName, $newValue) + { + if (!is_string($varName) || !is_string($newValue)) { + throw new InvalidArgumentException; + } + + $currentValue = ini_set($varName, $newValue); + + if ($currentValue !== FALSE) { + $this->iniSettings[$varName] = $currentValue; + } else { + throw new RuntimeException; + } + } + + /** + * This method is a wrapper for the setlocale() function that automatically + * resets the locale to its original value after the test is run. + * + * @param integer $category + * @param string $locale + * @throws InvalidArgumentException + * @throws RuntimeException + * @access protected + * @since Method available since Release 3.1.0 + */ + protected function setLocale() + { + $args = func_get_args(); + + if (count($args) < 2) { + throw new InvalidArgumentException; + } + + $category = $args[0]; + $locale = $args[1]; + + if (!in_array($category, array(LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, LC_NUMERIC, LC_TIME, LC_MESSAGES))) { + throw new InvalidArgumentException; + } + + if (!is_array($locale) && !is_string($locale)) { + throw new InvalidArgumentException; + } + + $this->locale[$category] = setlocale($category, NULL); + + $result = call_user_func_array( 'setlocale', $args ); + + if ($result === FALSE) { + throw new RuntimeException( + 'The locale functionality is not implemented on your platform, ' . + 'the specified locale does not exist or the category name is ' . + 'invalid.' + ); + } + } + + /** + * Returns a mock object for the specified class. + * + * @param string $className + * @param array $methods + * @param array $arguments + * @param string $mockClassName + * @param boolean $callOriginalConstructor + * @param boolean $callOriginalClone + * @param boolean $callAutoload + * @return object + * @access protected + * @since Method available since Release 3.0.0 + */ + protected function getMock($className, array $methods = array(), array $arguments = array(), $mockClassName = '', $callOriginalConstructor = TRUE, $callOriginalClone = TRUE, $callAutoload = TRUE) + { + if (!is_string($className) || !is_string($mockClassName)) { + throw new InvalidArgumentException; + } + + $mock = PHPUnit_Framework_MockObject_Mock::generate( + $className, + $methods, + $mockClassName, + $callOriginalConstructor, + $callOriginalClone, + $callAutoload + ); + + $mockClass = new ReflectionClass($mock->mockClassName); + $mockObject = $mockClass->newInstanceArgs($arguments); + + $this->mockObjects[] = $mockObject; + + return $mockObject; + } + + /** + * Returns a matcher that matches when the method it is evaluated for + * is executed zero or more times. + * + * @return PHPUnit_Framework_MockObject_Matcher_AnyInvokedCount + * @access protected + * @since Method available since Release 3.0.0 + */ + protected function any() + { + return new PHPUnit_Framework_MockObject_Matcher_AnyInvokedCount; + } + + /** + * Returns a matcher that matches when the method it is evaluated for + * is never executed. + * + * @return PHPUnit_Framework_MockObject_Matcher_InvokedCount + * @access protected + * @since Method available since Release 3.0.0 + */ + protected function never() + { + return new PHPUnit_Framework_MockObject_Matcher_InvokedCount(0); + } + + /** + * Returns a matcher that matches when the method it is evaluated for + * is executed at least once. + * + * @return PHPUnit_Framework_MockObject_Matcher_InvokedAtLeastOnce + * @access protected + * @since Method available since Release 3.0.0 + */ + protected function atLeastOnce() + { + return new PHPUnit_Framework_MockObject_Matcher_InvokedAtLeastOnce; + } + + /** + * Returns a matcher that matches when the method it is evaluated for + * is executed exactly once. + * + * @return PHPUnit_Framework_MockObject_Matcher_InvokedCount + * @access protected + * @since Method available since Release 3.0.0 + */ + protected function once() + { + return new PHPUnit_Framework_MockObject_Matcher_InvokedCount(1); + } + + /** + * Returns a matcher that matches when the method it is evaluated for + * is executed exactly $count times. + * + * @param integer $count + * @return PHPUnit_Framework_MockObject_Matcher_InvokedCount + * @access protected + * @since Method available since Release 3.0.0 + */ + protected function exactly($count) + { + return new PHPUnit_Framework_MockObject_Matcher_InvokedCount($count); + } + + /** + * Returns a matcher that matches when the method it is evaluated for + * is invoked at the given $index. + * + * @param integer $index + * @return PHPUnit_Framework_MockObject_Matcher_InvokedAtIndex + * @access protected + * @since Method available since Release 3.0.0 + */ + protected function at($index) + { + return new PHPUnit_Framework_MockObject_Matcher_InvokedAtIndex($index); + } + + /** + * + * + * @param mixed $value + * @return PHPUnit_Framework_MockObject_Stub_Return + * @access protected + * @since Method available since Release 3.0.0 + */ + protected function returnValue($value) + { + return new PHPUnit_Framework_MockObject_Stub_Return($value); + } + + /** + * + * + * @param Exception $exception + * @return PHPUnit_Framework_MockObject_Stub_Exception + * @access protected + * @since Method available since Release 3.1.0 + */ + protected function throwException(Exception $exception) + { + return new PHPUnit_Framework_MockObject_Stub_Exception($exception); + } + + /** + * + * + * @param mixed $value, ... + * @return PHPUnit_Framework_MockObject_Stub_ConsecutiveCalls + * @access protected + * @since Method available since Release 3.0.0 + */ + protected function onConsecutiveCalls() + { + $args = func_get_args(); + + return new PHPUnit_Framework_MockObject_Stub_ConsecutiveCalls($args); + } + + /** + * @param mixed $data + * @return string + * @access protected + * @since Method available since Release 3.2.1 + */ + protected function dataToString($data) + { + $result = array(); + + foreach ($data as $_data) { + if (is_array($_data)) { + $result[] = 'array(' . $this->dataToString($_data) . ')'; + } + + else if (is_object($_data)) { + $object = new ReflectionObject($_data); + + if ($object->hasMethod('__toString')) { + $result[] = (string)$_data; + } else { + $result[] = get_class($_data); + } + } + + else if (is_resource($_data)) { + $result[] = ''; + } + + else { + $result[] = var_export($_data, TRUE); + } + } + + return join(', ', $result); + } + + /** + * Creates a default TestResult object. + * + * @return PHPUnit_Framework_TestResult + * @access protected + */ + protected function createResult() + { + return new PHPUnit_Framework_TestResult; + } + + /** + * Sets up the fixture, for example, open a network connection. + * This method is called before a test is executed. + * + * @access protected + */ + protected function setUp() + { + } + + /** + * Performs assertions shared by all tests of a test case. + * + * This method is called before the execution of a test starts + * and after setUp() is called. + * + * @access protected + * @since Method available since Release 3.2.8 + */ + protected function assertPreConditions() + { + } + + /** + * Performs assertions shared by all tests of a test case. + * + * This method is called before the execution of a test ends + * and before tearDown() is called. + * + * @access protected + * @since Method available since Release 3.2.8 + */ + protected function assertPostConditions() + { + // assertPostConditions() was named sharedAssertions() in + // PHPUnit 3.0.0-3.2.7. + if (method_exists($this, 'sharedAssertions')) { + $this->sharedAssertions(); + } + } + + /** + * Tears down the fixture, for example, close a network connection. + * This method is called after a test is executed. + * + * @access protected + */ + protected function tearDown() + { + } +} + +} +?> Property changes on: test/PHPUnit/Framework/TestCase.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/TestResult.php =================================================================== --- test/PHPUnit/Framework/TestResult.php (revision 0) +++ test/PHPUnit/Framework/TestResult.php (revision 0) @@ -0,0 +1,723 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: TestResult.php 2126 2008-01-16 06:21:19Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit/Framework.php'; +require_once 'PHPUnit/Util/ErrorHandler.php'; +require_once 'PHPUnit/Util/Filter.php'; +require_once 'PHPUnit/Util/Printer.php'; +require_once 'PHPUnit/Util/Test.php'; +require_once 'PHPUnit/Util/Timer.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +if (!class_exists('PHPUnit_Framework_TestResult', FALSE)) { + +/** + * A TestResult collects the results of executing a test case. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class PHPUnit_Framework_TestResult implements Countable +{ + protected static $xdebugLoaded = null; + protected static $useXdebug = null; + + /** + * @var array + * @access protected + */ + protected $errors = array(); + + /** + * @var array + * @access protected + */ + protected $failures = array(); + + /** + * @var array + * @access protected + */ + protected $notImplemented = array(); + + /** + * @var array + * @access protected + */ + protected $skipped = array(); + + /** + * @var array + * @access protected + */ + protected $listeners = array(); + + /** + * @var integer + * @access protected + */ + protected $runTests = 0; + + /** + * @var float + * @access protected + */ + protected $time = 0; + + /** + * @var PHPUnit_Framework_TestSuite + * @access protected + */ + protected $topTestSuite = NULL; + + /** + * Code Coverage information provided by Xdebug. + * + * @var array + * @access protected + */ + protected $codeCoverageInformation = array(); + + /** + * @var boolean + * @access protected + */ + protected $collectCodeCoverageInformation = FALSE; + + /** + * @var boolean + * @access protected + */ + protected $stop = FALSE; + + /** + * @var boolean + * @access protected + */ + protected $stopOnFailure = FALSE; + + /** + * Registers a TestListener. + * + * @param PHPUnit_Framework_TestListener + * @access public + */ + public function addListener(PHPUnit_Framework_TestListener $listener) + { + $this->listeners[] = $listener; + } + + /** + * Unregisters a TestListener. + * + * @param PHPUnit_Framework_TestListener $listener + * @access public + */ + public function removeListener(PHPUnit_Framework_TestListener $listener) + { + foreach ($this->listeners as $key => $_listener) { + if ($listener === $_listener) { + unset($this->listeners[$key]); + } + } + } + + /** + * Flushes all flushable TestListeners. + * + * @access public + * @since Method available since Release 3.0.0 + */ + public function flushListeners() + { + foreach ($this->listeners as $listener) { + if ($listener instanceof PHPUnit_Util_Printer) { + $listener->flush(); + } + } + } + + /** + * Adds an error to the list of errors. + * The passed in exception caused the error. + * + * @param PHPUnit_Framework_Test $test + * @param Exception $e + * @param float $time + * @access public + */ + public function addError(PHPUnit_Framework_Test $test, Exception $e, $time) + { + if ($e instanceof PHPUnit_Framework_IncompleteTest) { + $this->notImplemented[] = new PHPUnit_Framework_TestFailure($test, $e); + $notifyMethod = 'addIncompleteTest'; + } + + else if ($e instanceof PHPUnit_Framework_SkippedTest) { + $this->skipped[] = new PHPUnit_Framework_TestFailure($test, $e); + $notifyMethod = 'addSkippedTest'; + } + + else { + $this->errors[] = new PHPUnit_Framework_TestFailure($test, $e); + $notifyMethod = 'addError'; + + if ($this->stopOnFailure) { + $this->stop(); + } + } + + foreach ($this->listeners as $listener) { + $listener->$notifyMethod($test, $e, $time); + } + } + + /** + * Adds a failure to the list of failures. + * The passed in exception caused the failure. + * + * @param PHPUnit_Framework_Test $test + * @param PHPUnit_Framework_AssertionFailedError $e + * @param float $time + * @access public + */ + public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) + { + if ($e instanceof PHPUnit_Framework_IncompleteTest) { + $this->notImplemented[] = new PHPUnit_Framework_TestFailure($test, $e); + $notifyMethod = 'addIncompleteTest'; + } + + else if ($e instanceof PHPUnit_Framework_SkippedTest) { + $this->skipped[] = new PHPUnit_Framework_TestFailure($test, $e); + $notifyMethod = 'addSkippedTest'; + } + + else { + $this->failures[] = new PHPUnit_Framework_TestFailure($test, $e); + $notifyMethod = 'addFailure'; + + if ($this->stopOnFailure) { + $this->stop(); + } + } + + foreach ($this->listeners as $listener) { + $listener->$notifyMethod($test, $e, $time); + } + } + + /** + * Informs the result that a testsuite will be started. + * + * @param PHPUnit_Framework_TestSuite $suite + * @access public + * @since Method available since Release 2.2.0 + */ + public function startTestSuite(PHPUnit_Framework_TestSuite $suite) + { + if ($this->topTestSuite === NULL) { + $this->topTestSuite = $suite; + } + + foreach ($this->listeners as $listener) { + $listener->startTestSuite($suite); + } + } + + /** + * Informs the result that a testsuite was completed. + * + * @param PHPUnit_Framework_TestSuite $suite + * @access public + * @since Method available since Release 2.2.0 + */ + public function endTestSuite(PHPUnit_Framework_TestSuite $suite) + { + foreach ($this->listeners as $listener) { + $listener->endTestSuite($suite); + } + } + + /** + * Informs the result that a test will be started. + * + * @param PHPUnit_Framework_Test $test + * @access public + */ + public function startTest(PHPUnit_Framework_Test $test) + { + $this->runTests += count($test); + + foreach ($this->listeners as $listener) { + $listener->startTest($test); + } + } + + /** + * Informs the result that a test was completed. + * + * @param PHPUnit_Framework_Test $test + * @param float $time + * @access public + */ + public function endTest(PHPUnit_Framework_Test $test, $time) + { + foreach ($this->listeners as $listener) { + $listener->endTest($test, $time); + } + } + + /** + * Returns TRUE if no incomplete test occured. + * + * @return boolean + * @access public + */ + public function allCompletlyImplemented() + { + return $this->notImplementedCount() == 0; + } + + /** + * Gets the number of incomplete tests. + * + * @return integer + * @access public + */ + public function notImplementedCount() + { + return count($this->notImplemented); + } + + /** + * Returns an Enumeration for the incomplete tests. + * + * @return array + * @access public + */ + public function notImplemented() + { + return $this->notImplemented; + } + + /** + * Returns TRUE if no test has been skipped. + * + * @return boolean + * @access public + * @since Method available since Release 3.0.0 + */ + public function noneSkipped() + { + return $this->skippedCount() == 0; + } + + /** + * Gets the number of skipped tests. + * + * @return integer + * @access public + * @since Method available since Release 3.0.0 + */ + public function skippedCount() + { + return count($this->skipped); + } + + /** + * Returns an Enumeration for the skipped tests. + * + * @return array + * @access public + * @since Method available since Release 3.0.0 + */ + public function skipped() + { + return $this->skipped; + } + + /** + * Gets the number of detected errors. + * + * @return integer + * @access public + */ + public function errorCount() + { + return count($this->errors); + } + + /** + * Returns an Enumeration for the errors. + * + * @return array + * @access public + */ + public function errors() + { + return $this->errors; + } + + /** + * Gets the number of detected failures. + * + * @return integer + * @access public + */ + public function failureCount() + { + return count($this->failures); + } + + /** + * Returns an Enumeration for the failures. + * + * @return array + * @access public + */ + public function failures() + { + return $this->failures; + } + + /** + * Returns the (top) test suite. + * + * @return PHPUnit_Framework_TestSuite + * @access public + * @since Method available since Release 3.0.0 + */ + public function topTestSuite() + { + return $this->topTestSuite; + } + + /** + * Enables or disables the collection of Code Coverage information. + * + * @param boolean $flag + * @throws InvalidArgumentException + * @access public + * @since Method available since Release 2.3.0 + */ + public function collectCodeCoverageInformation($flag) + { + if (is_bool($flag)) { + $this->collectCodeCoverageInformation = $flag; + } else { + throw new InvalidArgumentException; + } + } + + /** + * Returns whether code coverage information should be collected. + * + * @return boolean If code coverage should be collected + * @since Method available since Release 3.2.0 + */ + public function getCollectCodeCoverageInformation() + { + return $this->collectCodeCoverageInformation; + } + + /** + * Appends code coverage information to the test + * + * @param PHPUnit_Framework_Test $test + * @param array $data + * @since Method available since Release 3.2.0 + */ + public function appendCodeCoverageInformation(PHPUnit_Framework_Test $test, $data) + { + if ($test instanceof PHPUnit_Framework_TestCase) { + $linesToBeCovered = PHPUnit_Util_Test::getLinesToBeCovered( + get_class($test), $test->getName() + ); + + if (!empty($linesToBeCovered)) { + $filesToBeCovered = array_keys($linesToBeCovered); + $filesCovered = array_keys($data); + $filesCovered = array_intersect($filesCovered, $filesToBeCovered); + + foreach ($filesCovered as $file) { + $linesCovered = array_keys($data[$file]); + $linesNotToCover = array_diff($linesCovered, $linesToBeCovered[$file]); + + foreach ($linesNotToCover as $line) { + if ($data[$file][$line] > 0) { + $data[$file][$line] = -1; + } + } + } + } + } + + $this->codeCoverageInformation[] = array( + 'test' => $test, + 'files' => $data + ); + } + + /** + * Returns Code Coverage data per test case. + * + * Format of the result array: + * + * + * array( + * array( + * 'test' => PHPUnit_Framework_Test + * 'files' => array( + * "/tested/code.php" => array( + * linenumber => flag + * ) + * ) + * ) + * ) + * + * + * flag < 0: Line is executable but was not executed. + * flag > 0: Line was executed. + * + * @param boolean $filterTests + * @param boolean $filterPHPUnit + * @return array + * @access public + */ + public function getCodeCoverageInformation($filterTests = TRUE, $filterPHPUnit = TRUE) + { + return PHPUnit_Util_Filter::getFilteredCodeCoverage( + $this->codeCoverageInformation, + $filterTests, + $filterPHPUnit + ); + } + + /** + * Returns unfiltered Code Coverage data per test case. + * Returns data in the same form as getCodeCoverageInformation(). + * + * @return array + * @access public + */ + public function getUncoveredWhitelistFiles() + { + list(, $missing) = PHPUnit_Util_Filter::getFileCodeCoverageDisposition( + $this->codeCoverageInformation + ); + + return($missing); + } + + /** + * Runs a TestCase. + * + * @param PHPUnit_Framework_Test $test + * @access public + */ + public function run(PHPUnit_Framework_Test $test) + { + $error = FALSE; + $failure = FALSE; + + $this->startTest($test); + + $errorHandlerSet = FALSE; + + $oldErrorHandler = set_error_handler( + 'PHPUnit_Util_ErrorHandler', E_ALL | E_STRICT + ); + + if ($oldErrorHandler === NULL) { + $errorHandlerSet = TRUE; + } else { + restore_error_handler(); + } + $oldErrorHandler = set_error_handler( + 'PHPUnit_Util_ErrorHandler', E_ALL | E_STRICT + ); + + if ($oldErrorHandler === NULL) { + $errorHandlerSet = TRUE; + } else { + restore_error_handler(); + } + + if (self::$xdebugLoaded === NULL) { + self::$xdebugLoaded = extension_loaded('xdebug'); + self::$useXdebug = self::$xdebugLoaded; + } + + $useXdebug = self::$useXdebug && $this->collectCodeCoverageInformation && !$test instanceof PHPUnit_Extensions_SeleniumTestCase; + + if ($useXdebug) { + xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE); + } + + PHPUnit_Util_Timer::start(); + + try { + $test->runBare(); + } + + catch (PHPUnit_Framework_AssertionFailedError $e) { + $failure = TRUE; + } + + catch (Exception $e) { + $error = TRUE; + } + + $time = PHPUnit_Util_Timer::stop(); + + if ($useXdebug) { + $codeCoverage = xdebug_get_code_coverage(); + xdebug_stop_code_coverage(); + + $this->appendCodeCoverageInformation( + $test, $codeCoverage + ); + } + + if ($errorHandlerSet === TRUE) { + restore_error_handler(); + } + + if ($error === TRUE) { + $this->addError($test, $e, $time); + } + + else if ($failure === TRUE) { + $this->addFailure($test, $e, $time); + } + + $this->endTest($test, $time); + + $this->time += $time; + } + + /** + * Gets the number of run tests. + * + * @return integer + * @access public + */ + public function count() + { + return $this->runTests; + } + + /** + * Checks whether the test run should stop. + * + * @return boolean + * @access public + */ + public function shouldStop() + { + return $this->stop; + } + + /** + * Marks that the test run should stop. + * + * @access public + */ + public function stop() + { + $this->stop = TRUE; + } + + /** + * Enables or disables the stopping when a failure or error occurs. + * + * @param boolean $flag + * @throws InvalidArgumentException + * @access public + * @since Method available since Release 3.1.0 + */ + public function stopOnFailure($flag) + { + if (is_bool($flag)) { + $this->stopOnFailure = $flag; + } else { + throw new InvalidArgumentException; + } + } + + /** + * Returns the time spent running the tests. + * + * @return float + * @access public + */ + public function time() + { + return $this->time; + } + + /** + * Returns whether the entire test was successful or not. + * + * @return boolean + * @access public + */ + public function wasSuccessful() + { + return empty($this->errors) && empty($this->failures); + } +} + +} +?> Property changes on: test/PHPUnit/Framework/TestResult.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/Test.php =================================================================== --- test/PHPUnit/Framework/Test.php (revision 0) +++ test/PHPUnit/Framework/Test.php (revision 0) @@ -0,0 +1,79 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: Test.php 1985 2007-12-26 18:11:55Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +if (!interface_exists('PHPUnit_Framework_Test', FALSE)) { + +/** + * A Test can be run and collect its results. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: 3.2.9 + * @link http://www.phpunit.de/ + * @since Interface available since Release 2.0.0 + */ +interface PHPUnit_Framework_Test extends Countable +{ + /** + * Runs a test and collects its result in a TestResult instance. + * + * @param PHPUnit_Framework_TestResult $result + * @return PHPUnit_Framework_TestResult + * @access public + */ + public function run(PHPUnit_Framework_TestResult $result = NULL); +} + +} +?> Property changes on: test/PHPUnit/Framework/Test.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/Notice.php =================================================================== --- test/PHPUnit/Framework/Notice.php (revision 0) +++ test/PHPUnit/Framework/Notice.php (revision 0) @@ -0,0 +1,76 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: Notice.php 1985 2007-12-26 18:11:55Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 3.1.0 + */ + +require_once 'PHPUnit/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +if (!class_exists('PHPUnit_Framework_Notice', FALSE)) { + +/** + * Wrapper for PHP notices. + * You can disable notice-to-exception conversion by setting + * + * + * PHPUnit_Framework_Notice::$enabled = FALSE; + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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.0 + */ +class PHPUnit_Framework_Notice extends PHPUnit_Framework_Error +{ + public static $enabled = TRUE; +} + +} +?> Property changes on: test/PHPUnit/Framework/Notice.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/ComparisonFailure.php =================================================================== --- test/PHPUnit/Framework/ComparisonFailure.php (revision 0) +++ test/PHPUnit/Framework/ComparisonFailure.php (revision 0) @@ -0,0 +1,279 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: ComparisonFailure.php 1985 2007-12-26 18:11:55Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; +require_once 'PHPUnit/Util/Type.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +if (!class_exists('PHPUnit_Framework_ComparisonFailure', FALSE)) { + +/** + * Thrown when an assertion for string equality failed. + * + * @category Testing + * @package PHPUnit + * @author Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 class PHPUnit_Framework_ComparisonFailure extends PHPUnit_Framework_AssertionFailedError +{ + /** + * Expected value of the retrieval which does not match $actual. + * @var mixed + */ + protected $expected; + + /** + * Actually retrieved value which does not match $expected. + * @var mixed + */ + protected $actual; + + /** + * @var boolean + */ + protected $identical; + + /** + * Optional message which is placed in front of the first line + * returned by toString(). + * @var string + */ + protected $message; + + /** + * @var boolean + */ + protected static $hasDiff = NULL; + + /** + * Initialises with the expected value and the actual value. + * + * @param mixed $expected Expected value retrieved. + * @param mixed $actual Actual value retrieved. + * @param boolean $identical + * @param string $message A string which is prefixed on all returned lines + * in the difference output. + */ + public function __construct($expected, $actual, $identical = FALSE, $message = '') + { + $this->expected = $expected; + $this->actual = $actual; + $this->identical = $identical; + $this->message = $message; + } + + public function getActual() + { + return $this->actual; + } + + public function getExpected() + { + return $this->expected; + } + + public function identical() + { + return $this->identical; + } + + /** + * Figures out which diff class to use for the input types then + * instantiates that class and returns the object. + * @note The diff is type sensitive, if the type differs only the types + * are shown. + * + * @param mixed $expected Expected value retrieved. + * @param mixed $actual Actual value retrieved. + * @param string $message A string which is prefixed on all returned lines + * in the difference output. + * @return PHPUnit_Framework_ComparisonFailure + */ + public static function diffIdentical($expected, $actual, $message = '') + { + if (gettype($expected) !== gettype($actual)) { + return new PHPUnit_Framework_ComparisonFailure_Type($expected, $actual, TRUE, $message); + } + + elseif (is_string($expected)) { + return new PHPUnit_Framework_ComparisonFailure_String($expected, $actual, TRUE, $message); + } + + elseif (is_null($expected) || is_scalar($expected)) { + return new PHPUnit_Framework_ComparisonFailure_Scalar($expected, $actual, TRUE, $message); + } + + elseif (is_array($expected)) { + return new PHPUnit_Framework_ComparisonFailure_Array($expected, $actual, TRUE, $message); + } + + elseif (is_object($expected)) { + return new PHPUnit_Framework_ComparisonFailure_Object($expected, $actual, TRUE, $message); + } + } + + /** + * Figures out which diff class to use for the input types then + * instantiates that class and returns the object. + * @note The diff is not type sensitive, if the type differs the $actual + * value will be converted to the same type as the $expected. + * + * @param mixed $expected Expected value retrieved. + * @param mixed $actual Actual value retrieved. + * @param string $message A string which is prefixed on all returned lines + * in the difference output. + * @return PHPUnit_Framework_ComparisonFailure + */ + public static function diffEqual($expected, $actual, $message = '') + { + if (is_string($expected) && !is_object($actual)) { + return new PHPUnit_Framework_ComparisonFailure_String($expected, $actual, FALSE, $message); + } + + elseif (is_null($expected) || is_scalar($expected)) { + return new PHPUnit_Framework_ComparisonFailure_Scalar($expected, $actual, FALSE, $message); + } + + elseif (is_array($expected)) { + return new PHPUnit_Framework_ComparisonFailure_Array($expected, $actual, FALSE, $message); + } + + elseif (is_object($expected)) { + return new PHPUnit_Framework_ComparisonFailure_Object($expected, $actual, FALSE, $message); + } + } + + protected function diff($expected, $actual) + { + $expectedFile = tempnam('/tmp', 'expected'); + file_put_contents($expectedFile, $expected); + + $actualFile = tempnam('/tmp', 'actual'); + file_put_contents($actualFile, $actual); + + $buffer = shell_exec( + sprintf( + 'diff -u %s %s', + $expectedFile, + $actualFile + ) + ); + + unlink($expectedFile); + unlink($actualFile); + + if (!empty($buffer)) { + $buffer = explode("\n", $buffer); + + $buffer[0] = "--- Expected"; + $buffer[1] = "+++ Actual"; + + return implode("\n", $buffer); + } + + return ''; + } + + public static function hasDiff() + { + if (self::$hasDiff === NULL) + { + self::$hasDiff = FALSE; + + $binary = 'diff'; + + if (substr(php_uname('s'), 0, 7) == 'Windows') + { + $binary .= '.exe'; + } + + if (isset($_ENV['PATH'])) { + $paths = explode(PATH_SEPARATOR, $_ENV['PATH']); + } + + else if (isset($_ENV['Path'])) { + $paths = explode(PATH_SEPARATOR, $_ENV['Path']); + } + + else if (isset($_SERVER['PATH'])) { + $paths = explode(PATH_SEPARATOR, $_SERVER['PATH']); + } + + else { + $paths = array(); + } + + foreach ($paths as $path) { + if (file_exists($path . DIRECTORY_SEPARATOR . $binary) && + is_executable($path . DIRECTORY_SEPARATOR . $binary)) + { + self::$hasDiff = TRUE; + break; + } + } + } + + return self::$hasDiff; + } +} + +} + +require_once 'PHPUnit/Framework/ComparisonFailure/Array.php'; +require_once 'PHPUnit/Framework/ComparisonFailure/Object.php'; +require_once 'PHPUnit/Framework/ComparisonFailure/Scalar.php'; +require_once 'PHPUnit/Framework/ComparisonFailure/String.php'; +require_once 'PHPUnit/Framework/ComparisonFailure/Type.php'; +?> Property changes on: test/PHPUnit/Framework/ComparisonFailure.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/SelfDescribing.php =================================================================== --- test/PHPUnit/Framework/SelfDescribing.php (revision 0) +++ test/PHPUnit/Framework/SelfDescribing.php (revision 0) @@ -0,0 +1,77 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: SelfDescribing.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/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +if (!interface_exists('PHPUnit_Framework_SelfDescribing', FALSE)) { + +/** + * Interface for classes that can return a description of itself. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: 3.2.9 + * @link http://www.phpunit.de/ + * @since Interface available since Release 3.0.0 + */ +interface PHPUnit_Framework_SelfDescribing +{ + /** + * Returns a string representation of the object. + * + * @return string + * @access public + */ + public function toString(); +} + +} +?> Property changes on: test/PHPUnit/Framework/SelfDescribing.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/SkippedTestSuiteError.php =================================================================== --- test/PHPUnit/Framework/SkippedTestSuiteError.php (revision 0) +++ test/PHPUnit/Framework/SkippedTestSuiteError.php (revision 0) @@ -0,0 +1,72 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: SkippedTestSuiteError.php 1985 2007-12-26 18:11:55Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 3.1.0 + */ + +require_once 'PHPUnit/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +if (!class_exists('PHPUnit_Framework_SkippedTestSuiteError', FALSE)) { + +/** + * Extension to PHPUnit_Framework_AssertionFailedError to mark the special + * case of a skipped test suite. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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.0 + */ +class PHPUnit_Framework_SkippedTestSuiteError extends PHPUnit_Framework_AssertionFailedError implements PHPUnit_Framework_SkippedTest +{ +} + +} +?> Property changes on: test/PHPUnit/Framework/SkippedTestSuiteError.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/Constraint.php =================================================================== --- test/PHPUnit/Framework/Constraint.php (revision 0) +++ test/PHPUnit/Framework/Constraint.php (revision 0) @@ -0,0 +1,164 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: Constraint.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'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +if (!class_exists('PHPUnit_Framework_Constraint', FALSE)) { + +/** + * Abstract base class for constraints. which are placed upon any value. + * + * @category Testing + * @package PHPUnit + * @author Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: 3.2.9 + * @link http://www.phpunit.de/ + * @since Interface available since Release 3.0.0 + */ +abstract class PHPUnit_Framework_Constraint implements PHPUnit_Framework_SelfDescribing +{ + /** + * Evaluates the constraint for parameter $other. Returns TRUE if the + * constraint is met, FALSE otherwise. + * + * @param mixed $other Value or object to evaluate. + * @return bool + * @abstract + */ + abstract public function evaluate($other); + + /** + * Creates the appropriate exception for the constraint which can be caught + * by the unit test system. This can be called if a call to evaluate() fails. + * + * @param mixed $other The value passed to evaluate() which failed the + * constraint check. + * @param string $description A string with extra description of what was + * going on while the evaluation failed. + * @param boolean $not Flag to indicate negation. + * @throws PHPUnit_Framework_ExpectationFailedException + */ + public function fail($other, $description, $not = FALSE) + { + throw new PHPUnit_Framework_ExpectationFailedException( + $this->failureDescription($other, $description, $not), + NULL + ); + } + + protected function failureDescription($other, $description, $not) + { + $failureDescription = sprintf( + 'Failed asserting that %s %s.', + + PHPUnit_Util_Type::toString($other), + $this->toString() + ); + + if ($not) { + $failureDescription = self::negate($failureDescription); + } + + if (!empty($description)) { + $failureDescription = $description . "\n" . $failureDescription; + } + + return $failureDescription; + } + + public static function negate($string) + { + return str_replace( + array( + 'contains ', + 'exists', + 'has ', + 'is ', + 'matches ' + ), + array( + 'does not contain ', + 'does not exist', + 'does not have ', + 'is not ', + 'does not match ' + ), + $string + ); + } +} + +} + +require_once 'PHPUnit/Framework/Constraint/And.php'; +require_once 'PHPUnit/Framework/Constraint/ArrayHasKey.php'; +require_once 'PHPUnit/Framework/Constraint/Attribute.php'; +require_once 'PHPUnit/Framework/Constraint/ClassHasAttribute.php'; +require_once 'PHPUnit/Framework/Constraint/ClassHasStaticAttribute.php'; +require_once 'PHPUnit/Framework/Constraint/FileExists.php'; +require_once 'PHPUnit/Framework/Constraint/GreaterThan.php'; +require_once 'PHPUnit/Framework/Constraint/IsAnything.php'; +require_once 'PHPUnit/Framework/Constraint/IsEqual.php'; +require_once 'PHPUnit/Framework/Constraint/IsIdentical.php'; +require_once 'PHPUnit/Framework/Constraint/IsInstanceOf.php'; +require_once 'PHPUnit/Framework/Constraint/IsType.php'; +require_once 'PHPUnit/Framework/Constraint/LessThan.php'; +require_once 'PHPUnit/Framework/Constraint/Not.php'; +require_once 'PHPUnit/Framework/Constraint/ObjectHasAttribute.php'; +require_once 'PHPUnit/Framework/Constraint/Or.php'; +require_once 'PHPUnit/Framework/Constraint/PCREMatch.php'; +require_once 'PHPUnit/Framework/Constraint/StringContains.php'; +require_once 'PHPUnit/Framework/Constraint/TraversableContains.php'; +require_once 'PHPUnit/Framework/Constraint/TraversableContainsOnly.php'; +require_once 'PHPUnit/Framework/Constraint/Xor.php'; +?> Property changes on: test/PHPUnit/Framework/Constraint.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/TestListener.php =================================================================== --- test/PHPUnit/Framework/TestListener.php (revision 0) +++ test/PHPUnit/Framework/TestListener.php (revision 0) @@ -0,0 +1,146 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: TestListener.php 1985 2007-12-26 18:11:55Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +if (!interface_exists('PHPUnit_Framework_TestListener', FALSE)) { + +/** + * A Listener for test progress. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: 3.2.9 + * @link http://www.phpunit.de/ + * @since Interface available since Release 2.0.0 + */ +interface PHPUnit_Framework_TestListener +{ + /** + * An error occurred. + * + * @param PHPUnit_Framework_Test $test + * @param Exception $e + * @param float $time + * @access public + */ + public function addError(PHPUnit_Framework_Test $test, Exception $e, $time); + + /** + * A failure occurred. + * + * @param PHPUnit_Framework_Test $test + * @param PHPUnit_Framework_AssertionFailedError $e + * @param float $time + * @access public + */ + public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time); + + /** + * Incomplete test. + * + * @param PHPUnit_Framework_Test $test + * @param Exception $e + * @param float $time + * @access public + */ + public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time); + + /** + * Skipped test. + * + * @param PHPUnit_Framework_Test $test + * @param Exception $e + * @param float $time + * @access public + * @since Method available since Release 3.0.0 + */ + public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time); + + /** + * A test suite started. + * + * @param PHPUnit_Framework_TestSuite $suite + * @access public + * @since Method available since Release 2.2.0 + */ + public function startTestSuite(PHPUnit_Framework_TestSuite $suite); + + /** + * A test suite ended. + * + * @param PHPUnit_Framework_TestSuite $suite + * @access public + * @since Method available since Release 2.2.0 + */ + public function endTestSuite(PHPUnit_Framework_TestSuite $suite); + + /** + * A test started. + * + * @param PHPUnit_Framework_Test $test + * @access public + */ + public function startTest(PHPUnit_Framework_Test $test); + + /** + * A test ended. + * + * @param PHPUnit_Framework_Test $test + * @param float $time + * @access public + */ + public function endTest(PHPUnit_Framework_Test $test, $time); +} + +} +?> Property changes on: test/PHPUnit/Framework/TestListener.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/AssertionFailedError.php =================================================================== --- test/PHPUnit/Framework/AssertionFailedError.php (revision 0) +++ test/PHPUnit/Framework/AssertionFailedError.php (revision 0) @@ -0,0 +1,104 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: AssertionFailedError.php 1985 2007-12-26 18:11:55Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +if (!class_exists('PHPUnit_Framework_AssertionFailedError', FALSE)) { + +/** + * Thrown when an assertion failed. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class PHPUnit_Framework_AssertionFailedError extends Exception implements PHPUnit_Framework_SelfDescribing +{ + /** + * Returns the location where this failure occured. + * + * @return array + * @access public + * @since Method available since Release 3.0.0 + */ + public function getLocation() + { + foreach ($this->getTrace() as $frame) { + if (!isset($frame['line'])) { + break; + } + + $result = array( + 'file' => $frame['file'], + 'line' => $frame['line'] + ); + } + + return $result; + } + + /** + * Wrapper for getMessage() which is declared as final. + * + * @return string + * @access public + */ + public function toString() + { + return $this->getMessage(); + } +} + +} +?> Property changes on: test/PHPUnit/Framework/AssertionFailedError.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Framework/TestFailure.php =================================================================== --- test/PHPUnit/Framework/TestFailure.php (revision 0) +++ test/PHPUnit/Framework/TestFailure.php (revision 0) @@ -0,0 +1,251 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: TestFailure.php 2161 2008-01-17 15:41:39Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +if (!class_exists('PHPUnit_Framework_TestFailure', FALSE)) { + +/** + * A TestFailure collects a failed test together with the caught exception. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class PHPUnit_Framework_TestFailure +{ + /** + * @var PHPUnit_Framework_Test + * @access protected + */ + protected $failedTest; + + /** + * @var Exception + * @access protected + */ + protected $thrownException; + + /** + * Constructs a TestFailure with the given test and exception. + * + * @param PHPUnit_Framework_Test $failedTest + * @param Exception $thrownException + * @access public + */ + public function __construct(PHPUnit_Framework_Test $failedTest, Exception $thrownException) + { + $this->failedTest = $failedTest; + $this->thrownException = $thrownException; + } + + /** + * Returns a short description of the failure. + * + * @return string + * @access public + */ + public function toString() + { + return sprintf( + '%s: %s', + + $this->failedTest, + $this->thrownException->getMessage() + ); + } + + /** + * Returns a verbose description of the failure. + * + * @param bool $verbose + * @return string + * @access public + * @since Method available since Release 3.2.0 + */ + public function toStringVerbose($verbose = FALSE) + { + return self::exceptionToString($this->thrownException, $verbose); + } + + /** + * Returns a verbose description for an exception. + * + * @param Exception $e + * @param bool $verbose + * @return string + * @access public + * @static + * @since Method available since Release 3.2.0 + */ + public static function exceptionToString(Exception $e, $verbose = FALSE) + { + if ($e instanceof PHPUnit_Framework_SelfDescribing) { + if ($e instanceof PHPUnit_Framework_ExpectationFailedException) { + $comparisonFailure = $e->getComparisonFailure(); + + if ($comparisonFailure !== NULL) { + if ($comparisonFailure->identical()) { + if ($comparisonFailure instanceof PHPUnit_Framework_ComparisonFailure_Object) { + $buffer = "Failed asserting that two variables reference the same object.\n"; + } else { + $buffer = $comparisonFailure->toString() . "\n"; + } + } else { + if ($comparisonFailure instanceof PHPUnit_Framework_ComparisonFailure_Scalar) { + $buffer = sprintf( + "Failed asserting that %s matches expected value %s.\n", + + PHPUnit_Util_Type::toString($comparisonFailure->getActual()), + PHPUnit_Util_Type::toString($comparisonFailure->getExpected()) + ); + } + + else if ($comparisonFailure instanceof PHPUnit_Framework_ComparisonFailure_Array || + $comparisonFailure instanceof PHPUnit_Framework_ComparisonFailure_Object || + $comparisonFailure instanceof PHPUnit_Framework_ComparisonFailure_String) { + $buffer = sprintf( + "Failed asserting that two %ss are equal.\n%s\n", + + strtolower(substr(get_class($comparisonFailure), 36)), + $comparisonFailure->toString() + ); + } + + if ($verbose && + !$comparisonFailure instanceof PHPUnit_Framework_ComparisonFailure_Array && + !$comparisonFailure instanceof PHPUnit_Framework_ComparisonFailure_Object && + !$comparisonFailure instanceof PHPUnit_Framework_ComparisonFailure_String) { + $buffer = $comparisonFailure->toString() . "\n"; + } + } + } else { + $buffer = $e->toString(); + + if (!empty($buffer)) { + $buffer .= "\n"; + } + + $buffer .= $e->getDescription() . "\n"; + } + } + + else { + $buffer = $e->toString(); + + if (!empty($buffer)) { + $buffer .= "\n"; + } + } + } + + else if ($e instanceof PHPUnit_Framework_Error) { + $buffer = $e->getMessage() . "\n"; + } + + else { + $buffer = get_class($e) . ': ' . $e->getMessage() . "\n"; + } + + return $buffer; + } + + /** + * Gets the failed test. + * + * @return Test + * @access public + */ + public function failedTest() + { + return $this->failedTest; + } + + /** + * Gets the thrown exception. + * + * @return Exception + * @access public + */ + public function thrownException() + { + return $this->thrownException; + } + + /** + * Returns the exception's message. + * + * @return string + * @access public + */ + public function exceptionMessage() + { + return $this->thrownException()->getMessage(); + } + + /** + * Returns TRUE if the thrown exception + * is of type AssertionFailedError. + * + * @return boolean + * @access public + */ + public function isFailure() + { + return ($this->thrownException() instanceof PHPUnit_Framework_AssertionFailedError); + } +} + +} +?> Property changes on: test/PHPUnit/Framework/TestFailure.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/Log/JSON.php =================================================================== --- test/PHPUnit/Util/Log/JSON.php (revision 0) +++ test/PHPUnit/Util/Log/JSON.php (revision 0) @@ -0,0 +1,295 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: JSON.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/Printer.php'; +require_once 'PHPUnit/Util/Test.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * A TestListener that generates JSON messages. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class PHPUnit_Util_Log_JSON extends PHPUnit_Util_Printer implements PHPUnit_Framework_TestListener +{ + /** + * @var string + * @access protected + */ + protected $currentTestSuiteName = ''; + + /** + * @var string + * @access protected + */ + protected $currentTestName = ''; + + /** + * @var boolean + * @access private + */ + protected $currentTestPass = TRUE; + + /** + * An error occurred. + * + * @param PHPUnit_Framework_Test $test + * @param Exception $e + * @param float $time + * @access public + */ + public function addError(PHPUnit_Framework_Test $test, Exception $e, $time) + { + $this->writeCase( + 'error', + $time, + PHPUnit_Util_Filter::getFilteredStacktrace( + $e, + TRUE, + FALSE + ), + $e->getMessage() + ); + + $this->currentTestPass = FALSE; + } + + /** + * A failure occurred. + * + * @param PHPUnit_Framework_Test $test + * @param PHPUnit_Framework_AssertionFailedError $e + * @param float $time + * @access public + */ + public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) + { + $this->writeCase( + 'fail', + $time, + PHPUnit_Util_Filter::getFilteredStacktrace( + $e, + TRUE, + FALSE + ), + $e->getMessage() + ); + + $this->currentTestPass = FALSE; + } + + /** + * Incomplete test. + * + * @param PHPUnit_Framework_Test $test + * @param Exception $e + * @param float $time + * @access public + */ + public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time) + { + $this->writeCase('error', $time, array(), 'Incomplete Test'); + + $this->currentTestPass = FALSE; + } + + /** + * Skipped test. + * + * @param PHPUnit_Framework_Test $test + * @param Exception $e + * @param float $time + * @access public + */ + public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time) + { + $this->writeCase('error', $time, array(), 'Skipped Test'); + + $this->currentTestPass = FALSE; + } + + /** + * A testsuite started. + * + * @param PHPUnit_Framework_TestSuite $suite + * @access public + */ + public function startTestSuite(PHPUnit_Framework_TestSuite $suite) + { + $this->currentTestSuiteName = $suite->getName(); + $this->currentTestName = ''; + + $message = array( + 'event' => 'suiteStart', + 'suite' => $this->currentTestSuiteName, + 'tests' => count($suite) + ); + + $this->write($this->encode($message)); + } + + /** + * A testsuite ended. + * + * @param PHPUnit_Framework_TestSuite $suite + * @access public + */ + public function endTestSuite(PHPUnit_Framework_TestSuite $suite) + { + $this->currentTestSuiteName = ''; + $this->currentTestName = ''; + } + + /** + * A test started. + * + * @param PHPUnit_Framework_Test $test + * @access public + */ + public function startTest(PHPUnit_Framework_Test $test) + { + $this->currentTestName = PHPUnit_Util_Test::describe($test); + $this->currentTestPass = TRUE; + } + + /** + * A test ended. + * + * @param PHPUnit_Framework_Test $test + * @param float $time + * @access public + */ + public function endTest(PHPUnit_Framework_Test $test, $time) + { + if ($this->currentTestPass) { + $this->writeCase('pass', $time); + } + } + + /** + * @param string $status + * @param float $time + * @param array $trace + * @param string $message + * @access protected + */ + protected function writeCase($status, $time, array $trace = array(), $message = '') + { + $message = array( + 'event' => 'test', + 'suite' => $this->currentTestSuiteName, + 'test' => $this->currentTestName, + 'status' => $status, + 'time' => $time, + 'trace' => $trace, + 'message' => $message + ); + + $this->write($this->encode($message)); + } + + /** + * @param array $message + * @return string + * @access protected + */ + protected function encode($message) + { + if (function_exists('json_encode')) { + return json_encode($message); + } + + $first = TRUE; + $result = ''; + + if (is_scalar($message)) { + $message = array ($message); + } + + foreach ($message as $key => $value) { + if (!$first) { + $result .= ','; + } else { + $first = FALSE; + } + + $result .= sprintf('"%s":', $this->escape($key)); + + if (is_array($value) || is_object($value)) { + $result .= sprintf('%s', $this->encode($value)); + } else { + $result .= sprintf('"%s"', $this->escape($value)); + } + } + + return '{' . $result . '}'; + } + + /** + * @param string $value + * @return string + * @access protected + */ + protected function escape($value) + { + return str_replace( + array("\\", "\"", "/", "\b", "\f", "\n", "\r", "\t"), + array('\\\\', '\"', '\/', '\b', '\f', '\n', '\r', '\t'), + $value + ); + } +} +?> Property changes on: test/PHPUnit/Util/Log/JSON.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/Log/GraphViz.php =================================================================== --- test/PHPUnit/Util/Log/GraphViz.php (revision 0) +++ test/PHPUnit/Util/Log/GraphViz.php (revision 0) @@ -0,0 +1,309 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: GraphViz.php 1985 2007-12-26 18:11:55Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 3.0.0 + */ + +@include_once 'Image/GraphViz.php'; + +require_once 'PHPUnit/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; +require_once 'PHPUnit/Util/Filesystem.php'; +require_once 'PHPUnit/Util/Printer.php'; +require_once 'PHPUnit/Util/Test.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * A TestListener that generates maps of the executed tests + * in GraphViz markup. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class PHPUnit_Util_Log_GraphViz extends PHPUnit_Util_Printer implements PHPUnit_Framework_TestListener +{ + /** + * @var Image_GraphViz + * @access protected + */ + protected $graph; + + /** + * @var boolean + * @access protected + */ + protected $currentTestSuccess = TRUE; + + /** + * @var string[] + * @access protected + */ + protected $testSuites = array(); + + /** + * @var integer + * @access protected + */ + protected $testSuiteLevel = 0; + + /** + * @var integer[] + * @access protected + */ + protected $testSuiteFailureOrErrorCount = array(0); + + /** + * @var integer[] + * @access protected + */ + protected $testSuiteIncompleteOrSkippedCount = array(0); + + /** + * Constructor. + * + * @param mixed $out + * @access public + */ + public function __construct($out = NULL) + { + $this->graph = new Image_GraphViz( + TRUE, + array( + 'overlap' => 'scale', + 'splines' => 'true', + 'sep' => '.1', + 'fontsize' => '8' + ) + ); + + parent::__construct($out); + } + + /** + * Flush buffer and close output. + * + * @access public + */ + public function flush() + { + $this->write($this->graph->parse()); + + parent::flush(); + } + + /** + * An error occurred. + * + * @param PHPUnit_Framework_Test $test + * @param Exception $e + * @param float $time + * @access public + */ + public function addError(PHPUnit_Framework_Test $test, Exception $e, $time) + { + $this->addTestNode($test, 'red'); + $this->testSuiteFailureOrErrorCount[$this->testSuiteLevel]++; + + $this->currentTestSuccess = FALSE; + } + + /** + * A failure occurred. + * + * @param PHPUnit_Framework_Test $test + * @param PHPUnit_Framework_AssertionFailedError $e + * @param float $time + * @access public + */ + public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) + { + $this->addTestNode($test, 'red'); + $this->testSuiteFailureOrErrorCount[$this->testSuiteLevel]++; + + $this->currentTestSuccess = FALSE; + } + + /** + * Incomplete test. + * + * @param PHPUnit_Framework_Test $test + * @param Exception $e + * @param float $time + * @access public + */ + public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time) + { + $this->addTestNode($test, 'yellow'); + $this->testSuiteIncompleteOrSkippedCount[$this->testSuiteLevel]++; + + $this->currentTestSuccess = FALSE; + } + + /** + * Skipped test. + * + * @param PHPUnit_Framework_Test $test + * @param Exception $e + * @param float $time + * @access public + */ + public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time) + { + $this->addTestNode($test, 'yellow'); + $this->testSuiteIncompleteOrSkippedCount[$this->testSuiteLevel]++; + + $this->currentTestSuccess = FALSE; + } + + /** + * A testsuite started. + * + * @param PHPUnit_Framework_TestSuite $suite + * @access public + */ + public function startTestSuite(PHPUnit_Framework_TestSuite $suite) + { + $this->graph->addNode($suite->getName()); + + if ($this->testSuiteLevel > 0) { + $this->graph->addEdge( + array( + $this->testSuites[$this->testSuiteLevel] => $suite->getName() + ) + ); + } + + $this->testSuiteLevel++; + $this->testSuites[$this->testSuiteLevel] = $suite->getName(); + $this->testSuiteFailureOrErrorCount[$this->testSuiteLevel] = 0; + $this->testSuiteIncompleteOrSkippedCount[$this->testSuiteLevel] = 0; + } + + /** + * A testsuite ended. + * + * @param PHPUnit_Framework_TestSuite $suite + * @access public + */ + public function endTestSuite(PHPUnit_Framework_TestSuite $suite) + { + $color = 'red'; + + if ($this->testSuiteFailureOrErrorCount[$this->testSuiteLevel] == 0 && + $this->testSuiteIncompleteOrSkippedCount[$this->testSuiteLevel] == 0) { + $color = 'green'; + } + + else if ($this->testSuiteFailureOrErrorCount[$this->testSuiteLevel] == 0 && + $this->testSuiteIncompleteOrSkippedCount[$this->testSuiteLevel] > 0) { + $color = 'yellow'; + } + + $this->graph->addNode( + $this->testSuites[$this->testSuiteLevel], + array('color' => $color) + ); + + if ($this->testSuiteLevel > 1) { + $this->testSuiteFailureOrErrorCount[$this->testSuiteLevel - 1] += $this->testSuiteFailureOrErrorCount[$this->testSuiteLevel]; + $this->testSuiteIncompleteOrSkippedCount[$this->testSuiteLevel - 1] += $this->testSuiteIncompleteOrSkippedCount[$this->testSuiteLevel]; + } + + $this->testSuiteLevel--; + } + + /** + * A test started. + * + * @param PHPUnit_Framework_Test $test + * @access public + */ + public function startTest(PHPUnit_Framework_Test $test) + { + $this->currentTestSuccess = TRUE; + } + + /** + * A test ended. + * + * @param PHPUnit_Framework_Test $test + * @param float $time + * @access public + */ + public function endTest(PHPUnit_Framework_Test $test, $time) + { + if ($this->currentTestSuccess) { + $this->addTestNode($test, 'green'); + } + } + + /** + * @param PHPUnit_Framework_Test $test + * @param string $color + * @access protected + */ + protected function addTestNode(PHPUnit_Framework_Test $test, $color) + { + $name = PHPUnit_Util_Test::describe($test, FALSE); + + $this->graph->addNode( + $name[1], + array('color' => $color), + $this->testSuites[$this->testSuiteLevel] + ); + + $this->graph->addEdge( + array( + $this->testSuites[$this->testSuiteLevel] => $name[1] + ) + ); + } +} +?> Property changes on: test/PHPUnit/Util/Log/GraphViz.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/Log/PMD/Rule/Class/TooManyFields.php =================================================================== --- test/PHPUnit/Util/Log/PMD/Rule/Class/TooManyFields.php (revision 0) +++ test/PHPUnit/Util/Log/PMD/Rule/Class/TooManyFields.php (revision 0) @@ -0,0 +1,88 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: TooManyFields.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/Log/PMD/Rule/Class.php'; +require_once 'PHPUnit/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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_Log_PMD_Rule_Class_TooManyFields extends PHPUnit_Util_Log_PMD_Rule_Class +{ + public function __construct($threshold = 15, $priority = 1) + { + parent::__construct($threshold); + } + + public function apply(PHPUnit_Util_Metrics $metrics) + { + $varsNp = $metrics->getVARSnp(); + + if ($varsNp > $this->threshold) { + return sprintf( + "Class has %d public fields.\n" . + 'Classes that have too many fields could be redesigned ' . + 'to have fewer fields, possibly through some nested ' . + 'object grouping of some of the information. For ' . + 'example, a class with city/state/zip fields could ' . + 'instead have one Address field.', + $varsNp + ); + } + } +} +?> Property changes on: test/PHPUnit/Util/Log/PMD/Rule/Class/TooManyFields.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/Log/PMD/Rule/Class/EfferentCoupling.php =================================================================== --- test/PHPUnit/Util/Log/PMD/Rule/Class/EfferentCoupling.php (revision 0) +++ test/PHPUnit/Util/Log/PMD/Rule/Class/EfferentCoupling.php (revision 0) @@ -0,0 +1,86 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: EfferentCoupling.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/Log/PMD/Rule/Class.php'; +require_once 'PHPUnit/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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_Log_PMD_Rule_Class_EfferentCoupling extends PHPUnit_Util_Log_PMD_Rule_Class +{ + public function __construct($threshold = 20, $priority = 1) + { + parent::__construct($threshold); + } + + public function apply(PHPUnit_Util_Metrics $metrics) + { + $ce = $metrics->getCe(); + + if ($ce > $this->threshold) { + return sprintf( + "Class depends on %d other classes.\n" . + 'The number of other classes that the class ' . + 'depends upon is an indicator of the class\' ' . + 'independence.', + $ce + ); + } + } +} +?> Property changes on: test/PHPUnit/Util/Log/PMD/Rule/Class/EfferentCoupling.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/Log/PMD/Rule/Class/DepthOfInheritanceTree.php =================================================================== --- test/PHPUnit/Util/Log/PMD/Rule/Class/DepthOfInheritanceTree.php (revision 0) +++ test/PHPUnit/Util/Log/PMD/Rule/Class/DepthOfInheritanceTree.php (revision 0) @@ -0,0 +1,83 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: DepthOfInheritanceTree.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/Log/PMD/Rule/Class.php'; +require_once 'PHPUnit/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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_Log_PMD_Rule_Class_DepthOfInheritanceTree extends PHPUnit_Util_Log_PMD_Rule_Class +{ + public function __construct($threshold = 6, $priority = 1) + { + parent::__construct($threshold); + } + + public function apply(PHPUnit_Util_Metrics $metrics) + { + $dit = $metrics->getDIT(); + + if ($dit > $this->threshold) { + return sprintf( + 'Depth of Inheritance Tree (DIT) is %d.', + $dit + ); + } + } +} +?> Property changes on: test/PHPUnit/Util/Log/PMD/Rule/Class/DepthOfInheritanceTree.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/Log/PMD/Rule/Class/ExcessiveClassLength.php =================================================================== --- test/PHPUnit/Util/Log/PMD/Rule/Class/ExcessiveClassLength.php (revision 0) +++ test/PHPUnit/Util/Log/PMD/Rule/Class/ExcessiveClassLength.php (revision 0) @@ -0,0 +1,86 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: ExcessiveClassLength.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/Log/PMD/Rule/Class.php'; +require_once 'PHPUnit/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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_Log_PMD_Rule_Class_ExcessiveClassLength extends PHPUnit_Util_Log_PMD_Rule_Class +{ + public function __construct($threshold = 1000, $priority = 1) + { + parent::__construct($threshold); + } + + public function apply(PHPUnit_Util_Metrics $metrics) + { + $locExecutable = $metrics->getLocExecutable(); + + if ($locExecutable > $this->threshold) { + return sprintf( + "Class has %d lines of executable code.\n" . + 'This is an indication that the class may be ' . + 'trying to do too much. Try to break it down, ' . + 'and reduce the size to something manageable.', + $locExecutable + ); + } + } +} +?> Property changes on: test/PHPUnit/Util/Log/PMD/Rule/Class/ExcessiveClassLength.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/Log/PMD/Rule/Class/ExcessivePublicCount.php =================================================================== --- test/PHPUnit/Util/Log/PMD/Rule/Class/ExcessivePublicCount.php (revision 0) +++ test/PHPUnit/Util/Log/PMD/Rule/Class/ExcessivePublicCount.php (revision 0) @@ -0,0 +1,87 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: ExcessivePublicCount.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/Log/PMD/Rule/Class.php'; +require_once 'PHPUnit/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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_Log_PMD_Rule_Class_ExcessivePublicCount extends PHPUnit_Util_Log_PMD_Rule_Class +{ + public function __construct($threshold = 45, $priority = 1) + { + parent::__construct($threshold); + } + + public function apply(PHPUnit_Util_Metrics $metrics) + { + $publicMethods = $metrics->getPublicMethods(); + + if ($publicMethods > $this->threshold) { + return sprintf( + "Class has %d public methods.\n" . + 'A large number of public methods and attributes ' . + 'declared in a class can indicate the class may need ' . + 'to be broken up as increased effort will be required ' . + 'to thoroughly test it.', + $publicMethods + ); + } + } +} +?> Property changes on: test/PHPUnit/Util/Log/PMD/Rule/Class/ExcessivePublicCount.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/Log/PMD/Rule/File.php =================================================================== --- test/PHPUnit/Util/Log/PMD/Rule/File.php (revision 0) +++ test/PHPUnit/Util/Log/PMD/Rule/File.php (revision 0) @@ -0,0 +1,67 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: File.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/Log/PMD/Rule.php'; +require_once 'PHPUnit/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Abstract base class for PMD rule classes that operate on the file-level. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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_Log_PMD_Rule_File extends PHPUnit_Util_Log_PMD_Rule +{ +} +?> Property changes on: test/PHPUnit/Util/Log/PMD/Rule/File.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/Log/PMD/Rule/Function/ExcessiveParameterList.php =================================================================== --- test/PHPUnit/Util/Log/PMD/Rule/Function/ExcessiveParameterList.php (revision 0) +++ test/PHPUnit/Util/Log/PMD/Rule/Function/ExcessiveParameterList.php (revision 0) @@ -0,0 +1,86 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: ExcessiveParameterList.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/Log/PMD/Rule/Function.php'; +require_once 'PHPUnit/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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_Log_PMD_Rule_Function_ExcessiveParameterList extends PHPUnit_Util_Log_PMD_Rule_Function +{ + public function __construct($threshold = 10, $priority = 1) + { + parent::__construct($threshold); + } + + public function apply(PHPUnit_Util_Metrics $metrics) + { + $parameters = $metrics->getParameters(); + + if ($parameters >= $this->threshold) { + return sprintf( + "Function or method has %d parameters.\n" . + 'Long parameter lists can indicate that a new object should be ' . + 'created to wrap the numerous parameters. Basically, try to '. + 'group the parameters together.', + $parameters + ); + } + } +} +?> Property changes on: test/PHPUnit/Util/Log/PMD/Rule/Function/ExcessiveParameterList.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/Log/PMD/Rule/Function/ExcessiveMethodLength.php =================================================================== --- test/PHPUnit/Util/Log/PMD/Rule/Function/ExcessiveMethodLength.php (revision 0) +++ test/PHPUnit/Util/Log/PMD/Rule/Function/ExcessiveMethodLength.php (revision 0) @@ -0,0 +1,86 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: ExcessiveMethodLength.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/Log/PMD/Rule/Function.php'; +require_once 'PHPUnit/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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_Log_PMD_Rule_Function_ExcessiveMethodLength extends PHPUnit_Util_Log_PMD_Rule_Function +{ + public function __construct($threshold = 100, $priority = 1) + { + parent::__construct($threshold); + } + + public function apply(PHPUnit_Util_Metrics $metrics) + { + $locExecutable = $metrics->getLocExecutable(); + + if ($locExecutable >= $this->threshold) { + return sprintf( + "Function or method has %d lines of executable code.\n" . + 'Violations of this rule usually indicate that the method is ' . + 'doing too much. Try to reduce the method size by creating ' . + 'helper methods and removing any copy/pasted code.', + $locExecutable + ); + } + } +} +?> Property changes on: test/PHPUnit/Util/Log/PMD/Rule/Function/ExcessiveMethodLength.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/Log/PMD/Rule/Function/CRAP.php =================================================================== --- test/PHPUnit/Util/Log/PMD/Rule/Function/CRAP.php (revision 0) +++ test/PHPUnit/Util/Log/PMD/Rule/Function/CRAP.php (revision 0) @@ -0,0 +1,88 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: CRAP.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/Log/PMD/Rule/Function.php'; +require_once 'PHPUnit/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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_Log_PMD_Rule_Function_CRAP extends PHPUnit_Util_Log_PMD_Rule_Function +{ + public function __construct($threshold = 30, $priority = 1) + { + parent::__construct($threshold); + } + + public function apply(PHPUnit_Util_Metrics $metrics) + { + $crap = $metrics->getCrapIndex(); + + if ($crap >= $this->threshold) { + return sprintf( + "The CRAP index is %d.\n" . + 'The Change Risk Analysis and Predictions (CRAP) index of a ' . + 'function or method uses cyclomatic complexity and code coverage ' . + 'from automated tests to help estimate the effort and risk ' . + 'associated with maintaining legacy code. A CRAP index over 30 ' . + 'is a good indicator of crappy code.', + $crap + ); + } + } +} +?> Property changes on: test/PHPUnit/Util/Log/PMD/Rule/Function/CRAP.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/Log/PMD/Rule/Function/CyclomaticComplexity.php =================================================================== --- test/PHPUnit/Util/Log/PMD/Rule/Function/CyclomaticComplexity.php (revision 0) +++ test/PHPUnit/Util/Log/PMD/Rule/Function/CyclomaticComplexity.php (revision 0) @@ -0,0 +1,89 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: CyclomaticComplexity.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/Log/PMD/Rule/Function.php'; +require_once 'PHPUnit/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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_Log_PMD_Rule_Function_CyclomaticComplexity extends PHPUnit_Util_Log_PMD_Rule_Function +{ + public function __construct($threshold = 20, $priority = 1) + { + parent::__construct($threshold); + } + + public function apply(PHPUnit_Util_Metrics $metrics) + { + $ccn = $metrics->getCCN(); + + if ($ccn >= $this->threshold) { + return sprintf( + "The cyclomatic complexity is %d.\n" . + 'Complexity is determined by the number of decision points in a ' . + 'function or method plus one for the function or method entry. ' . + 'The decision points are "if", "for", "foreach", "while", "case", ' . + '"catch", "&&", "||", and "?:". Generally, 1-4 is low ' . + 'complexity, 5-7 indicates moderate complexity, 8-10 is high ' . + 'complexity, and 11+ is very high complexity.', + $ccn + ); + } + } +} +?> Property changes on: test/PHPUnit/Util/Log/PMD/Rule/Function/CyclomaticComplexity.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/Log/PMD/Rule/Function/CodeCoverage.php =================================================================== --- test/PHPUnit/Util/Log/PMD/Rule/Function/CodeCoverage.php (revision 0) +++ test/PHPUnit/Util/Log/PMD/Rule/Function/CodeCoverage.php (revision 0) @@ -0,0 +1,91 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: CodeCoverage.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/Log/PMD/Rule/Function.php'; +require_once 'PHPUnit/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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_Log_PMD_Rule_Function_CodeCoverage extends PHPUnit_Util_Log_PMD_Rule_Function +{ + public function __construct($threshold = array(35, 70), $priority = 1) + { + parent::__construct($threshold); + } + + public function apply(PHPUnit_Util_Metrics $metrics) + { + $coverage = $metrics->getCoverage(); + + if ($coverage <= $this->threshold[0]) { + $violation = 'The code coverage is %01.2F which is considered low.'; + } + + else if ($coverage > $this->threshold[0] && $coverage < $this->threshold[1]) { + $violation = 'The code coverage is %01.2F which is considered medium.'; + } + + if (isset($violation)) { + return sprintf( + $violation, + $coverage + ); + } + } +} +?> Property changes on: test/PHPUnit/Util/Log/PMD/Rule/Function/CodeCoverage.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/Log/PMD/Rule/Function/NPathComplexity.php =================================================================== --- test/PHPUnit/Util/Log/PMD/Rule/Function/NPathComplexity.php (revision 0) +++ test/PHPUnit/Util/Log/PMD/Rule/Function/NPathComplexity.php (revision 0) @@ -0,0 +1,87 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: NPathComplexity.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/Log/PMD/Rule/Function.php'; +require_once 'PHPUnit/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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_Log_PMD_Rule_Function_NPathComplexity extends PHPUnit_Util_Log_PMD_Rule_Function +{ + public function __construct($threshold = 200, $priority = 1) + { + parent::__construct($threshold); + } + + public function apply(PHPUnit_Util_Metrics $metrics) + { + $npath = $metrics->getNPath(); + + if ($npath >= $this->threshold) { + return sprintf( + "The NPath complexity is %d.\n" . + 'The NPath complexity of a function or method is the number of ' . + 'acyclic execution paths through that method. A threshold of 200 ' . + 'is generally considered the point where measures should be taken ' . + 'to reduce complexity.', + $npath + ); + } + } +} +?> Property changes on: test/PHPUnit/Util/Log/PMD/Rule/Function/NPathComplexity.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/Log/PMD/Rule/Project/CRAP.php =================================================================== --- test/PHPUnit/Util/Log/PMD/Rule/Project/CRAP.php (revision 0) +++ test/PHPUnit/Util/Log/PMD/Rule/Project/CRAP.php (revision 0) @@ -0,0 +1,109 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: CRAP.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/Log/PMD/Rule/Function.php'; +require_once 'PHPUnit/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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_Log_PMD_Rule_Project_CRAP extends PHPUnit_Util_Log_PMD_Rule_Project +{ + public function __construct($threshold = array(5, 30), $priority = 1) + { + parent::__construct($threshold); + } + + public function apply(PHPUnit_Util_Metrics $metrics) + { + $numCrappyMethods = 0; + $numMethods = 0; + + foreach ($metrics->getClasses() as $class) { + $methods = $class->getMethods(); + + foreach ($methods as $method) { + if ($method->getCrapIndex() > $this->threshold[1]) { + $numCrappyMethods++; + } + } + + $numMethods += count($methods); + } + + if ($numMethods > 0) { + $percent = ($numCrappyMethods / $numMethods) * 100; + } else { + $percent = 0; + } + + if ($percent > $this->threshold[0]) { + return sprintf( + "More than %01.2f%% of the project's methods have a Change Risk " . + 'Analysis and Predictions (CRAP) index that is above the threshold ' . + "of %d.\n" . + 'The CRAP index of a function or method uses cyclomatic complexity ' . + 'and code coverage from automated tests to help estimate the ' . + 'effort and risk associated with maintaining legacy code. A CRAP ' . + 'index over 30 is a good indicator of crappy code.', + $this->threshold[0], + $this->threshold[1] + ); + } + } +} +?> Property changes on: test/PHPUnit/Util/Log/PMD/Rule/Project/CRAP.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/Log/PMD/Rule/Class.php =================================================================== --- test/PHPUnit/Util/Log/PMD/Rule/Class.php (revision 0) +++ test/PHPUnit/Util/Log/PMD/Rule/Class.php (revision 0) @@ -0,0 +1,67 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: Class.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/Log/PMD/Rule.php'; +require_once 'PHPUnit/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Abstract base class for PMD rule classes that operate on the class-level. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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_Log_PMD_Rule_Class extends PHPUnit_Util_Log_PMD_Rule +{ +} +?> Property changes on: test/PHPUnit/Util/Log/PMD/Rule/Class.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/Log/PMD/Rule/Function.php =================================================================== --- test/PHPUnit/Util/Log/PMD/Rule/Function.php (revision 0) +++ test/PHPUnit/Util/Log/PMD/Rule/Function.php (revision 0) @@ -0,0 +1,68 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: Function.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/Log/PMD/Rule.php'; +require_once 'PHPUnit/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Abstract base class for PMD rule classes that operate on the function- or + * method-level. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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_Log_PMD_Rule_Function extends PHPUnit_Util_Log_PMD_Rule +{ +} +?> Property changes on: test/PHPUnit/Util/Log/PMD/Rule/Function.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/Log/PMD/Rule/Project.php =================================================================== --- test/PHPUnit/Util/Log/PMD/Rule/Project.php (revision 0) +++ test/PHPUnit/Util/Log/PMD/Rule/Project.php (revision 0) @@ -0,0 +1,67 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ + +require_once 'PHPUnit/Util/Log/PMD/Rule.php'; +require_once 'PHPUnit/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Abstract base class for PMD rule classes that operate on the project-level. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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_Log_PMD_Rule_Project extends PHPUnit_Util_Log_PMD_Rule +{ +} +?> Property changes on: test/PHPUnit/Util/Log/PMD/Rule/Project.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/Log/PMD/Rule.php =================================================================== --- test/PHPUnit/Util/Log/PMD/Rule.php (revision 0) +++ test/PHPUnit/Util/Log/PMD/Rule.php (revision 0) @@ -0,0 +1,89 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: Rule.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/Metrics.php'; +require_once 'PHPUnit/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Abstract base class for PMD rule classes. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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_Log_PMD_Rule +{ + protected $threshold; + protected $priority; + + public function __construct($threshold, $priority = 1) + { + $this->threshold = $threshold; + $this->priority = $priority; + } + + public function getName() + { + $name = explode('_', get_class($this)); + + return array_pop($name); + } + + public function getPriority() + { + return $this->priority; + } + + abstract public function apply(PHPUnit_Util_Metrics $metrics); +} +?> Property changes on: test/PHPUnit/Util/Log/PMD/Rule.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/Log/Database/SQLite3.sql =================================================================== --- test/PHPUnit/Util/Log/Database/SQLite3.sql (revision 0) +++ test/PHPUnit/Util/Log/Database/SQLite3.sql (revision 0) @@ -0,0 +1,205 @@ +-- +-- PHPUnit +-- +-- Copyright (c) 2002-2007, Sebastian Bergmann . +-- 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. +-- +-- $Id: SQLite3.sql 2102 2008-01-15 07:35:10Z sb $ +-- + +CREATE TABLE IF NOT EXISTS run( + run_id INTEGER PRIMARY KEY AUTOINCREMENT, + timestamp INTEGER, + revision INTEGER, + information STRING +); + +CREATE TABLE IF NOT EXISTS test( + run_id INTEGER, + test_id INTEGER PRIMARY KEY AUTOINCREMENT, + test_name TEXT, + test_result INTEGER DEFAULT 0, + test_message TEXT DEFAULT "", + test_execution_time REAL DEFAULT 0, + code_method_id INTEGER, + node_root INTEGER, + node_left INTEGER, + node_right INTEGER, + node_is_leaf INTEGER DEFAULT 0 +); + +CREATE INDEX IF NOT EXISTS test_run_id ON test (run_id); +CREATE INDEX IF NOT EXISTS test_result ON test (test_result); +CREATE INDEX IF NOT EXISTS test_code_method_id ON test (code_method_id); +CREATE INDEX IF NOT EXISTS test_node_root ON test (node_root); +CREATE INDEX IF NOT EXISTS test_node_left ON test (node_left); +CREATE INDEX IF NOT EXISTS test_node_right ON test (node_right); + +CREATE TABLE IF NOT EXISTS code_file( + code_file_id INTEGER PRIMARY KEY AUTOINCREMENT, + code_file_name TEXT, + code_file_md5 TEXT, + revision INTEGER +); + +CREATE TABLE IF NOT EXISTS code_function( + code_file_id INTEGER, + code_function_id INTEGER PRIMARY KEY AUTOINCREMENT, + code_function_name TEXT, + code_function_start_line INTEGER, + code_function_end_line INTEGER +); + +CREATE INDEX IF NOT EXISTS code_file_id ON code_function (code_file_id); + +CREATE TABLE IF NOT EXISTS code_class( + code_file_id INTEGER, + code_class_id INTEGER PRIMARY KEY AUTOINCREMENT, + code_class_parent_id INTEGER, + code_class_name TEXT, + code_class_start_line INTEGER, + code_class_end_line INTEGER +); + +CREATE INDEX IF NOT EXISTS code_file_id ON code_class (code_file_id); + +CREATE TABLE IF NOT EXISTS code_method( + code_class_id INTEGER, + code_method_id INTEGER PRIMARY KEY AUTOINCREMENT, + code_method_name TEXT, + code_method_start_line INTEGER, + code_method_end_line INTEGER +); + +CREATE INDEX IF NOT EXISTS code_class_id ON code_method (code_class_id); + +CREATE TABLE IF NOT EXISTS code_line( + code_file_id INTEGER, + code_line_id INTEGER PRIMARY KEY AUTOINCREMENT, + code_line_number INTEGER, + code_line TEXT, + code_line_covered INTEGER +); + +CREATE INDEX IF NOT EXISTS code_line_code_file_id ON code_line (code_file_id); + +CREATE TABLE IF NOT EXISTS code_coverage( + test_id INTEGER, + code_line_id INTEGER +); + +CREATE UNIQUE INDEX IF NOT EXISTS code_coverage_test_id_code_line_id ON code_coverage (test_id, code_line_id); + +CREATE TABLE IF NOT EXISTS metrics_project( + run_id INTEGER, + metrics_project_cls INTEGER, + metrics_project_clsa INTEGER, + metrics_project_clsc INTEGER, + metrics_project_roots INTEGER, + metrics_project_leafs INTEGER, + metrics_project_interfs INTEGER, + metrics_project_maxdit INTEGER +); + +CREATE INDEX IF NOT EXISTS run_id ON metrics_project (run_id); + +CREATE TABLE IF NOT EXISTS metrics_file( + run_id INTEGER, + code_file_id INTEGER, + metrics_file_coverage REAL, + metrics_file_loc INTEGER, + metrics_file_cloc INTEGER, + metrics_file_ncloc INTEGER, + metrics_file_loc_executable INTEGER, + metrics_file_loc_executed INTEGER +); + +CREATE INDEX IF NOT EXISTS run_id ON metrics_file (run_id); +CREATE INDEX IF NOT EXISTS code_file_id ON metrics_file (code_file_id); + +CREATE TABLE IF NOT EXISTS metrics_function( + run_id INTEGER, + code_function_id INTEGER, + metrics_function_coverage REAL, + metrics_function_loc INTEGER, + metrics_function_loc_executable INTEGER, + metrics_function_loc_executed INTEGER, + metrics_function_ccn INTEGER, + metrics_function_crap REAL, + metrics_function_npath INTEGER +); + +CREATE INDEX IF NOT EXISTS run_id ON metrics_function (run_id); +CREATE INDEX IF NOT EXISTS code_function_id ON metrics_function (code_function_id); + +CREATE TABLE IF NOT EXISTS metrics_class( + run_id INTEGER, + code_class_id INTEGER, + metrics_class_coverage REAL, + metrics_class_loc INTEGER, + metrics_class_loc_executable INTEGER, + metrics_class_loc_executed INTEGER, + metrics_class_aif REAL, + metrics_class_ahf REAL, + metrics_class_cis INTEGER, + metrics_class_csz INTEGER, + metrics_class_dit INTEGER, + metrics_class_impl INTEGER, + metrics_class_mif REAL, + metrics_class_mhf REAL, + metrics_class_noc INTEGER, + metrics_class_pf REAL, + metrics_class_vars INTEGER, + metrics_class_varsnp INTEGER, + metrics_class_varsi INTEGER, + metrics_class_wmc INTEGER, + metrics_class_wmcnp INTEGER, + metrics_class_wmci INTEGER +); + +CREATE INDEX IF NOT EXISTS run_id ON metrics_class (run_id); +CREATE INDEX IF NOT EXISTS code_class_id ON metrics_class (code_class_id); + +CREATE TABLE IF NOT EXISTS metrics_method( + run_id INTEGER, + code_method_id INTEGER, + metrics_method_coverage REAL, + metrics_method_loc INTEGER, + metrics_method_loc_executable INTEGER, + metrics_method_loc_executed INTEGER, + metrics_method_ccn INTEGER, + metrics_method_crap REAL, + metrics_method_npath INTEGER +); + +CREATE INDEX IF NOT EXISTS run_id ON metrics_method (run_id); +CREATE INDEX IF NOT EXISTS code_method_id ON metrics_method (code_method_id); Property changes on: test/PHPUnit/Util/Log/Database/SQLite3.sql ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/Log/Database/MySQL.sql =================================================================== --- test/PHPUnit/Util/Log/Database/MySQL.sql (revision 0) +++ test/PHPUnit/Util/Log/Database/MySQL.sql (revision 0) @@ -0,0 +1,205 @@ +# +# PHPUnit +# +# Copyright (c) 2002-2007, Sebastian Bergmann . +# 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. +# +# $Id: MySQL.sql 2102 2008-01-15 07:35:10Z sb $ +# + +CREATE TABLE IF NOT EXISTS run( + run_id INTEGER UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT, + timestamp INTEGER UNSIGNED NOT NULL, + revision INTEGER UNSIGNED NOT NULL, + information TEXT NOT NULL +) ENGINE=InnoDB; + +CREATE TABLE IF NOT EXISTS test( + run_id INTEGER UNSIGNED NOT NULL REFERENCES run.run_id, + test_id INTEGER UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT, + test_name CHAR(128) NOT NULL, + test_result TINYINT UNSIGNED NOT NULL DEFAULT 0, + test_message TEXT NOT NULL DEFAULT "", + test_execution_time FLOAT UNSIGNED NOT NULL DEFAULT 0, + code_method_id INTEGER UNSIGNED REFERENCES code_method.code_method_id, + node_root INTEGER UNSIGNED NOT NULL, + node_left INTEGER UNSIGNED NOT NULL, + node_right INTEGER UNSIGNED NOT NULL, + node_is_leaf BOOLEAN NOT NULL DEFAULT 0, + + INDEX (run_id), + INDEX (test_result), + INDEX (code_method_id), + INDEX (node_root), + INDEX (node_left), + INDEX (node_right) +) ENGINE=InnoDB; + +CREATE TABLE IF NOT EXISTS code_file( + code_file_id INTEGER UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT, + code_file_name CHAR(255), + code_file_md5 CHAR(32), + revision INTEGER UNSIGNED NOT NULL +) ENGINE=InnoDB; + +CREATE TABLE IF NOT EXISTS code_function( + code_file_id INTEGER UNSIGNED NOT NULL REFERENCES code_file.code_file_id, + code_function_id INTEGER UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT, + code_function_name CHAR(255), + code_function_start_line INTEGER UNSIGNED NOT NULL, + code_function_end_line INTEGER UNSIGNED NOT NULL, + + INDEX (code_file_id) +) ENGINE=InnoDB; + +CREATE TABLE IF NOT EXISTS code_class( + code_file_id INTEGER UNSIGNED NOT NULL REFERENCES code_file.code_file_id, + code_class_id INTEGER UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT, + code_class_parent_id INTEGER UNSIGNED REFERENCES code_class.code_class_id, + code_class_name CHAR(255), + code_class_start_line INTEGER UNSIGNED NOT NULL, + code_class_end_line INTEGER UNSIGNED NOT NULL, + + INDEX (code_file_id) +) ENGINE=InnoDB; + +CREATE TABLE IF NOT EXISTS code_method( + code_class_id INTEGER UNSIGNED NOT NULL REFERENCES code_class.code_class_id, + code_method_id INTEGER UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT, + code_method_name CHAR(255), + code_method_start_line INTEGER UNSIGNED NOT NULL, + code_method_end_line INTEGER UNSIGNED NOT NULL, + + INDEX (code_class_id) +) ENGINE=InnoDB; + +CREATE TABLE IF NOT EXISTS code_line( + code_file_id INTEGER UNSIGNED NOT NULL REFERENCES code_file.code_file_id, + code_line_id INTEGER UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT, + code_line_number INTEGER UNSIGNED NOT NULL, + code_line TEXT, + code_line_covered TINYINT UNSIGNED NOT NULL, + + INDEX (code_file_id) +) ENGINE=InnoDB; + +CREATE TABLE IF NOT EXISTS code_coverage( + test_id INTEGER UNSIGNED NOT NULL REFERENCES test.test_id, + code_line_id INTEGER UNSIGNED NOT NULL REFERENCES code_line.code_line_id, + + PRIMARY KEY (test_id, code_line_id) +) ENGINE=InnoDB; + +CREATE TABLE IF NOT EXISTS metrics_project( + run_id INTEGER UNSIGNED NOT NULL, + metrics_project_cls INTEGER UNSIGNED NOT NULL, + metrics_project_clsa INTEGER UNSIGNED NOT NULL, + metrics_project_clsc INTEGER UNSIGNED NOT NULL, + metrics_project_roots INTEGER UNSIGNED NOT NULL, + metrics_project_leafs INTEGER UNSIGNED NOT NULL, + metrics_project_interfs INTEGER UNSIGNED NOT NULL, + metrics_project_maxdit INTEGER UNSIGNED NOT NULL, + + INDEX (run_id) +) ENGINE=InnoDB; + +CREATE TABLE IF NOT EXISTS metrics_file( + run_id INTEGER UNSIGNED NOT NULL, + code_file_id INTEGER UNSIGNED NOT NULL REFERENCES code_file.code_file_id, + metrics_file_coverage FLOAT UNSIGNED NOT NULL, + metrics_file_loc INTEGER UNSIGNED NOT NULL, + metrics_file_cloc INTEGER UNSIGNED NOT NULL, + metrics_file_ncloc INTEGER UNSIGNED NOT NULL, + metrics_file_loc_executable INTEGER UNSIGNED NOT NULL, + metrics_file_loc_executed INTEGER UNSIGNED NOT NULL, + + INDEX (run_id), + INDEX (code_file_id) +) ENGINE=InnoDB; + +CREATE TABLE IF NOT EXISTS metrics_function( + run_id INTEGER UNSIGNED NOT NULL, + code_function_id INTEGER UNSIGNED NOT NULL REFERENCES code_method.code_function_id, + metrics_function_coverage FLOAT UNSIGNED NOT NULL, + metrics_function_loc INTEGER UNSIGNED NOT NULL, + metrics_function_loc_executable INTEGER UNSIGNED NOT NULL, + metrics_function_loc_executed INTEGER UNSIGNED NOT NULL, + metrics_function_ccn INTEGER UNSIGNED NOT NULL, + metrics_function_crap FLOAT UNSIGNED NOT NULL, + metrics_function_npath INTEGER UNSIGNED NOT NULL, + + INDEX (run_id), + INDEX (code_function_id) +) ENGINE=InnoDB; + +CREATE TABLE IF NOT EXISTS metrics_class( + run_id INTEGER UNSIGNED NOT NULL, + code_class_id INTEGER UNSIGNED NOT NULL REFERENCES code_class.code_class_id, + metrics_class_coverage FLOAT UNSIGNED NOT NULL, + metrics_class_loc INTEGER UNSIGNED NOT NULL, + metrics_class_loc_executable INTEGER UNSIGNED NOT NULL, + metrics_class_loc_executed INTEGER UNSIGNED NOT NULL, + metrics_class_aif FLOAT UNSIGNED NOT NULL, + metrics_class_ahf FLOAT UNSIGNED NOT NULL, + metrics_class_cis INTEGER UNSIGNED NOT NULL, + metrics_class_csz INTEGER UNSIGNED NOT NULL, + metrics_class_dit INTEGER UNSIGNED NOT NULL, + metrics_class_impl INTEGER UNSIGNED NOT NULL, + metrics_class_mif FLOAT UNSIGNED NOT NULL, + metrics_class_mhf FLOAT UNSIGNED NOT NULL, + metrics_class_noc INTEGER UNSIGNED NOT NULL, + metrics_class_pf FLOAT UNSIGNED NOT NULL, + metrics_class_vars INTEGER UNSIGNED NOT NULL, + metrics_class_varsnp INTEGER UNSIGNED NOT NULL, + metrics_class_varsi INTEGER UNSIGNED NOT NULL, + metrics_class_wmc INTEGER UNSIGNED NOT NULL, + metrics_class_wmcnp INTEGER UNSIGNED NOT NULL, + metrics_class_wmci INTEGER UNSIGNED NOT NULL, + + INDEX (run_id), + INDEX (code_class_id) +) ENGINE=InnoDB; + +CREATE TABLE IF NOT EXISTS metrics_method( + run_id INTEGER UNSIGNED NOT NULL, + code_method_id INTEGER UNSIGNED NOT NULL REFERENCES code_method.code_method_id, + metrics_method_coverage FLOAT UNSIGNED NOT NULL, + metrics_method_loc INTEGER UNSIGNED NOT NULL, + metrics_method_loc_executable INTEGER UNSIGNED NOT NULL, + metrics_method_loc_executed INTEGER UNSIGNED NOT NULL, + metrics_method_ccn INTEGER UNSIGNED NOT NULL, + metrics_method_crap FLOAT UNSIGNED NOT NULL, + metrics_method_npath INTEGER UNSIGNED NOT NULL, + + INDEX (run_id), + INDEX (code_method_id) +) ENGINE=InnoDB; Property changes on: test/PHPUnit/Util/Log/Database/MySQL.sql ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/Log/CodeCoverage/XML.php =================================================================== --- test/PHPUnit/Util/Log/CodeCoverage/XML.php (revision 0) +++ test/PHPUnit/Util/Log/CodeCoverage/XML.php (revision 0) @@ -0,0 +1,293 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: XML.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/Runner/Version.php'; +require_once 'PHPUnit/Util/Metrics/File.php'; +require_once 'PHPUnit/Util/Class.php'; +require_once 'PHPUnit/Util/CodeCoverage.php'; +require_once 'PHPUnit/Util/Filter.php'; +require_once 'PHPUnit/Util/Printer.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Generates an XML logfile with code coverage information using the + * Clover format "documented" at + * http://svn.atlassian.com/svn/public/contrib/bamboo/bamboo-coverage-plugin/trunk/src/test/resources/test-clover-report.xml + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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_Log_CodeCoverage_XML extends PHPUnit_Util_Printer +{ + /** + * @param PHPUnit_Framework_TestResult $result + * @access public + * @todo Count conditionals. + */ + public function process(PHPUnit_Framework_TestResult $result) + { + $document = new DOMDocument('1.0', 'UTF-8'); + $document->formatOutput = TRUE; + + $coverage = $document->createElement('coverage'); + $coverage->setAttribute('generated', time()); + $coverage->setAttribute('phpunit', PHPUnit_Runner_Version::id()); + $document->appendChild($coverage); + + $project = $document->createElement('project'); + $project->setAttribute('name', $result->topTestSuite()->getName()); + $project->setAttribute('timestamp', time()); + $coverage->appendChild($project); + + $codeCoverageInformation = $result->getCodeCoverageInformation(); + $files = PHPUnit_Util_CodeCoverage::getSummary($codeCoverageInformation); + + $projectFiles = 0; + $projectLoc = 0; + $projectNcloc = 0; + $projectLinesExecutable = 0; + $projectLinesExecuted = 0; + $projectClasses = 0; + $projectMethods = 0; + $projectCoveredMethods = 0; + $projectConditionals = 0; + $projectCoveredConditionals = 0; + $projectStatements = 0; + $projectCoveredStatements = 0; + + foreach ($files as $filename => $data) { + $projectFiles++; + + $fileClasses = 0; + $fileConditionals = 0; + $fileCoveredConditionals = 0; + $fileStatements = 0; + $fileCoveredStatements = 0; + $fileMethods = 0; + $fileCoveredMethods = 0; + + $file = $document->createElement('file'); + $file->setAttribute('name', $filename); + + $classes = PHPUnit_Util_Class::getClassesInFile($filename); + $lines = array(); + + foreach ($classes as $class) { + $methods = $class->getMethods(); + $numMethods = 0; + $fileClasses++; + $projectClasses++; + + $classConditionals = 0; + $classCoveredConditionals = 0; + $classStatements = 0; + $classCoveredStatements = 0; + $classCoveredMethods = 0; + + foreach ($methods as $method) { + if ($method->getDeclaringClass()->getName() == $class->getName()) { + $startLine = $method->getStartLine(); + $numMethods++; + $fileMethods++; + $projectMethods++; + + if ($startLine) { + $endLine = $method->getEndLine(); + $tests = array(); + + for ($i = $startLine; $i <= $endLine; $i++) { + if (isset($files[$filename][$i])) { + if (is_array($files[$filename][$i])) { + foreach ($files[$filename][$i] as $_test) { + $add = TRUE; + + foreach ($tests as $test) { + if ($test === $_test) { + $add = FALSE; + break; + } + } + + if ($add) { + $tests[] = $_test; + } + } + + $classCoveredStatements++; + } + + $classStatements++; + } + } + + $count = count($tests); + + $lines[$startLine] = array( + 'count' => $count, + 'type' => 'method' + ); + + if ($count > 0) { + $classCoveredMethods++; + $fileCoveredMethods++; + $projectCoveredMethods++; + } + } + } + } + + $classXML = $document->createElement('class'); + $classXML->setAttribute('name', $class->getName()); + $file->appendChild($classXML); + + $classMetricsXML = $document->createElement('metrics'); + $classMetricsXML->setAttribute('methods', $numMethods); + $classMetricsXML->setAttribute('coveredmethods', $classCoveredMethods); + //$classMetricsXML->setAttribute('conditionals', $classConditionals); + //$classMetricsXML->setAttribute('coveredconditionals', $classCoveredConditionals); + $classMetricsXML->setAttribute('statements', $classStatements); + $classMetricsXML->setAttribute('coveredstatements', $classCoveredStatements); + $classMetricsXML->setAttribute('elements', $classConditionals + $classStatements + $numMethods); + $classMetricsXML->setAttribute('coveredelements', $classCoveredConditionals + $classCoveredStatements + $classCoveredMethods); + $classXML->appendChild($classMetricsXML); + + $fileStatements += $classStatements; + $fileCoveredStatements += $classCoveredStatements; + } + + foreach ($data as $_line => $_data) { + if (is_array($_data)) { + $count = count($_data); + } + + else if ($_data == -1) { + $count = 0; + } + + else if ($_data == -2) { + continue; + } + + $lines[$_line] = array( + 'count' => $count, + 'type' => 'stmt' + ); + } + + ksort($lines); + + foreach ($lines as $_line => $_data) { + $line = $document->createElement('line'); + $line->setAttribute('num', $_line); + $line->setAttribute('type', $_data['type']); + $line->setAttribute('count', $_data['count']); + + $file->appendChild($line); + } + + if (file_exists($filename)) { + $fileMetrics = PHPUnit_Util_Metrics_File::factory($filename, $files); + $fileLoc = $fileMetrics->getLoc(); + $fileNcloc = $fileMetrics->getNcloc(); + $fileLinesExecutable = $fileMetrics->getLocExecutable(); + $fileLinesExecuted = $fileMetrics->getLocExecuted(); + + $fileMetricsXML = $document->createElement('metrics'); + $fileMetricsXML->setAttribute('loc', $fileLoc); + $fileMetricsXML->setAttribute('ncloc', $fileNcloc); + $fileMetricsXML->setAttribute('executablelines', $fileLinesExecutable); + $fileMetricsXML->setAttribute('executedlines', $fileLinesExecuted); + $fileMetricsXML->setAttribute('classes', $fileClasses); + $fileMetricsXML->setAttribute('methods', $fileMethods); + $fileMetricsXML->setAttribute('coveredmethods', $fileCoveredMethods); + //$fileMetricsXML->setAttribute('conditionals', $fileConditionals); + //$fileMetricsXML->setAttribute('coveredconditionals', $fileCoveredConditionals); + $fileMetricsXML->setAttribute('statements', $fileStatements); + $fileMetricsXML->setAttribute('coveredstatements', $fileCoveredStatements); + $fileMetricsXML->setAttribute('elements', $fileConditionals + $fileStatements + $fileMethods); + $fileMetricsXML->setAttribute('coveredelements', $fileCoveredConditionals + $fileCoveredStatements + $fileCoveredMethods); + + $file->appendChild($fileMetricsXML); + $project->appendChild($file); + + $projectLoc += $fileLoc; + $projectNcloc += $fileNcloc; + $projectLinesExecutable += $fileLinesExecutable; + $projectLinesExecuted += $fileLinesExecuted; + $projectStatements += $fileStatements; + $projectCoveredStatements += $fileCoveredStatements; + } + } + + $projectMetricsXML = $document->createElement('metrics'); + $projectMetricsXML->setAttribute('files', $projectFiles); + $projectMetricsXML->setAttribute('loc', $projectLoc); + $projectMetricsXML->setAttribute('ncloc', $projectNcloc); + $projectMetricsXML->setAttribute('executablelines', $projectLinesExecutable); + $projectMetricsXML->setAttribute('executedlines', $projectLinesExecuted); + $projectMetricsXML->setAttribute('classes', $projectClasses); + $projectMetricsXML->setAttribute('methods', $projectMethods); + $projectMetricsXML->setAttribute('coveredmethods', $projectCoveredMethods); + //$projectMetricsXML->setAttribute('conditionals', $projectConditionals); + //$projectMetricsXML->setAttribute('coveredconditionals', $projectCoveredConditionals); + $projectMetricsXML->setAttribute('statements', $projectStatements); + $projectMetricsXML->setAttribute('coveredstatements', $projectCoveredStatements); + $projectMetricsXML->setAttribute('elements', $projectConditionals + $projectStatements + $projectMethods); + $projectMetricsXML->setAttribute('coveredelements', $projectCoveredConditionals + $projectCoveredStatements + $projectCoveredMethods); + $project->appendChild($projectMetricsXML); + + $this->write($document->saveXML()); + $this->flush(); + } +} +?> Property changes on: test/PHPUnit/Util/Log/CodeCoverage/XML.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/Log/CodeCoverage/Database.php =================================================================== --- test/PHPUnit/Util/Log/CodeCoverage/Database.php (revision 0) +++ test/PHPUnit/Util/Log/CodeCoverage/Database.php (revision 0) @@ -0,0 +1,587 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: Database.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/Framework.php'; +require_once 'PHPUnit/Util/Metrics/Project.php'; +require_once 'PHPUnit/Util/Class.php'; +require_once 'PHPUnit/Util/CodeCoverage.php'; +require_once 'PHPUnit/Util/Filesystem.php'; +require_once 'PHPUnit/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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_Log_CodeCoverage_Database +{ + /** + * @var PDO + * @access protected + */ + protected $dbh; + + /** + * Constructor. + * + * @param PDO $dbh + * @throws PDOException + * @access public + */ + public function __construct(PDO $dbh) + { + $this->dbh = $dbh; + } + + /** + * Stores code coverage information. + * + * @param PHPUnit_Framework_TestResult $result + * @param integer $runId + * @param integer $revision + * @param string $commonPath + * @access public + */ + public function storeCodeCoverage(PHPUnit_Framework_TestResult $result, $runId, $revision, $commonPath = '') + { + $codeCoverage = $result->getCodeCoverageInformation(FALSE, TRUE); + $summary = PHPUnit_Util_CodeCoverage::getSummary($codeCoverage); + $files = array_keys($summary); + $projectMetrics = new PHPUnit_Util_Metrics_Project($files, $summary); + $storedClasses = array(); + + if (empty($commonPath)) { + $commonPath = PHPUnit_Util_Filesystem::getCommonPath($files); + } + + $this->dbh->beginTransaction(); + + foreach ($files as $file) { + $filename = str_replace($commonPath, '', $file); + $fileId = FALSE; + $fileMetrics = $projectMetrics->getFile($file); + $lines = $fileMetrics->getLines(); + $hash = md5_file($file); + + $stmt = $this->dbh->prepare( + 'SELECT code_file_id + FROM code_file + WHERE code_file_name = :filename + AND revision = :revision;' + ); + + $stmt->bindParam(':filename', $filename, PDO::PARAM_STR); + $stmt->bindParam(':revision', $revision, PDO::PARAM_INT); + $stmt->execute(); + + if ($stmt) { + $fileId = (int)$stmt->fetchColumn(); + } + + unset($stmt); + + if ($fileId == 0) { + $stmt = $this->dbh->prepare( + 'INSERT INTO code_file + (code_file_name, code_file_md5, revision) + VALUES(:filename, :hash, :revision);' + ); + + $stmt->bindParam(':filename', $filename, PDO::PARAM_STR); + $stmt->bindParam(':hash', $hash, PDO::PARAM_STR); + $stmt->bindParam(':revision', $revision, PDO::PARAM_INT); + $stmt->execute(); + + $fileId = $this->dbh->lastInsertId(); + + $stmt = $this->dbh->prepare( + 'INSERT INTO code_class + (code_file_id, code_class_name, + code_class_start_line, code_class_end_line) + VALUES(:fileId, :className, :startLine, :endLine);' + ); + + foreach ($fileMetrics->getClasses() as $classMetrics) { + $className = $classMetrics->getClass()->getName(); + $classStartLine = $classMetrics->getClass()->getStartLine(); + $classEndLine = $classMetrics->getClass()->getEndLine(); + + $stmt->bindParam(':fileId', $fileId, PDO::PARAM_INT); + $stmt->bindParam(':className', $className, PDO::PARAM_STR); + $stmt->bindParam(':startLine', $classStartLine, PDO::PARAM_INT); + $stmt->bindParam(':endLine', $classEndLine, PDO::PARAM_INT); + $stmt->execute(); + + $classId = $this->dbh->lastInsertId(); + $storedClasses[$className] = $classId; + + $stmt2 = $this->dbh->prepare( + 'INSERT INTO code_method + (code_class_id, code_method_name, + code_method_start_line, code_method_end_line) + VALUES(:classId, :methodName, :startLine, :endLine);' + ); + + foreach ($classMetrics->getMethods() as $methodMetrics) { + $methodName = $methodMetrics->getMethod()->getName(); + $methodStartLine = $methodMetrics->getMethod()->getStartLine(); + $methodEndLine = $methodMetrics->getMethod()->getEndLine(); + + $stmt2->bindParam(':classId', $classId, PDO::PARAM_INT); + $stmt2->bindParam(':methodName', $methodName, PDO::PARAM_STR); + $stmt2->bindParam(':startLine', $methodStartLine, PDO::PARAM_INT); + $stmt2->bindParam(':endLine', $methodEndLine, PDO::PARAM_INT); + $stmt2->execute(); + } + + unset($stmt2); + } + + $stmt = $this->dbh->prepare( + 'INSERT INTO code_line + (code_file_id, code_line_number, code_line, + code_line_covered) + VALUES(:fileId, :lineNumber, :line, :covered);' + ); + + $i = 1; + + foreach ($lines as $line) { + $covered = isset($summary[$file][$i]) ? 1 : 0; + + $stmt->bindParam(':fileId', $fileId, PDO::PARAM_INT); + $stmt->bindParam(':lineNumber', $i, PDO::PARAM_INT); + $stmt->bindParam(':line', $line, PDO::PARAM_STR); + $stmt->bindParam(':covered', $covered, PDO::PARAM_INT); + $stmt->execute(); + + $i++; + } + } + + $stmt = $this->dbh->prepare( + 'INSERT INTO metrics_file + (run_id, code_file_id, metrics_file_coverage, + metrics_file_loc, metrics_file_cloc, metrics_file_ncloc, + metrics_file_loc_executable, metrics_file_loc_executed) + VALUES(:runId, :fileId, :coverage, :loc, :cloc, :ncloc, + :locExecutable, :locExecuted);' + ); + + $fileCoverage = $fileMetrics->getCoverage(); + $fileLoc = $fileMetrics->getLoc(); + $fileCloc = $fileMetrics->getCloc(); + $fileNcloc = $fileMetrics->getNcloc(); + $fileLocExecutable = $fileMetrics->getLocExecutable(); + $fileLocExecuted = $fileMetrics->getLocExecuted(); + + $stmt->bindParam(':runId', $runId, PDO::PARAM_INT); + $stmt->bindParam(':fileId', $fileId, PDO::PARAM_INT); + $stmt->bindParam(':coverage', $fileCoverage); + $stmt->bindParam(':loc', $fileLoc, PDO::PARAM_INT); + $stmt->bindParam(':cloc', $fileCloc, PDO::PARAM_INT); + $stmt->bindParam(':ncloc', $fileNcloc, PDO::PARAM_INT); + $stmt->bindParam(':locExecutable', $fileLocExecutable, PDO::PARAM_INT); + $stmt->bindParam(':locExecuted', $fileLocExecuted, PDO::PARAM_INT); + $stmt->execute(); + + $stmtSelectFunctionId = $this->dbh->prepare( + 'SELECT code_function_id + FROM code_file, code_function + WHERE code_function.code_file_id = code_file.code_file_id + AND code_file.revision = :revision + AND code_function.code_function_name = :functionName;' + ); + + $stmtInsertFunction = $this->dbh->prepare( + 'INSERT INTO metrics_function + (run_id, code_function_id, metrics_function_coverage, + metrics_function_loc, metrics_function_loc_executable, metrics_function_loc_executed, + metrics_function_ccn, metrics_function_crap, metrics_function_npath) + VALUES(:runId, :functionId, :coverage, :loc, + :locExecutable, :locExecuted, :ccn, :crap, :npath);' + ); + + $stmtSelectClassId = $this->dbh->prepare( + 'SELECT code_class_id + FROM code_file, code_class + WHERE code_class.code_file_id = code_file.code_file_id + AND code_file.revision = :revision + AND code_class.code_class_name = :className;' + ); + + $stmtInsertClass = $this->dbh->prepare( + 'INSERT INTO metrics_class + (run_id, code_class_id, metrics_class_coverage, + metrics_class_loc, metrics_class_loc_executable, metrics_class_loc_executed, + metrics_class_aif, metrics_class_ahf, + metrics_class_cis, metrics_class_csz, metrics_class_dit, + metrics_class_impl, metrics_class_mif, metrics_class_mhf, + metrics_class_noc, metrics_class_pf, metrics_class_vars, + metrics_class_varsnp, metrics_class_varsi, + metrics_class_wmc, metrics_class_wmcnp, metrics_class_wmci) + VALUES(:runId, :classId, :coverage, :loc, :locExecutable, + :locExecuted, :aif, :ahf, :cis, :csz, :dit, :impl, + :mif, :mhf, :noc, :pf, :vars, :varsnp, :varsi, + :wmc, :wmcnp, :wmci);' + ); + + $stmtSelectMethodId = $this->dbh->prepare( + 'SELECT code_method_id + FROM code_file, code_class, code_method + WHERE code_class.code_file_id = code_file.code_file_id + AND code_class.code_class_id = code_method.code_class_id + AND code_file.revision = :revision + AND code_class.code_class_name = :className + AND code_method.code_method_name = :methodName;' + ); + + $stmtInsertMethod = $this->dbh->prepare( + 'INSERT INTO metrics_method + (run_id, code_method_id, metrics_method_coverage, + metrics_method_loc, metrics_method_loc_executable, metrics_method_loc_executed, + metrics_method_ccn, metrics_method_crap, metrics_method_npath) + VALUES(:runId, :methodId, :coverage, :loc, + :locExecutable, :locExecuted, :ccn, :crap, :npath);' + ); + + foreach ($fileMetrics->getFunctions() as $functionMetrics) { + $functionName = $functionMetrics->getFunction()->getName(); + + $stmtSelectFunctionId->bindParam(':functionName', $functionName, PDO::PARAM_STR); + $stmtSelectFunctionId->bindParam(':revision', $revision, PDO::PARAM_INT); + $stmtSelectFunctionId->execute(); + + $functionId = (int)$stmtSelectFunctionId->fetchColumn(); + $stmtSelectFunctionId->closeCursor(); + + $functionCoverage = $functionMetrics->getCoverage(); + $functionLoc = $functionMetrics->getLoc(); + $functionLocExecutable = $functionMetrics->getLocExecutable(); + $functionLocExecuted = $functionMetrics->getLocExecuted(); + $functionCcn = $functionMetrics->getCCN(); + $functionCrap = $functionMetrics->getCrapIndex(); + $functionNpath = $functionMetrics->getNPath(); + + $stmtInsertFunction->bindParam(':runId', $runId, PDO::PARAM_INT); + $stmtInsertFunction->bindParam(':functionId', $functionId, PDO::PARAM_INT); + $stmtInsertFunction->bindParam(':coverage', $functionCoverage); + $stmtInsertFunction->bindParam(':loc', $functionLoc, PDO::PARAM_INT); + $stmtInsertFunction->bindParam(':locExecutable', $functionLocExecutable, PDO::PARAM_INT); + $stmtInsertFunction->bindParam(':locExecuted', $functionLocExecuted, PDO::PARAM_INT); + $stmtInsertFunction->bindParam(':ccn', $functionCcn, PDO::PARAM_INT); + $stmtInsertFunction->bindParam(':crap', $functionCrap); + $stmtInsertFunction->bindParam(':npath', $functionNpath, PDO::PARAM_INT); + $stmtInsertFunction->execute(); + } + + foreach ($fileMetrics->getClasses() as $classMetrics) { + $className = $classMetrics->getClass()->getName(); + + $stmtSelectClassId->bindParam(':className', $className, PDO::PARAM_STR); + $stmtSelectClassId->bindParam(':revision', $revision, PDO::PARAM_INT); + $stmtSelectClassId->execute(); + + $classId = (int)$stmtSelectClassId->fetchColumn(); + $stmtSelectClassId->closeCursor(); + + $classCoverage = $classMetrics->getCoverage(); + $classLoc = $classMetrics->getLoc(); + $classLocExecutable = $classMetrics->getLocExecutable(); + $classLocExecuted = $classMetrics->getLocExecuted(); + $classAif = $classMetrics->getAIF(); + $classAhf = $classMetrics->getAHF(); + $classCis = $classMetrics->getCIS(); + $classCsz = $classMetrics->getCSZ(); + $classDit = $classMetrics->getDIT(); + $classImpl = $classMetrics->getIMPL(); + $classMif = $classMetrics->getMIF(); + $classMhf = $classMetrics->getMHF(); + $classNoc = $classMetrics->getNOC(); + $classPf = $classMetrics->getPF(); + $classVars = $classMetrics->getVARS(); + $classVarsnp = $classMetrics->getVARSnp(); + $classVarsi = $classMetrics->getVARSi(); + $classWmc = $classMetrics->getWMC(); + $classWmcnp = $classMetrics->getWMCnp(); + $classWmci = $classMetrics->getWMCi(); + + $stmtInsertClass->bindParam(':runId', $runId, PDO::PARAM_INT); + $stmtInsertClass->bindParam(':classId', $classId, PDO::PARAM_INT); + $stmtInsertClass->bindParam(':coverage', $classCoverage); + $stmtInsertClass->bindParam(':loc', $classLoc, PDO::PARAM_INT); + $stmtInsertClass->bindParam(':locExecutable', $classLocExecutable, PDO::PARAM_INT); + $stmtInsertClass->bindParam(':locExecuted', $classLocExecuted, PDO::PARAM_INT); + $stmtInsertClass->bindParam(':aif', $classAif); + $stmtInsertClass->bindParam(':ahf', $classAhf); + $stmtInsertClass->bindParam(':cis', $classCis, PDO::PARAM_INT); + $stmtInsertClass->bindParam(':csz', $classCsz, PDO::PARAM_INT); + $stmtInsertClass->bindParam(':dit', $classDit, PDO::PARAM_INT); + $stmtInsertClass->bindParam(':impl', $classImpl, PDO::PARAM_INT); + $stmtInsertClass->bindParam(':mif', $classMif); + $stmtInsertClass->bindParam(':mhf', $classMhf); + $stmtInsertClass->bindParam(':noc', $classNoc, PDO::PARAM_INT); + $stmtInsertClass->bindParam(':pf', $classPf); + $stmtInsertClass->bindParam(':vars', $classVars, PDO::PARAM_INT); + $stmtInsertClass->bindParam(':varsnp', $classVarsnp, PDO::PARAM_INT); + $stmtInsertClass->bindParam(':varsi', $classVarsi, PDO::PARAM_INT); + $stmtInsertClass->bindParam(':wmc', $classWmc, PDO::PARAM_INT); + $stmtInsertClass->bindParam(':wmcnp', $classWmcnp, PDO::PARAM_INT); + $stmtInsertClass->bindParam(':wmci', $classWmci, PDO::PARAM_INT); + $stmtInsertClass->execute(); + + foreach ($classMetrics->getMethods() as $methodMetrics) { + $methodName = $methodMetrics->getMethod()->getName(); + + $stmtSelectMethodId->bindParam(':className', $className, PDO::PARAM_STR); + $stmtSelectMethodId->bindParam(':methodName', $methodName, PDO::PARAM_STR); + $stmtSelectMethodId->bindParam(':revision', $revision, PDO::PARAM_INT); + $stmtSelectMethodId->execute(); + + $methodId = (int)$stmtSelectMethodId->fetchColumn(); + $stmtSelectMethodId->closeCursor(); + + $methodCoverage = $methodMetrics->getCoverage(); + $methodLoc = $methodMetrics->getLoc(); + $methodLocExecutable = $methodMetrics->getLocExecutable(); + $methodLocExecuted = $methodMetrics->getLocExecuted(); + $methodCcn = $methodMetrics->getCCN(); + $methodCrap = $methodMetrics->getCrapIndex(); + $methodNpath = $methodMetrics->getNPath(); + + $stmtInsertMethod->bindParam(':runId', $runId, PDO::PARAM_INT); + $stmtInsertMethod->bindParam(':methodId', $methodId, PDO::PARAM_INT); + $stmtInsertMethod->bindParam(':coverage', $methodCoverage); + $stmtInsertMethod->bindParam(':loc', $methodLoc, PDO::PARAM_INT); + $stmtInsertMethod->bindParam(':locExecutable', $methodLocExecutable, PDO::PARAM_INT); + $stmtInsertMethod->bindParam(':locExecuted', $methodLocExecuted, PDO::PARAM_INT); + $stmtInsertMethod->bindParam(':ccn', $methodCcn, PDO::PARAM_INT); + $stmtInsertMethod->bindParam(':crap', $methodCrap); + $stmtInsertMethod->bindParam(':npath', $methodNpath, PDO::PARAM_INT); + $stmtInsertMethod->execute(); + } + } + + unset($stmtSelectFunctionId); + unset($stmtInsertFunction); + unset($stmtSelectClassId); + unset($stmtInsertClass); + unset($stmtSelectMethodId); + unset($stmtInsertMethod); + + $stmt = $this->dbh->prepare( + 'SELECT code_line_id, code_line_covered + FROM code_line + WHERE code_file_id = :fileId + AND code_line_number = :lineNumber;' + ); + + $stmt2 = $this->dbh->prepare( + 'UPDATE code_line + SET code_line_covered = :lineCovered + WHERE code_line_id = :lineId;' + ); + + $stmt3 = $this->dbh->prepare( + 'INSERT INTO code_coverage + (test_id, code_line_id) + VALUES(:testId, :lineId);' + ); + + for ($lineNumber = 1; $lineNumber <= $fileLoc; $lineNumber++) { + $coveringTests = PHPUnit_Util_CodeCoverage::getCoveringTests( + $codeCoverage, $file, $lineNumber + ); + + if (is_array($coveringTests)) { + $stmt->bindParam(':fileId', $fileId, PDO::PARAM_INT); + $stmt->bindParam(':lineNumber', $lineNumber, PDO::PARAM_INT); + $stmt->execute(); + + $codeLineId = (int)$stmt->fetchColumn(0); + $oldCoverageFlag = (int)$stmt->fetchColumn(1); + $newCoverageFlag = isset($summary[$file][$lineNumber]) ? 1 : 0; + + if (($oldCoverageFlag == 0 && $newCoverageFlag != 0) || + ($oldCoverageFlag < 0 && $newCoverageFlag > 0)) { + $stmt2->bindParam(':lineCovered', $newCoverageFlag, PDO::PARAM_INT); + $stmt2->bindParam(':lineId', $codeLineId, PDO::PARAM_INT); + $stmt2->execute(); + } + + foreach ($coveringTests as $test) { + $stmt3->bindParam(':testId', $test->__db_id, PDO::PARAM_INT); + $stmt3->bindParam(':lineId', $codeLineId, PDO::PARAM_INT); + $stmt3->execute(); + } + } + } + } + + unset($stmt); + unset($stmt2); + unset($stmt3); + + $stmt = $this->dbh->prepare( + 'SELECT code_method.code_method_id + FROM code_class, code_method + WHERE code_class.code_class_id = code_method.code_class_id + AND code_class.code_class_name = :className + AND code_method.code_method_name = :methodName;' + ); + + $stmt2 = $this->dbh->prepare( + 'UPDATE test + SET code_method_id = :methodId + WHERE test_id = :testId;' + ); + + foreach ($result->topTestSuite() as $test) { + if ($test instanceof PHPUnit_Framework_TestCase) { + $className = get_class($test); + $methodName = $test->getName(); + + $stmt->bindParam(':className', $className, PDO::PARAM_STR); + $stmt->bindParam(':methodName', $methodName, PDO::PARAM_STR); + $stmt->execute(); + + $methodId = (int)$stmt->fetchColumn(); + + $stmt2->bindParam(':methodId', $methodId, PDO::PARAM_INT); + $stmt2->bindParam(':testId', $test->__db_id, PDO::PARAM_INT); + $stmt2->execute(); + } + } + + unset($stmt); + unset($stmt2); + + $stmt = $this->dbh->prepare( + 'INSERT INTO metrics_project + (run_id, metrics_project_cls, metrics_project_clsa, + metrics_project_clsc, metrics_project_roots, + metrics_project_leafs, metrics_project_interfs, + metrics_project_maxdit) + VALUES(:runId, :cls, :clsa, :clsc, :roots, :leafs, + :interfs, :maxdit);' + ); + + $cls = $projectMetrics->getCLS(); + $clsa = $projectMetrics->getCLSa(); + $clsc = $projectMetrics->getCLSc(); + $interfs = $projectMetrics->getInterfs(); + $roots = $projectMetrics->getRoots(); + $leafs = $projectMetrics->getLeafs(); + $maxDit = $projectMetrics->getMaxDit(); + + $stmt->bindParam(':runId', $runId, PDO::PARAM_INT); + $stmt->bindParam(':cls', $cls, PDO::PARAM_INT); + $stmt->bindParam(':clsa', $clsa, PDO::PARAM_INT); + $stmt->bindParam(':clsc', $clsc, PDO::PARAM_INT); + $stmt->bindParam(':roots', $roots, PDO::PARAM_INT); + $stmt->bindParam(':leafs', $leafs, PDO::PARAM_INT); + $stmt->bindParam(':interfs', $interfs, PDO::PARAM_INT); + $stmt->bindParam(':maxdit', $maxDit, PDO::PARAM_INT); + $stmt->execute(); + + unset($stmt); + + $stmt = $this->dbh->prepare( + 'UPDATE code_class + SET code_class_parent_id = :parentClassId + WHERE code_class_id = :classId;' + ); + + $stmt2 = $this->dbh->prepare( + 'SELECT code_class.code_class_id as code_class_id + FROM code_class, code_file + WHERE code_class.code_file_id = code_file.code_file_id + AND code_file.revision = :revision + AND code_class.code_class_name = :parentClassName;' + ); + + foreach ($storedClasses as $className => $classId) { + $class = new ReflectionClass($className); + $parentClass = $class->getParentClass(); + + if ($parentClass !== FALSE) { + $parentClassName = $parentClass->getName(); + $parentClassId = 0; + + if (isset($storedClasses[$parentClassName])) { + $parentClassId = $storedClasses[$parentClassName]; + } else { + $stmt2->bindParam(':parentClassName', $parentClassName, PDO::PARAM_STR); + $stmt2->bindParam(':revision', $revision, PDO::PARAM_INT); + $stmt2->execute(); + + $parentClassId = (int)$stmt->fetchColumn(); + } + + if ($parentClassId > 0) { + $stmt->bindParam(':classId', $classId, PDO::PARAM_INT); + $stmt->bindParam(':parentClassId', $parentClassId, PDO::PARAM_INT); + $stmt->execute(); + } + } + } + + unset($stmt); + unset($stmt2); + + $this->dbh->commit(); + } +} +?> Property changes on: test/PHPUnit/Util/Log/CodeCoverage/Database.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/Log/PMD.php =================================================================== --- test/PHPUnit/Util/Log/PMD.php (revision 0) +++ test/PHPUnit/Util/Log/PMD.php (revision 0) @@ -0,0 +1,340 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: PMD.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/Runner/Version.php'; +require_once 'PHPUnit/Util/Metrics/Project.php'; +require_once 'PHPUnit/Util/Log/PMD/Rule/Class.php'; +require_once 'PHPUnit/Util/Log/PMD/Rule/File.php'; +require_once 'PHPUnit/Util/Log/PMD/Rule/Function.php'; +require_once 'PHPUnit/Util/Log/PMD/Rule/Project.php'; +require_once 'PHPUnit/Util/Class.php'; +require_once 'PHPUnit/Util/CodeCoverage.php'; +require_once 'PHPUnit/Util/Filter.php'; +require_once 'PHPUnit/Util/FilterIterator.php'; +require_once 'PHPUnit/Util/Printer.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Generates an XML logfile with software metrics information using the + * PMD format "documented" at + * http://svn.atlassian.com/fisheye/browse/~raw,r=7084/public/contrib/bamboo/bamboo-pmd-plugin/trunk/src/test/resources/test-pmd-report.xml + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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_Log_PMD extends PHPUnit_Util_Printer +{ + protected $added; + + protected $rules = array( + 'project' => array(), + 'file' => array(), + 'class' => array(), + 'function' => array() + ); + + /** + * Constructor. + * + * @param mixed $out + * @param array $configuration + * @throws InvalidArgumentException + * @access public + */ + public function __construct($out = NULL, array $configuration = array()) + { + parent::__construct($out); + $this->loadClasses($configuration); + } + + /** + * @param PHPUnit_Framework_TestResult $result + * @access public + */ + public function process(PHPUnit_Framework_TestResult $result) + { + $codeCoverage = $result->getCodeCoverageInformation(); + $summary = PHPUnit_Util_CodeCoverage::getSummary($codeCoverage); + $files = array_keys($summary); + $metrics = new PHPUnit_Util_Metrics_Project($files, $summary); + + $document = new DOMDocument('1.0', 'UTF-8'); + $document->formatOutput = TRUE; + + $pmd = $document->createElement('pmd'); + $pmd->setAttribute('version', 'PHPUnit ' . PHPUnit_Runner_Version::id()); + $document->appendChild($pmd); + + foreach ($this->rules['project'] as $ruleName => $rule) { + $result = $rule->apply($metrics); + + if ($result !== NULL) { + $this->addViolation( + $result, + $pmd, + $rule + ); + } + } + + foreach ($metrics->getFiles() as $fileName => $fileMetrics) { + $xmlFile = $document->createElement('file'); + $xmlFile->setAttribute('name', $fileName); + + $this->added = FALSE; + + foreach ($this->rules['file'] as $ruleName => $rule) { + $result = $rule->apply($fileMetrics); + + if ($result !== NULL) { + $this->addViolation( + $result, + $xmlFile, + $rule + ); + + $this->added = TRUE; + } + } + + foreach ($fileMetrics->getClasses() as $className => $classMetrics) { + if (!$classMetrics->getClass()->isInterface()) { + $classStartLine = $classMetrics->getClass()->getStartLine(); + $classEndLine = $classMetrics->getClass()->getEndLine(); + $classPackage = $classMetrics->getPackage(); + + foreach ($this->rules['class'] as $ruleName => $rule) { + $result = $rule->apply($classMetrics); + + if ($result !== NULL) { + $this->addViolation( + $result, + $xmlFile, + $rule, + $classStartLine, + $classEndLine, + $classPackage, + $className + ); + + $this->added = TRUE; + } + } + + foreach ($classMetrics->getMethods() as $methodName => $methodMetrics) { + if (!$methodMetrics->getMethod()->isAbstract()) { + $this->processFunctionOrMethod($xmlFile, $methodMetrics, $classPackage); + } + } + } + } + + foreach ($fileMetrics->getFunctions() as $functionName => $functionMetrics) { + $this->processFunctionOrMethod($xmlFile, $functionMetrics); + } + + if ($this->added) { + $pmd->appendChild($xmlFile); + } + } + + $this->write($document->saveXML()); + $this->flush(); + } + + /** + * @param string $violation + * @param DOMElement $element + * @param PHPUnit_Util_Log_PMD_Rule $rule + * @param integer $line + * @param integer $toLine + * @param string $package + * @param string $class + * @param string $method + * @access public + */ + protected function addViolation($violation, DOMElement $element, PHPUnit_Util_Log_PMD_Rule $rule, $line = '', $toLine = '', $package = '', $class = '', $method = '', $function = '') + { + $violationXml = $element->appendChild( + $element->ownerDocument->createElement('violation', $violation) + ); + + $violationXml->setAttribute('rule', $rule->getName()); + $violationXml->setAttribute('priority', $rule->getPriority()); + + if (!empty($line)) { + $violationXml->setAttribute('line', $line); + } + + if (!empty($toLine)) { + $violationXml->setAttribute('to-line', $toLine); + } + + if (empty($package)) { + $package = 'global'; + } + + if (!empty($package)) { + $violationXml->setAttribute('package', $package); + } + + if (!empty($class)) { + $violationXml->setAttribute('class', $class); + } + + if (!empty($method)) { + $violationXml->setAttribute('method', $method); + } + + if (!empty($function)) { + $violationXml->setAttribute('function', $function); + } + } + + protected function processFunctionOrMethod(DOMElement $element, $metrics, $package = '') + { + $scope = ''; + + if ($metrics->getFunction() instanceof ReflectionMethod) { + $scope = $metrics->getFunction()->getDeclaringClass()->getName(); + } + + $startLine = $metrics->getFunction()->getStartLine(); + $endLine = $metrics->getFunction()->getEndLine(); + $name = $metrics->getFunction()->getName(); + + foreach ($this->rules['function'] as $ruleName => $rule) { + $result = $rule->apply($metrics); + + if ($result !== NULL) { + $this->addViolation( + $result, + $element, + $rule, + $startLine, + $endLine, + $package, + $scope, + $name + ); + + $this->added = TRUE; + } + } + } + + protected function loadClasses(array $configuration) + { + $basedir = dirname(__FILE__) . DIRECTORY_SEPARATOR . + 'PMD' . DIRECTORY_SEPARATOR . 'Rule'; + + $dirs = array( + $basedir . DIRECTORY_SEPARATOR . 'Class', + $basedir . DIRECTORY_SEPARATOR . 'File', + $basedir . DIRECTORY_SEPARATOR . 'Function', + $basedir . DIRECTORY_SEPARATOR . 'Project' + ); + + foreach ($dirs as $dir) { + if (file_exists($dir)) { + $iterator = new PHPUnit_Util_FilterIterator( + new RecursiveIteratorIterator( + new RecursiveDirectoryIterator($dir) + ), + '.php' + ); + + foreach ($iterator as $file) { + include_once $file->getPathname(); + } + } + } + + $classes = get_declared_classes(); + + foreach ($classes as $className) { + $class = new ReflectionClass($className); + + if (!$class->isAbstract() && $class->isSubclassOf('PHPUnit_Util_Log_PMD_Rule')) { + $rule = explode('_', $className); + $rule = $rule[count($rule)-1]; + + if (isset($configuration[$className])) { + $object = new $className( + $configuration[$className]['threshold'], + $configuration[$className]['priority'] + ); + } else { + $object = new $className; + } + + if ($class->isSubclassOf('PHPUnit_Util_Log_PMD_Rule_Project')) { + $this->rules['project'][$rule] = $object; + } + + if ($class->isSubclassOf('PHPUnit_Util_Log_PMD_Rule_File')) { + $this->rules['file'][$rule] = $object; + } + + else if ($class->isSubclassOf('PHPUnit_Util_Log_PMD_Rule_Class')) { + $this->rules['class'][$rule] = $object; + } + + else if ($class->isSubclassOf('PHPUnit_Util_Log_PMD_Rule_Function')) { + $this->rules['function'][$rule] = $object; + } + } + } + } +} +?> Property changes on: test/PHPUnit/Util/Log/PMD.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/Log/XML.php =================================================================== --- test/PHPUnit/Util/Log/XML.php (revision 0) +++ test/PHPUnit/Util/Log/XML.php (revision 0) @@ -0,0 +1,458 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: XML.php 1985 2007-12-26 18:11:55Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 2.3.0 + */ + +require_once 'PHPUnit/Framework.php'; +require_once 'PHPUnit/Util/Class.php'; +require_once 'PHPUnit/Util/Filter.php'; +require_once 'PHPUnit/Util/Printer.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * A TestListener that generates an XML-based logfile + * of the test execution. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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.1.0 + */ +class PHPUnit_Util_Log_XML extends PHPUnit_Util_Printer implements PHPUnit_Framework_TestListener +{ + /** + * @var DOMDocument + * @access protected + */ + protected $document; + + /** + * @var DOMElement + * @access protected + */ + protected $root; + + /** + * @var boolean + * @access protected + */ + protected $logIncompleteSkipeed = FALSE; + + /** + * @var boolean + * @access protected + */ + protected $writeDocument = TRUE; + + /** + * @var DOMElement[] + * @access protected + */ + protected $testSuites = array(); + + /** + * @var integer[] + * @access protected + */ + protected $testSuiteTests = array(0); + + /** + * @var integer[] + * @access protected + */ + protected $testSuiteErrors = array(0); + + /** + * @var integer[] + * @access protected + */ + protected $testSuiteFailures = array(0); + + /** + * @var integer[] + * @access protected + */ + protected $testSuiteTimes = array(0); + + /** + * @var integer + * @access protected + */ + protected $testSuiteLevel = 0; + + /** + * @var DOMElement + * @access protected + */ + protected $currentTestCase = NULL; + + /** + * @var boolean + * @access protected + */ + protected $attachCurrentTestCase = TRUE; + + /** + * Constructor. + * + * @param mixed $out + * @param boolean $logIncompleteSkipped + * @access public + */ + public function __construct($out = NULL, $logIncompleteSkipped = FALSE) + { + $this->document = new DOMDocument('1.0', 'UTF-8'); + $this->document->formatOutput = TRUE; + + $this->root = $this->document->createElement('testsuites'); + $this->document->appendChild($this->root); + + parent::__construct($out); + + $this->logIncompleteSkipped = $logIncompleteSkipped; + } + + /** + * Flush buffer and close output. + * + * @access public + */ + public function flush() + { + if ($this->writeDocument === TRUE) { + $this->write($this->getXML()); + } + + parent::flush(); + } + + /** + * An error occurred. + * + * @param PHPUnit_Framework_Test $test + * @param Exception $e + * @param float $time + * @access public + */ + public function addError(PHPUnit_Framework_Test $test, Exception $e, $time) + { + $error = $this->document->createElement('error'); + $error->setAttribute('type', get_class($e)); + + if ($test instanceof PHPUnit_Framework_SelfDescribing) { + $buffer = $test->toString() . "\n"; + } else { + $buffer = ''; + } + + $buffer .= PHPUnit_Framework_TestFailure::exceptionToString($e) . "\n" . + PHPUnit_Util_Filter::getFilteredStacktrace($e, FALSE); + + $error->appendChild( + $this->document->createCDATASection( + utf8_encode($buffer) + ) + ); + + $this->currentTestCase->appendChild($error); + + $this->testSuiteErrors[$this->testSuiteLevel]++; + } + + /** + * A failure occurred. + * + * @param PHPUnit_Framework_Test $test + * @param PHPUnit_Framework_AssertionFailedError $e + * @param float $time + * @access public + */ + public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) + { + $failure = $this->document->createElement('failure'); + $failure->setAttribute('type', get_class($e)); + + if ($test instanceof PHPUnit_Framework_SelfDescribing) { + $buffer = $test->toString() . "\n"; + } else { + $buffer = ''; + } + + $buffer .= PHPUnit_Framework_TestFailure::exceptionToString($e) . "\n" . + PHPUnit_Util_Filter::getFilteredStacktrace($e, FALSE); + + $failure->appendChild( + $this->document->createCDATASection( + utf8_encode($buffer) + ) + ); + + $this->currentTestCase->appendChild($failure); + + $this->testSuiteFailures[$this->testSuiteLevel]++; + } + + /** + * Incomplete test. + * + * @param PHPUnit_Framework_Test $test + * @param Exception $e + * @param float $time + * @access public + */ + public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time) + { + if ($this->logIncompleteSkipped) { + $error = $this->document->createElement('error'); + $error->setAttribute('type', get_class($e)); + + $error->appendChild( + $this->document->createCDATASection( + utf8_encode( + "Incomplete Test\n" . + PHPUnit_Util_Filter::getFilteredStacktrace($e, FALSE) + ) + ) + ); + + $this->currentTestCase->appendChild($error); + + $this->testSuiteErrors[$this->testSuiteLevel]++; + } else { + $this->attachCurrentTestCase = FALSE; + } + } + + /** + * Skipped test. + * + * @param PHPUnit_Framework_Test $test + * @param Exception $e + * @param float $time + * @access public + * @since Method available since Release 3.0.0 + */ + public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time) + { + if ($this->logIncompleteSkipped) { + $error = $this->document->createElement('error'); + $error->setAttribute('type', get_class($e)); + + $error->appendChild( + $this->document->createCDATASection( + utf8_encode( + "Skipped Test\n" . + PHPUnit_Util_Filter::getFilteredStacktrace($e, FALSE) + ) + ) + ); + + $this->currentTestCase->appendChild($error); + + $this->testSuiteErrors[$this->testSuiteLevel]++; + } else { + $this->attachCurrentTestCase = FALSE; + } + } + + /** + * A testsuite started. + * + * @param PHPUnit_Framework_TestSuite $suite + * @access public + * @since Method available since Release 2.2.0 + */ + public function startTestSuite(PHPUnit_Framework_TestSuite $suite) + { + $testSuite = $this->document->createElement('testsuite'); + $testSuite->setAttribute('name', $suite->getName()); + + if (class_exists($suite->getName(), FALSE)) { + try { + $class = new ReflectionClass($suite->getName()); + + $testSuite->setAttribute('file', $class->getFileName()); + + $packageInformation = PHPUnit_Util_Class::getPackageInformation( + $suite->getName() + ); + + if (!empty($packageInformation['category'])) { + $testSuite->setAttribute('category', $packageInformation['category']); + } + + if (!empty($packageInformation['package'])) { + $testSuite->setAttribute('package', $packageInformation['package']); + } + + if (!empty($packageInformation['subpackage'])) { + $testSuite->setAttribute('subpackage', $packageInformation['subpackage']); + } + } + + catch (ReflectionException $e) { + } + } + + if ($this->testSuiteLevel > 0) { + $this->testSuites[$this->testSuiteLevel]->appendChild($testSuite); + } else { + $this->root->appendChild($testSuite); + } + + $this->testSuiteLevel++; + $this->testSuites[$this->testSuiteLevel] = $testSuite; + $this->testSuiteTests[$this->testSuiteLevel] = 0; + $this->testSuiteErrors[$this->testSuiteLevel] = 0; + $this->testSuiteFailures[$this->testSuiteLevel] = 0; + $this->testSuiteTimes[$this->testSuiteLevel] = 0; + } + + /** + * A testsuite ended. + * + * @param PHPUnit_Framework_TestSuite $suite + * @access public + * @since Method available since Release 2.2.0 + */ + public function endTestSuite(PHPUnit_Framework_TestSuite $suite) + { + $this->testSuites[$this->testSuiteLevel]->setAttribute('tests', $this->testSuiteTests[$this->testSuiteLevel]); + $this->testSuites[$this->testSuiteLevel]->setAttribute('failures', $this->testSuiteFailures[$this->testSuiteLevel]); + $this->testSuites[$this->testSuiteLevel]->setAttribute('errors', $this->testSuiteErrors[$this->testSuiteLevel]); + $this->testSuites[$this->testSuiteLevel]->setAttribute('time', sprintf('%F', $this->testSuiteTimes[$this->testSuiteLevel])); + + if ($this->testSuiteLevel > 1) { + $this->testSuiteTests[$this->testSuiteLevel - 1] += $this->testSuiteTests[$this->testSuiteLevel]; + $this->testSuiteErrors[$this->testSuiteLevel - 1] += $this->testSuiteErrors[$this->testSuiteLevel]; + $this->testSuiteFailures[$this->testSuiteLevel - 1] += $this->testSuiteFailures[$this->testSuiteLevel]; + $this->testSuiteTimes[$this->testSuiteLevel - 1] += $this->testSuiteTimes[$this->testSuiteLevel]; + } + + $this->testSuiteLevel--; + } + + /** + * A test started. + * + * @param PHPUnit_Framework_Test $test + * @access public + */ + public function startTest(PHPUnit_Framework_Test $test) + { + $testCase = $this->document->createElement('testcase'); + $testCase->setAttribute('name', $test->getName()); + + if ($test instanceof PHPUnit_Framework_TestCase) { + $class = new ReflectionClass($test); + $method = $class->getMethod($test->getName()); + + $testCase->setAttribute('class', $class->getName()); + $testCase->setAttribute('file', $class->getFileName()); + $testCase->setAttribute('line', $method->getStartLine()); + } + + $this->currentTestCase = $testCase; + } + + /** + * A test ended. + * + * @param PHPUnit_Framework_Test $test + * @param float $time + * @access public + */ + public function endTest(PHPUnit_Framework_Test $test, $time) + { + if ($this->attachCurrentTestCase) { + $this->currentTestCase->setAttribute('time', sprintf('%F', $time)); + + $this->testSuites[$this->testSuiteLevel]->appendChild( + $this->currentTestCase + ); + + $this->testSuiteTests[$this->testSuiteLevel]++; + $this->testSuiteTimes[$this->testSuiteLevel] += $time; + } + + $this->currentTestCase = NULL; + $this->attachCurrentTestCase = TRUE; + } + + /** + * Returns the XML as a string. + * + * @return string + * @access public + * @since Method available since Release 2.2.0 + */ + public function getXML() + { + return $this->document->saveXML(); + } + + /** + * Enables or disables the writing of the document + * in flush(). + * + * This is a "hack" needed for the integration of + * PHPUnit with Phing. + * + * @return string + * @access public + * @since Method available since Release 2.2.0 + */ + public function setWriteDocument($flag) + { + if (is_bool($flag)) { + $this->writeDocument = $flag; + } + } +} +?> Property changes on: test/PHPUnit/Util/Log/XML.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/Log/Database.php =================================================================== --- test/PHPUnit/Util/Log/Database.php (revision 0) +++ test/PHPUnit/Util/Log/Database.php (revision 0) @@ -0,0 +1,529 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: Database.php 2102 2008-01-15 07:35:10Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 3.1.0 + */ + +require_once 'PHPUnit/Framework.php'; +require_once 'PHPUnit/Runner/BaseTestRunner.php'; +require_once 'PHPUnit/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Writes test result and code coverage data to a database. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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.0 + */ +class PHPUnit_Util_Log_Database implements PHPUnit_Framework_TestListener +{ + /** + * @var PHPUnit_Util_Log_Database + * @access protected + * @static + */ + protected static $instance = NULL; + + /** + * @var integer + * @access protected + */ + protected $currentTestId; + + /** + * @var integer + * @access protected + */ + protected $runId; + + /** + * @var integer[] + * @access protected + */ + protected $testSuites = array(); + + /** + * @var boolean + * @access protected + */ + protected $currentTestSuccess = TRUE; + + /** + * @var PDO + * @access protected + */ + protected $dbh; + + /** + * Constructor. + * + * @param PDO $dbh + * @param integer $revision + * @param string $information + * @throws PDOException + * @throws RuntimeException + * @access protected + */ + protected function __construct(PDO $dbh, $revision, $information = '') + { + $this->dbh = $dbh; + + $stmt = $this->dbh->prepare( + 'INSERT INTO run + (timestamp, revision, information) + VALUES(:timestamp, :revision, :information);' + ); + + $timestamp = time(); + + $stmt->bindParam(':timestamp', $timestamp, PDO::PARAM_INT); + $stmt->bindParam(':revision', $revision, PDO::PARAM_INT); + $stmt->bindParam(':information', $information, PDO::PARAM_STR); + $stmt->execute(); + + $this->runId = $this->dbh->lastInsertId(); + } + + /** + * @param PDO $dbh + * @param integer $revision + * @param string $information + * @return PHPUnit_Util_Log_Database + * @throws InvalidArgumentException + * @throws PDOException + * @throws RuntimeException + * @access public + * @static + */ + public static function getInstance(PDO $dbh = NULL, $revision = '', $information = '') + { + if ($dbh === NULL) { + if (self::$instance != NULL) { + return self::$instance; + } else { + return FALSE; + } + } + + if (self::$instance != NULL) { + throw new RuntimeException; + } + + if (empty($revision)) { + throw new InvalidArgumentException; + } + + self::$instance = new PHPUnit_Util_Log_Database( + $dbh, $revision, $information + ); + + return self::$instance; + } + + /** + * Returns the ID of the current test. + * + * @return integer + * @access public + */ + public function getCurrentTestId() + { + return $this->currentTestId; + } + + /** + * Returns the ID of this test run. + * + * @return integer + * @access public + */ + public function getRunId() + { + return $this->runId; + } + + /** + * An error occurred. + * + * @param PHPUnit_Framework_Test $test + * @param Exception $e + * @param float $time + * @access public + */ + public function addError(PHPUnit_Framework_Test $test, Exception $e, $time) + { + $message = PHPUnit_Framework_TestFailure::exceptionToString($e) . "\n" . + PHPUnit_Util_Filter::getFilteredStacktrace($e, FALSE); + + $this->storeResult( + PHPUnit_Runner_BaseTestRunner::STATUS_ERROR, + $time, + $message + ); + + $this->updateParents( + $time, PHPUnit_Runner_BaseTestRunner::STATUS_ERROR + ); + + $this->currentTestSuccess = FALSE; + } + + /** + * A failure occurred. + * + * @param PHPUnit_Framework_Test $test + * @param PHPUnit_Framework_AssertionFailedError $e + * @param float $time + * @access public + */ + public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) + { + $message = PHPUnit_Framework_TestFailure::exceptionToString($e) . "\n" . + PHPUnit_Util_Filter::getFilteredStacktrace($e, FALSE); + + $this->storeResult( + PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE, + $time, + $message + ); + + $this->updateParents( + $time, PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE + ); + + $this->currentTestSuccess = FALSE; + } + + /** + * Incomplete test. + * + * @param PHPUnit_Framework_Test $test + * @param Exception $e + * @param float $time + * @access public + */ + public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time) + { + $message = PHPUnit_Framework_TestFailure::exceptionToString($e) . "\n" . + PHPUnit_Util_Filter::getFilteredStacktrace($e, FALSE); + + $this->storeResult( + PHPUnit_Runner_BaseTestRunner::STATUS_INCOMPLETE, + $time, + $message + ); + + $this->currentTestSuccess = FALSE; + } + + /** + * Skipped test. + * + * @param PHPUnit_Framework_Test $test + * @param Exception $e + * @param float $time + * @access public + */ + public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time) + { + $message = PHPUnit_Framework_TestFailure::exceptionToString($e) . "\n" . + PHPUnit_Util_Filter::getFilteredStacktrace($e, FALSE); + + $this->storeResult( + PHPUnit_Runner_BaseTestRunner::STATUS_SKIPPED, + $time, + $message + ); + + $this->currentTestSuccess = FALSE; + } + + /** + * A test suite started. + * + * @param PHPUnit_Framework_TestSuite $suite + * @access public + */ + public function startTestSuite(PHPUnit_Framework_TestSuite $suite) + { + if (empty($this->testSuites)) { + $testSuiteId = $this->insertRootNode($suite->getName()); + } else { + $testSuiteId = $this->insertNode($suite); + } + + $this->testSuites[] = array( + 'id' => $testSuiteId, + 'result' => PHPUnit_Runner_BaseTestRunner::STATUS_PASSED + ); + } + + /** + * A test suite ended. + * + * @param PHPUnit_Framework_TestSuite $suite + * @access public + */ + public function endTestSuite(PHPUnit_Framework_TestSuite $suite) + { + array_pop($this->testSuites); + } + + /** + * A test started. + * + * @param PHPUnit_Framework_Test $test + * @access public + */ + public function startTest(PHPUnit_Framework_Test $test) + { + $this->insertNode($test); + $this->currentTestSuccess = TRUE; + } + + /** + * A test ended. + * + * @param PHPUnit_Framework_Test $test + * @param float $time + * @access public + */ + public function endTest(PHPUnit_Framework_Test $test, $time) + { + if ($this->currentTestSuccess) { + $this->storeResult( + PHPUnit_Runner_BaseTestRunner::STATUS_PASSED, $time + ); + + $this->updateParents($time); + } + } + + /** + * Inserts the root node into the tree. + * + * @param string $name + * @return integer + * @throws PDOException + * @access protected + */ + protected function insertRootNode($name) + { + $this->dbh->beginTransaction(); + + $stmt = $this->dbh->prepare( + 'INSERT INTO test + (run_id, test_name, node_left, node_right, node_is_leaf) + VALUES(:runId, :testName, 1, 2, 0);' + ); + + $stmt->bindParam(':runId', $this->runId, PDO::PARAM_INT); + $stmt->bindParam(':testName', $name, PDO::PARAM_STR); + $stmt->execute(); + + $rootId = $this->dbh->lastInsertId(); + + $stmt = $this->dbh->prepare( + 'UPDATE test + SET node_root = :root + WHERE test_id = :testId;' + ); + + $stmt->bindParam(':root', $rootId, PDO::PARAM_INT); + $stmt->bindParam(':testId', $rootId, PDO::PARAM_INT); + $stmt->execute(); + + $this->dbh->commit(); + + return $rootId; + } + + /** + * Inserts a node into the tree. + * + * @param PHPUnit_Framework_Test $test + * @throws PDOException + * @access protected + */ + protected function insertNode(PHPUnit_Framework_Test $test) + { + $isLeaf = (int)!$test instanceof PHPUnit_Framework_TestSuite; + + $this->dbh->beginTransaction(); + + $stmt = $this->dbh->prepare( + 'SELECT node_right + FROM test + WHERE test_id = :testId;' + ); + + $stmt->bindParam(':testId', $this->testSuites[count($this->testSuites)-1]['id'], PDO::PARAM_INT); + $stmt->execute(); + + $right = (int)$stmt->fetchColumn(); + unset($stmt); + + $stmt = $this->dbh->prepare( + 'UPDATE test + SET node_left = node_left + 2 + WHERE node_root = :root + AND node_left > :left;' + ); + + $stmt->bindParam(':root', $this->testSuites[0]['id'], PDO::PARAM_INT); + $stmt->bindParam(':left', $right, PDO::PARAM_INT); + $stmt->execute(); + + $stmt = $this->dbh->prepare( + 'UPDATE test + SET node_right = node_right + 2 + WHERE node_root = :root + AND node_right >= :right;' + ); + + $stmt->bindParam(':root', $this->testSuites[0]['id'], PDO::PARAM_INT); + $stmt->bindParam(':right', $right, PDO::PARAM_INT); + $stmt->execute(); + + $testName = $test->getName(); + $left = $right; + $right = $right + 1; + + $stmt = $this->dbh->prepare( + 'INSERT INTO test + (run_id, test_name, test_result, test_message, + test_execution_time, node_root, node_left, node_right, + node_is_leaf) + VALUES(:runId, :testName, 0, "", 0, :root, :left, :right, + :isLeaf);' + ); + + $stmt->bindParam(':runId', $this->runId, PDO::PARAM_INT); + $stmt->bindParam(':testName', $testName, PDO::PARAM_STR); + $stmt->bindParam(':root', $this->testSuites[0]['id'], PDO::PARAM_INT); + $stmt->bindParam(':left', $left, PDO::PARAM_INT); + $stmt->bindParam(':right', $right, PDO::PARAM_INT); + $stmt->bindParam(':isLeaf', $isLeaf, PDO::PARAM_INT); + $stmt->execute(); + + $this->currentTestId = $this->dbh->lastInsertId(); + $this->dbh->commit(); + + if (!$test instanceof PHPUnit_Framework_TestSuite) { + $test->__db_id = $this->currentTestId; + } + + return $this->currentTestId; + } + + /** + * Stores a test result. + * + * @param integer $result + * @param float $time + * @param string $message + * @throws PDOException + * @access protected + */ + protected function storeResult($result = PHPUnit_Runner_BaseTestRunner::STATUS_PASSED, $time = 0, $message = '') + { + $stmt = $this->dbh->prepare( + 'UPDATE test + SET test_result = :result, + test_message = :message, + test_execution_time = :executionTime + WHERE test_id = :testId;' + ); + + $stmt->bindParam(':result', $result, PDO::PARAM_INT); + $stmt->bindParam(':message', $message, PDO::PARAM_STR); + $stmt->bindParam(':executionTime', $time); + $stmt->bindParam(':testId', $this->currentTestId, PDO::PARAM_INT); + $stmt->execute(); + } + + /** + * @param float $time + * @param integer $result + * @throws PDOException + * @access protected + */ + protected function updateParents($time, $result = NULL) + { + $stmtUpdateResultAndTime = $this->dbh->prepare( + 'UPDATE test + SET test_result = :result, + test_execution_time = test_execution_time + :time + WHERE test_id = :testSuiteId;' + ); + + $stmtUpdateTime = $this->dbh->prepare( + 'UPDATE test + SET test_execution_time = test_execution_time + :time + WHERE test_id = :testSuiteId;' + ); + + foreach ($this->testSuites as &$testSuite) { + if ($result > $testSuite['result']) { + $stmtUpdateResultAndTime->bindParam(':result', $result, PDO::PARAM_INT); + $stmtUpdateResultAndTime->bindParam(':testSuiteId', $testSuite['id'], PDO::PARAM_INT); + $stmtUpdateResultAndTime->bindParam(':time', $time); + $stmtUpdateResultAndTime->execute(); + + $testSuite['result'] = $result; + } else { + $stmtUpdateTime->bindParam(':testSuiteId', $testSuite['id'], PDO::PARAM_INT); + $stmtUpdateTime->bindParam(':time', $time); + $stmtUpdateTime->execute(); + } + } + } +} +?> Property changes on: test/PHPUnit/Util/Log/Database.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/Log/TAP.php =================================================================== --- test/PHPUnit/Util/Log/TAP.php (revision 0) +++ test/PHPUnit/Util/Log/TAP.php (revision 0) @@ -0,0 +1,242 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: TAP.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/Printer.php'; +require_once 'PHPUnit/Util/Test.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * A TestListener that generates a logfile of the + * test execution using the Test Anything Protocol (TAP). + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class PHPUnit_Util_Log_TAP extends PHPUnit_Util_Printer implements PHPUnit_Framework_TestListener +{ + /** + * @var integer + * @access protected + */ + protected $testNumber = 0; + + /** + * @var boolean + * @access protected + */ + protected $testSuccessful = TRUE; + + /** + * An error occurred. + * + * @param PHPUnit_Framework_Test $test + * @param Exception $e + * @param float $time + * @access public + */ + public function addError(PHPUnit_Framework_Test $test, Exception $e, $time) + { + $this->writeNotOk($test, 'Error'); + } + + /** + * A failure occurred. + * + * @param PHPUnit_Framework_Test $test + * @param PHPUnit_Framework_AssertionFailedError $e + * @param float $time + * @access public + */ + public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) + { + $this->writeNotOk($test, 'Failure'); + } + + /** + * Incomplete test. + * + * @param PHPUnit_Framework_Test $test + * @param Exception $e + * @param float $time + * @access public + */ + public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time) + { + $this->writeNotOk($test, '', 'TODO Incomplete Test'); + } + + /** + * Skipped test. + * + * @param PHPUnit_Framework_Test $test + * @param Exception $e + * @param float $time + * @access public + * @since Method available since Release 3.0.0 + */ + public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time) + { + $this->write( + sprintf( + "ok %d - # SKIP%s\n", + + $this->testNumber, + $e->getMessage() != '' ? ' ' . $e->getMessage() : '' + ) + ); + + $this->testSuccessful = FALSE; + } + + /** + * A testsuite started. + * + * @param PHPUnit_Framework_TestSuite $suite + * @access public + */ + public function startTestSuite(PHPUnit_Framework_TestSuite $suite) + { + if ($this->testNumber == 0) { + $this->write( + sprintf( + "1..%d\n", + + count($suite) + ) + ); + } + + $this->write( + sprintf( + "# TestSuite \"%s\" started.\n", + + $suite->getName() + ) + ); + } + + /** + * A testsuite ended. + * + * @param PHPUnit_Framework_TestSuite $suite + * @access public + */ + public function endTestSuite(PHPUnit_Framework_TestSuite $suite) + { + $this->write( + sprintf( + "# TestSuite \"%s\" ended.\n", + + $suite->getName() + ) + ); + } + + /** + * A test started. + * + * @param PHPUnit_Framework_Test $test + * @access public + */ + public function startTest(PHPUnit_Framework_Test $test) + { + $this->testNumber++; + $this->testSuccessful = TRUE; + } + + /** + * A test ended. + * + * @param PHPUnit_Framework_Test $test + * @param float $time + * @access public + */ + public function endTest(PHPUnit_Framework_Test $test, $time) + { + if ($this->testSuccessful === TRUE) { + $this->write( + sprintf( + "ok %d - %s\n", + + $this->testNumber, + PHPUnit_Util_Test::describe($test) + ) + ); + } + } + + /** + * @param PHPUnit_Framework_Test $test + * @param string $prefix + * @param string $directive + * @access protected + */ + protected function writeNotOk(PHPUnit_Framework_Test $test, $prefix = '', $directive = '') + { + $this->write( + sprintf( + "not ok %d - %s%s%s\n", + + $this->testNumber, + $prefix != '' ? $prefix . ': ' : '', + PHPUnit_Util_Test::describe($test), + $directive != '' ? ' # ' . $directive : '' + ) + ); + + $this->testSuccessful = FALSE; + } +} +?> Property changes on: test/PHPUnit/Util/Log/TAP.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/Log/CPD.php =================================================================== --- test/PHPUnit/Util/Log/CPD.php (revision 0) +++ test/PHPUnit/Util/Log/CPD.php (revision 0) @@ -0,0 +1,133 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: CPD.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/Runner/Version.php'; +require_once 'PHPUnit/Util/Metrics/Project.php'; +require_once 'PHPUnit/Util/CodeCoverage.php'; +require_once 'PHPUnit/Util/Filter.php'; +require_once 'PHPUnit/Util/Printer.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Generates an XML logfile with code duplication information. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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_Log_CPD extends PHPUnit_Util_Printer +{ + /** + * @param PHPUnit_Framework_TestResult $result + * @access public + */ + public function process(PHPUnit_Framework_TestResult $result, $minLines = 5, $minMatches = 70) + { + $codeCoverage = $result->getCodeCoverageInformation(); + $summary = PHPUnit_Util_CodeCoverage::getSummary($codeCoverage); + $files = array_keys($summary); + $metrics = new PHPUnit_Util_Metrics_Project($files, $summary, TRUE, $minLines, $minMatches); + + $document = new DOMDocument('1.0', 'UTF-8'); + $document->formatOutput = TRUE; + + $cpd = $document->createElement('pmd-cpd'); + $cpd->setAttribute('version', 'PHPUnit ' . PHPUnit_Runner_Version::id()); + $document->appendChild($cpd); + + foreach ($metrics->getDuplicates() as $duplicate) { + $xmlDuplication = $cpd->appendChild( + $document->createElement('duplication') + ); + + $xmlDuplication->setAttribute('lines', $duplicate['numLines']); + $xmlDuplication->setAttribute('tokens', $duplicate['numTokens']); + + $xmlFile = $xmlDuplication->appendChild( + $document->createElement('file') + ); + + $xmlFile->setAttribute('path', $duplicate['fileA']->getPath()); + $xmlFile->setAttribute('line', $duplicate['firstLineA']); + + $xmlFile = $xmlDuplication->appendChild( + $document->createElement('file') + ); + + $xmlFile->setAttribute('path', $duplicate['fileB']->getPath()); + $xmlFile->setAttribute('line', $duplicate['firstLineB']); + + $codefragment = $xmlDuplication->appendChild( + $document->createElement('codefragment') + ); + + $codefragment->appendChild( + $document->createCDATASection( + utf8_encode( + join( + '', + array_slice( + $duplicate['fileA']->getLines(), + $duplicate['firstLineA'] - 1, + $duplicate['numLines'] + ) + ) + ) + ) + ); + } + + $this->write($document->saveXML()); + $this->flush(); + } +} +?> Property changes on: test/PHPUnit/Util/Log/CPD.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/Log/Metrics.php =================================================================== --- test/PHPUnit/Util/Log/Metrics.php (revision 0) +++ test/PHPUnit/Util/Log/Metrics.php (revision 0) @@ -0,0 +1,184 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: Metrics.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/Runner/Version.php'; +require_once 'PHPUnit/Util/Metrics/Project.php'; +require_once 'PHPUnit/Util/Class.php'; +require_once 'PHPUnit/Util/CodeCoverage.php'; +require_once 'PHPUnit/Util/Filter.php'; +require_once 'PHPUnit/Util/Printer.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Generates an XML logfile with software metrics information. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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_Log_Metrics extends PHPUnit_Util_Printer +{ + /** + * @param PHPUnit_Framework_TestResult $result + * @access public + */ + public function process(PHPUnit_Framework_TestResult $result) + { + $codeCoverage = $result->getCodeCoverageInformation(); + $summary = PHPUnit_Util_CodeCoverage::getSummary($codeCoverage); + $files = array_keys($summary); + $projectMetrics = new PHPUnit_Util_Metrics_Project($files, $summary); + + $document = new DOMDocument('1.0', 'UTF-8'); + $document->formatOutput = TRUE; + + $metrics = $document->createElement('metrics'); + $metrics->setAttribute('files', count($projectMetrics->getFiles())); + $metrics->setAttribute('functions', count($projectMetrics->getFunctions())); + $metrics->setAttribute('cls', $projectMetrics->getCLS()); + $metrics->setAttribute('clsa', $projectMetrics->getCLSa()); + $metrics->setAttribute('clsc', $projectMetrics->getCLSc()); + $metrics->setAttribute('roots', $projectMetrics->getRoots()); + $metrics->setAttribute('leafs', $projectMetrics->getLeafs()); + $metrics->setAttribute('interfs', $projectMetrics->getInterfs()); + $metrics->setAttribute('maxdit', $projectMetrics->getMaxDit()); + + $document->appendChild($metrics); + + foreach ($projectMetrics->getFiles() as $fileName => $fileMetrics) { + $xmlFile = $metrics->appendChild( + $document->createElement('file') + ); + + $xmlFile->setAttribute('name', $fileName); + $xmlFile->setAttribute('classes', count($fileMetrics->getClasses())); + $xmlFile->setAttribute('functions', count($fileMetrics->getFunctions())); + $xmlFile->setAttribute('loc', $fileMetrics->getLoc()); + $xmlFile->setAttribute('cloc', $fileMetrics->getCloc()); + $xmlFile->setAttribute('ncloc', $fileMetrics->getNcloc()); + $xmlFile->setAttribute('locExecutable', $fileMetrics->getLocExecutable()); + $xmlFile->setAttribute('locExecuted', $fileMetrics->getLocExecuted()); + $xmlFile->setAttribute('coverage', sprintf('%F', $fileMetrics->getCoverage())); + + foreach ($fileMetrics->getClasses() as $className => $classMetrics) { + if (!$classMetrics->getClass()->implementsInterface('PHPUnit_Framework_Test')) { + $xmlClass = $document->createElement('class'); + + $xmlClass->setAttribute('name', $classMetrics->getClass()->getName()); + $xmlClass->setAttribute('loc', $classMetrics->getLoc()); + $xmlClass->setAttribute('locExecutable', $classMetrics->getLocExecutable()); + $xmlClass->setAttribute('locExecuted', $classMetrics->getLocExecuted()); + $xmlClass->setAttribute('aif', sprintf('%F', $classMetrics->getAIF())); + $xmlClass->setAttribute('ahf', sprintf('%F', $classMetrics->getAHF())); + $xmlClass->setAttribute('ca', $classMetrics->getCa()); + $xmlClass->setAttribute('ce', $classMetrics->getCe()); + $xmlClass->setAttribute('csz', $classMetrics->getCSZ()); + $xmlClass->setAttribute('cis', $classMetrics->getCIS()); + $xmlClass->setAttribute('coverage', sprintf('%F', $classMetrics->getCoverage())); + $xmlClass->setAttribute('dit', $classMetrics->getDIT()); + $xmlClass->setAttribute('i', sprintf('%F', $classMetrics->getI())); + $xmlClass->setAttribute('impl', $classMetrics->getIMPL()); + $xmlClass->setAttribute('mif', sprintf('%F', $classMetrics->getMIF())); + $xmlClass->setAttribute('mhf', sprintf('%F', $classMetrics->getMHF())); + $xmlClass->setAttribute('noc', $classMetrics->getNOC()); + $xmlClass->setAttribute('pf', sprintf('%F', $classMetrics->getPF())); + $xmlClass->setAttribute('vars', $classMetrics->getVARS()); + $xmlClass->setAttribute('varsnp', $classMetrics->getVARSnp()); + $xmlClass->setAttribute('varsi', $classMetrics->getVARSi()); + $xmlClass->setAttribute('wmc', $classMetrics->getWMC()); + $xmlClass->setAttribute('wmcnp', $classMetrics->getWMCnp()); + $xmlClass->setAttribute('wmci', $classMetrics->getWMCi()); + + foreach ($classMetrics->getMethods() as $methodName => $methodMetrics) { + $xmlMethod = $xmlClass->appendChild( + $document->createElement('method') + ); + + $this->processFunctionOrMethod($methodMetrics, $xmlMethod); + } + + $xmlFile->appendChild($xmlClass); + } + } + + foreach ($fileMetrics->getFunctions() as $functionName => $functionMetrics) { + $xmlFunction = $xmlFile->appendChild( + $document->createElement('function') + ); + + $this->processFunctionOrMethod($functionMetrics, $xmlFunction); + } + } + + $this->write($document->saveXML()); + $this->flush(); + } + + /** + * @param PHPUnit_Util_Metrics_Function $metrics + * @param DOMElement $element + * @access protected + */ + protected function processFunctionOrMethod($metrics, DOMElement $element) + { + $element->setAttribute('name', $metrics->getFunction()->getName()); + $element->setAttribute('loc', $metrics->getLoc()); + $element->setAttribute('locExecutable', $metrics->getLocExecutable()); + $element->setAttribute('locExecuted', $metrics->getLocExecuted()); + $element->setAttribute('coverage', sprintf('%F', $metrics->getCoverage())); + $element->setAttribute('ccn', $metrics->getCCN()); + $element->setAttribute('crap', sprintf('%F', $metrics->getCrapIndex())); + $element->setAttribute('npath', $metrics->getNPath()); + $element->setAttribute('parameters', $metrics->getParameters()); + } +} +?> Property changes on: test/PHPUnit/Util/Log/Metrics.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/Log/PEAR.php =================================================================== --- test/PHPUnit/Util/Log/PEAR.php (revision 0) +++ test/PHPUnit/Util/Log/PEAR.php (revision 0) @@ -0,0 +1,247 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: PEAR.php 1985 2007-12-26 18:11:55Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 2.3.0 + */ + +@include_once 'Log.php'; + +require_once 'PHPUnit/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * A TestListener that logs to a PEAR_Log sink. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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.1.0 + */ +class PHPUnit_Util_Log_PEAR implements PHPUnit_Framework_TestListener +{ + /** + * Log. + * + * @var Log + * @access protected + */ + protected $log; + + /** + * @param string $type The type of concrete Log subclass to use. + * Currently, valid values are 'console', + * 'syslog', 'sql', 'file', and 'mcal'. + * @param string $name The name of the actually log file, table, or + * other specific store to use. Defaults to an + * empty string, with which the subclass will + * attempt to do something intelligent. + * @param string $ident The identity reported to the log system. + * @param array $conf A hash containing any additional configuration + * information that a subclass might need. + * @param int $maxLevel Maximum priority level at which to log. + * @access public + */ + public function __construct($type, $name = '', $ident = '', $conf = array(), $maxLevel = PEAR_LOG_DEBUG) + { + $this->log = Log::factory($type, $name, $ident, $conf, $maxLevel); + } + + /** + * An error occurred. + * + * @param PHPUnit_Framework_Test $test + * @param Exception $e + * @param float $time + * @access public + */ + public function addError(PHPUnit_Framework_Test $test, Exception $e, $time) + { + $this->log->crit( + sprintf( + 'Test "%s" failed: %s', + + $test->getName(), + $e->getMessage() + ) + ); + } + + /** + * A failure occurred. + * + * @param PHPUnit_Framework_Test $test + * @param PHPUnit_Framework_AssertionFailedError $e + * @param float $time + * @access public + */ + public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) + { + $this->log->err( + sprintf( + 'Test "%s" failed: %s', + + $test->getName(), + $e->getMessage() + ) + ); + } + + /** + * Incomplete test. + * + * @param PHPUnit_Framework_Test $test + * @param Exception $e + * @param float $time + * @access public + */ + public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time) + { + $this->log->info( + sprintf( + 'Test "%s" incomplete: %s', + + $test->getName(), + $e->getMessage() + ) + ); + } + + /** + * Skipped test. + * + * @param PHPUnit_Framework_Test $test + * @param Exception $e + * @param float $time + * @access public + * @since Method available since Release 3.0.0 + */ + public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time) + { + $this->log->info( + sprintf( + 'Test "%s" skipped: %s', + + $test->getName(), + $e->getMessage() + ) + ); + } + + /** + * A test suite started. + * + * @param PHPUnit_Framework_TestSuite $suite + * @access public + * @since Method available since Release 2.2.0 + */ + public function startTestSuite(PHPUnit_Framework_TestSuite $suite) + { + $this->log->info( + sprintf( + 'TestSuite "%s" started.', + + $suite->getName() + ) + ); + } + + /** + * A test suite ended. + * + * @param PHPUnit_Framework_TestSuite $suite + * @access public + * @since Method available since Release 2.2.0 + */ + public function endTestSuite(PHPUnit_Framework_TestSuite $suite) + { + $this->log->info( + sprintf( + 'TestSuite "%s" ended.', + + $suite->getName() + ) + ); + } + + /** + * A test started. + * + * @param PHPUnit_Framework_Test $test + * @access public + */ + public function startTest(PHPUnit_Framework_Test $test) + { + $this->log->info( + sprintf( + 'Test "%s" started.', + + $test->getName() + ) + ); + } + + /** + * A test ended. + * + * @param PHPUnit_Framework_Test $test + * @param float $time + * @access public + */ + public function endTest(PHPUnit_Framework_Test $test, $time) + { + $this->log->info( + sprintf( + 'Test "%s" ended.', + + $test->getName() + ) + ); + } +} +?> Property changes on: test/PHPUnit/Util/Log/PEAR.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/Skeleton/TestMethodBoolStatic.tpl =================================================================== --- test/PHPUnit/Util/Skeleton/TestMethodBoolStatic.tpl (revision 0) +++ test/PHPUnit/Util/Skeleton/TestMethodBoolStatic.tpl (revision 0) @@ -0,0 +1,10 @@ + + /** + * Generated from @assert {annotation}. + */ + public function test{methodName}() + { + $this->assert{assertion}( + {className}::{origMethodName}({arguments}) + ); + } Property changes on: test/PHPUnit/Util/Skeleton/TestMethodBoolStatic.tpl ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/Skeleton/TestClass.tpl =================================================================== --- test/PHPUnit/Util/Skeleton/TestClass.tpl (revision 0) +++ test/PHPUnit/Util/Skeleton/TestClass.tpl (revision 0) @@ -0,0 +1,61 @@ +object = new {className}; + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + * + * @access protected + */ + protected function tearDown() + { + } +{methods}} + +// Call {className}Test::main() if this source file is executed directly. +if (PHPUnit_MAIN_METHOD == '{className}Test::main') { + {className}Test::main(); +} +?> Property changes on: test/PHPUnit/Util/Skeleton/TestClass.tpl ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/Skeleton/TestMethodExceptionStatic.tpl =================================================================== --- test/PHPUnit/Util/Skeleton/TestMethodExceptionStatic.tpl (revision 0) +++ test/PHPUnit/Util/Skeleton/TestMethodExceptionStatic.tpl (revision 0) @@ -0,0 +1,9 @@ + + /** + * Generated from @assert {annotation}. + * @expectedException {expected} + */ + public function test{methodName}() + { + {className}::{origMethodName}({arguments}); + } Property changes on: test/PHPUnit/Util/Skeleton/TestMethodExceptionStatic.tpl ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/Skeleton/TestMethodStatic.tpl =================================================================== --- test/PHPUnit/Util/Skeleton/TestMethodStatic.tpl (revision 0) +++ test/PHPUnit/Util/Skeleton/TestMethodStatic.tpl (revision 0) @@ -0,0 +1,11 @@ + + /** + * Generated from @assert {annotation}. + */ + public function test{methodName}() + { + $this->assert{assertion}( + {expected}, + {className}::{origMethodName}({arguments}) + ); + } Property changes on: test/PHPUnit/Util/Skeleton/TestMethodStatic.tpl ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/Skeleton/TestMethodBool.tpl =================================================================== --- test/PHPUnit/Util/Skeleton/TestMethodBool.tpl (revision 0) +++ test/PHPUnit/Util/Skeleton/TestMethodBool.tpl (revision 0) @@ -0,0 +1,10 @@ + + /** + * Generated from @assert {annotation}. + */ + public function test{methodName}() + { + $this->assert{assertion}( + $this->object->{origMethodName}({arguments}) + ); + } Property changes on: test/PHPUnit/Util/Skeleton/TestMethodBool.tpl ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/Skeleton/TestMethodException.tpl =================================================================== --- test/PHPUnit/Util/Skeleton/TestMethodException.tpl (revision 0) +++ test/PHPUnit/Util/Skeleton/TestMethodException.tpl (revision 0) @@ -0,0 +1,9 @@ + + /** + * Generated from @assert {annotation}. + * @expectedException {expected} + */ + public function test{methodName}() + { + $this->object->{origMethodName}({arguments}); + } Property changes on: test/PHPUnit/Util/Skeleton/TestMethodException.tpl ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/Skeleton/IncompleteTestMethod.tpl =================================================================== --- test/PHPUnit/Util/Skeleton/IncompleteTestMethod.tpl (revision 0) +++ test/PHPUnit/Util/Skeleton/IncompleteTestMethod.tpl (revision 0) @@ -0,0 +1,10 @@ + + /** + * @todo Implement test{methodName}(). + */ + public function test{methodName}() { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } Property changes on: test/PHPUnit/Util/Skeleton/IncompleteTestMethod.tpl ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/Skeleton/TestMethod.tpl =================================================================== --- test/PHPUnit/Util/Skeleton/TestMethod.tpl (revision 0) +++ test/PHPUnit/Util/Skeleton/TestMethod.tpl (revision 0) @@ -0,0 +1,11 @@ + + /** + * Generated from @assert {annotation}. + */ + public function test{methodName}() + { + $this->assert{assertion}( + {expected}, + $this->object->{origMethodName}({arguments}) + ); + } Property changes on: test/PHPUnit/Util/Skeleton/TestMethod.tpl ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/FilterIterator.php =================================================================== --- test/PHPUnit/Util/FilterIterator.php (revision 0) +++ test/PHPUnit/Util/FilterIterator.php (revision 0) @@ -0,0 +1,92 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: FilterIterator.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/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ + +class PHPUnit_Util_FilterIterator extends FilterIterator +{ + /** + * @var string + * @access protected + */ + protected $suffix; + + /** + * @param Iterator $iterator + * @param string $suffix + * @access public + */ + public function __construct(Iterator $iterator, $suffix = 'Test.php') + { + parent::__construct($iterator); + $this->suffix = $suffix; + } + + /** + * @return boolean + * @access public + */ + public function accept() + { + return substr($this->getInnerIterator()->current(), -1 * strlen($this->suffix)) == $this->suffix; + } +} +?> Property changes on: test/PHPUnit/Util/FilterIterator.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/XML.php =================================================================== --- test/PHPUnit/Util/XML.php (revision 0) +++ test/PHPUnit/Util/XML.php (revision 0) @@ -0,0 +1,106 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: XML.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'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * XML helpers. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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_XML +{ + public static function load($filename, $html = FALSE) + { + $document = new DOMDocument; + + if (is_readable($filename)) { + libxml_use_internal_errors(TRUE); + + if (!$html) { + $loaded = @$document->load($filename); + } else { + $loaded = @$document->loadHTMLFile($filename); + } + + if ($loaded === FALSE) { + $message = ''; + + foreach (libxml_get_errors() as $error) { + $message .= $error->message; + } + + throw new RuntimeException( + sprintf( + 'Could not load "%s".%s', + + $filename, + $message != '' ? "\n" . $message : '' + ) + ); + } + } else { + throw new RuntimeException( + sprintf( + 'Could not read "%s".', + $filename + ) + ); + } + + return $document; + } +} +?> Property changes on: test/PHPUnit/Util/XML.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/Getopt.php =================================================================== --- test/PHPUnit/Util/Getopt.php (revision 0) +++ test/PHPUnit/Util/Getopt.php (revision 0) @@ -0,0 +1,181 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: Getopt.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/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Command-line options parsing class. + * + * @category Testing + * @package PHPUnit + * @author Andrei Zmievski + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class PHPUnit_Util_Getopt { + public static function getopt(array $args, $short_options, $long_options = null) + { + if (empty($args)) { + return array(array(), array()); + } + + $opts = array(); + $non_opts = array(); + + if ($long_options) { + sort($long_options); + } + + if (isset($args[0]{0}) && $args[0]{0} != '-') { + array_shift($args); + } + + reset($args); + + while (list($i, $arg) = each($args)) { + if ($arg == '--') { + $non_opts = array_merge($non_opts, array_slice($args, $i + 1)); + break; + } + + if ($arg{0} != '-' || (strlen($arg) > 1 && $arg{1} == '-' && !$long_options)) { + $non_opts = array_merge($non_opts, array_slice($args, $i)); + break; + } + + elseif (strlen($arg) > 1 && $arg{1} == '-') { + self::parseLongOption(substr($arg, 2), $long_options, $opts, $args); + } + + else { + self::parseShortOption(substr($arg, 1), $short_options, $opts, $args); + } + } + + return array($opts, $non_opts); + } + + protected static function parseShortOption($arg, $short_options, &$opts, &$args) + { + for ($i = 0; $i < strlen($arg); $i++) { + $opt = $arg{$i}; + $opt_arg = null; + + if (($spec = strstr($short_options, $opt)) === false || $arg{$i} == ':') { + throw new RuntimeException("unrecognized option -- $opt"); + } + + if (strlen($spec) > 1 && $spec{1} == ':') { + if (strlen($spec) > 2 && $spec{2} == ':') { + if ($i + 1 < strlen($arg)) { + $opts[] = array($opt, substr($arg, $i + 1)); + break; + } + } else { + if ($i + 1 < strlen($arg)) { + $opts[] = array($opt, substr($arg, $i + 1)); + break; + } + + else if (list(, $opt_arg) = each($args)) { + } + + else { + throw new RuntimeException("option requires an argument -- $opt"); + } + } + } + + $opts[] = array($opt, $opt_arg); + } + } + + protected static function parseLongOption($arg, $long_options, &$opts, &$args) + { + @list($opt, $opt_arg) = explode('=', $arg); + $opt_len = strlen($opt); + + for ($i = 0; $i < count($long_options); $i++) { + $long_opt = $long_options[$i]; + $opt_start = substr($long_opt, 0, $opt_len); + + if ($opt_start != $opt) continue; + + $opt_rest = substr($long_opt, $opt_len); + + if ($opt_rest != '' && $opt{0} != '=' && + $i + 1 < count($long_options) && + $opt == substr($long_options[$i+1], 0, $opt_len)) { + throw new RuntimeException("option --$opt is ambiguous"); + } + + if (substr($long_opt, -1) == '=') { + if (substr($long_opt, -2) != '==') { + if (!strlen($opt_arg) && !(list(, $opt_arg) = each($args))) { + throw new RuntimeException("option --$opt requires an argument"); + } + } + } + + else if ($opt_arg) { + throw new RuntimeException("option --$opt doesn't allow an argument"); + } + + $opts[] = array('--' . $opt, $opt_arg); + return; + } + + throw new RuntimeException("unrecognized option --$opt"); + } +} +?> Property changes on: test/PHPUnit/Util/Getopt.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/TestSuiteIterator.php =================================================================== --- test/PHPUnit/Util/TestSuiteIterator.php (revision 0) +++ test/PHPUnit/Util/TestSuiteIterator.php (revision 0) @@ -0,0 +1,163 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: TestSuiteIterator.php 1985 2007-12-26 18:11:55Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 3.1.0 + */ + +require_once 'PHPUnit/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Iterator for test suites. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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.0 + */ +class PHPUnit_Util_TestSuiteIterator implements RecursiveIterator +{ + /** + * @var integer + * @access protected + */ + protected $position; + + /** + * @var PHPUnit_Framework_Test[] + * @access protected + */ + protected $tests; + + /** + * Constructor. + * + * @param PHPUnit_Framework_TestSuite $suite + * @access public + */ + public function __construct(PHPUnit_Framework_TestSuite $testSuite) + { + $this->tests = $testSuite->tests(); + } + + /** + * Rewinds the Iterator to the first element. + * + * @access public + */ + public function rewind() + { + $this->position = 0; + } + + /** + * Checks if there is a current element after calls to rewind() or next(). + * + * @return boolean + * @access public + */ + public function valid() + { + return $this->position < count($this->tests); + } + + /** + * Returns the key of the current element. + * + * @return integer + * @access public + */ + public function key() + { + return $this->position; + } + + /** + * Returns the current element. + * + * @return PHPUnit_Framework_Test + * @access public + */ + public function current() + { + return $this->valid() ? $this->tests[$this->position] : NULL; + } + + /** + * Moves forward to next element. + * + * @access public + */ + public function next() + { + $this->position++; + } + + /** + * Returns the sub iterator for the current element. + * + * @return PHPUnit_Util_TestSuiteIterator + * @access public + */ + public function getChildren() + { + return new PHPUnit_Util_TestSuiteIterator($this->tests[$this->position]); + } + + /** + * Checks whether the current element has children. + * + * @return boolean + * @access public + */ + public function hasChildren() + { + return $this->tests[$this->position] instanceof PHPUnit_Framework_TestSuite; + } +} +?> Property changes on: test/PHPUnit/Util/TestSuiteIterator.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/TestDox/ResultPrinter/HTML.php =================================================================== --- test/PHPUnit/Util/TestDox/ResultPrinter/HTML.php (revision 0) +++ test/PHPUnit/Util/TestDox/ResultPrinter/HTML.php (revision 0) @@ -0,0 +1,125 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: HTML.php 2141 2008-01-17 10:49:39Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 2.3.0 + */ + +require_once 'PHPUnit/Util/Filter.php'; +require_once 'PHPUnit/Util/TestDox/ResultPrinter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Prints TestDox documentation in HTML format. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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.1.0 + */ +class PHPUnit_Util_TestDox_ResultPrinter_HTML extends PHPUnit_Util_TestDox_ResultPrinter +{ + /** + * @var boolean + * @access protected + */ + protected $printsHTML = TRUE; + + /** + * Handler for 'start run' event. + * + * @access protected + */ + protected function startRun() + { + $this->write(''); + } + + /** + * Handler for 'start class' event. + * + * @param string $name + * @access protected + */ + protected function startClass($name) + { + $this->write('

' . $name . '

    '); + } + + /** + * Handler for 'on test' event. + * + * @param string $name + * @access protected + */ + protected function onTest($name) + { + $this->write('
  • ' . $name . '
  • '); + } + + /** + * Handler for 'end class' event. + * + * @param string $name + * @access protected + */ + protected function endClass($name) + { + $this->write('
'); + } + + /** + * Handler for 'end run' event. + * + * @access protected + */ + protected function endRun() + { + $this->write(''); + } +} +?> Property changes on: test/PHPUnit/Util/TestDox/ResultPrinter/HTML.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/TestDox/ResultPrinter/Text.php =================================================================== --- test/PHPUnit/Util/TestDox/ResultPrinter/Text.php (revision 0) +++ test/PHPUnit/Util/TestDox/ResultPrinter/Text.php (revision 0) @@ -0,0 +1,99 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: Text.php 1985 2007-12-26 18:11:55Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 2.3.0 + */ + +require_once 'PHPUnit/Util/Filter.php'; +require_once 'PHPUnit/Util/TestDox/ResultPrinter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Prints TestDox documentation in text format. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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.1.0 + */ +class PHPUnit_Util_TestDox_ResultPrinter_Text extends PHPUnit_Util_TestDox_ResultPrinter +{ + /** + * Handler for 'start class' event. + * + * @param string $name + * @access protected + */ + protected function startClass($name) + { + $this->write($name . "\n"); + } + + /** + * Handler for 'on test' event. + * + * @param string $name + * @access protected + */ + protected function onTest($name) + { + $this->write(' - ' . $name . "\n"); + } + + /** + * Handler for 'end class' event. + * + * @param string $name + * @access protected + */ + protected function endClass($name) + { + $this->write("\n"); + } +} +?> Property changes on: test/PHPUnit/Util/TestDox/ResultPrinter/Text.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/TestDox/NamePrettifier.php =================================================================== --- test/PHPUnit/Util/TestDox/NamePrettifier.php (revision 0) +++ test/PHPUnit/Util/TestDox/NamePrettifier.php (revision 0) @@ -0,0 +1,187 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: NamePrettifier.php 1985 2007-12-26 18:11:55Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 2.3.0 + */ + +require_once 'PHPUnit/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Prettifies class and method names for use in TestDox documentation. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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.1.0 + */ +class PHPUnit_Util_TestDox_NamePrettifier +{ + /** + * @var string + * @access protected + */ + protected $prefix = 'Test'; + + /** + * @var string + * @access protected + */ + protected $suffix = 'Test'; + + /** + * @var array + * @access protected + */ + protected $strings = array(); + + /** + * Prettifies the name of a test class. + * + * @param string $testClassName + * @return string + * @access public + */ + public function prettifyTestClass($testClassName) + { + $title = $testClassName; + + if ($this->suffix !== NULL && + $this->suffix == substr($testClassName, -1 * strlen($this->suffix))) { + $title = substr($title, 0, strripos($title, $this->suffix)); + } + + if ($this->prefix !== NULL && + $this->prefix == substr($testClassName, 0, strlen($this->prefix))) { + $title = substr($title, strlen($this->prefix)); + } + + return $title; + } + + /** + * Prettifies the name of a test method. + * + * @param string $testMethodName + * @return string + * @access public + */ + public function prettifyTestMethod($testMethodName) + { + $buffer = ''; + + if (!is_string($testMethodName) || strlen($testMethodName) == 0) { + return $buffer; + } + + $string = preg_replace('#\d+$#', '', $testMethodName); + + if (in_array($string, $this->strings)) { + $testMethodName = $string; + } else { + $this->strings[] = $string; + } + + $max = strlen($testMethodName); + + if (substr($testMethodName, 0, 4) == 'test') { + $offset = 4; + } else { + $offset = 0; + $testMethodName[0] = strtoupper($testMethodName[0]); + } + + $wasNumeric = FALSE; + + for ($i = $offset; $i < $max; $i++) { + if ($i > $offset && + ord($testMethodName[$i]) >= 65 && + ord($testMethodName[$i]) <= 90) { + $buffer .= ' ' . strtolower($testMethodName[$i]); + } else { + $isNumeric = is_numeric($testMethodName[$i]); + + if (!$wasNumeric && $isNumeric) { + $buffer .= ' '; + $wasNumeric = TRUE; + } + + if ($wasNumeric && !$isNumeric) { + $wasNumeric = FALSE; + } + + $buffer .= $testMethodName[$i]; + } + } + + return $buffer; + } + + /** + * Sets the prefix of test names. + * + * @param string $prefix + * @access public + */ + public function setPrefix($prefix) + { + $this->prefix = $prefix; + } + + /** + * Sets the suffix of test names. + * + * @param string $prefix + * @access public + */ + public function setSuffix($suffix) + { + $this->suffix = $suffix; + } +} +?> Property changes on: test/PHPUnit/Util/TestDox/NamePrettifier.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/TestDox/ResultPrinter.php =================================================================== --- test/PHPUnit/Util/TestDox/ResultPrinter.php (revision 0) +++ test/PHPUnit/Util/TestDox/ResultPrinter.php (revision 0) @@ -0,0 +1,350 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: ResultPrinter.php 2144 2008-01-17 10:53:25Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 2.3.0 + */ + +require_once 'PHPUnit/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; +require_once 'PHPUnit/Util/TestDox/NamePrettifier.php'; +require_once 'PHPUnit/Util/Printer.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Base class for printers of TestDox documentation. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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.1.0 + * @abstract + */ +abstract class PHPUnit_Util_TestDox_ResultPrinter extends PHPUnit_Util_Printer implements PHPUnit_Framework_TestListener +{ + /** + * @var PHPUnit_Util_TestDox_NamePrettifier + * @access protected + */ + protected $prettifier; + + /** + * @var string + * @access protected + */ + protected $testClass = ''; + + /** + * @var integer + * @access protected + */ + protected $testStatus = FALSE; + + /** + * @var array + * @access protected + */ + protected $tests = array(); + + protected $successful = 0; + protected $failed = 0; + protected $skipped = 0; + protected $incomplete = 0; + protected $testTypeOfInterest = 'PHPUnit_Framework_TestCase'; + + /** + * @var string + * @access protected + */ + protected $currentTestClassPrettified; + + /** + * @var string + * @access protected + */ + protected $currentTestMethodPrettified; + + /** + * Constructor. + * + * @param resource $out + * @access public + */ + public function __construct($out = NULL) + { + parent::__construct($out); + + $this->prettifier = new PHPUnit_Util_TestDox_NamePrettifier; + $this->startRun(); + } + + /** + * Flush buffer and close output. + * + * @access public + */ + public function flush() + { + $this->doEndClass(); + $this->endRun(); + + parent::flush(); + } + + /** + * An error occurred. + * + * @param PHPUnit_Framework_Test $test + * @param Exception $e + * @param float $time + * @access public + */ + public function addError(PHPUnit_Framework_Test $test, Exception $e, $time) + { + if ($test instanceof $this->testTypeOfInterest) { + $this->testStatus = PHPUnit_Runner_BaseTestRunner::STATUS_ERROR; + $this->failed++; + } + } + + /** + * A failure occurred. + * + * @param PHPUnit_Framework_Test $test + * @param PHPUnit_Framework_AssertionFailedError $e + * @param float $time + * @access public + */ + public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) + { + if ($test instanceof $this->testTypeOfInterest) { + $this->testStatus = PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE; + $this->failed++; + } + } + + /** + * Incomplete test. + * + * @param PHPUnit_Framework_Test $test + * @param Exception $e + * @param float $time + * @access public + */ + public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time) + { + if ($test instanceof $this->testTypeOfInterest) { + $this->testStatus = PHPUnit_Runner_BaseTestRunner::STATUS_INCOMPLETE; + $this->incomplete++; + } + } + + /** + * Skipped test. + * + * @param PHPUnit_Framework_Test $test + * @param Exception $e + * @param float $time + * @access public + * @since Method available since Release 3.0.0 + */ + public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time) + { + if ($test instanceof $this->testTypeOfInterest) { + $this->testStatus = PHPUnit_Runner_BaseTestRunner::STATUS_SKIPPED; + $this->skipped++; + } + } + + /** + * A testsuite started. + * + * @param PHPUnit_Framework_TestSuite $suite + * @access public + * @since Method available since Release 2.2.0 + */ + public function startTestSuite(PHPUnit_Framework_TestSuite $suite) + { + } + + /** + * A testsuite ended. + * + * @param PHPUnit_Framework_TestSuite $suite + * @access public + * @since Method available since Release 2.2.0 + */ + public function endTestSuite(PHPUnit_Framework_TestSuite $suite) + { + } + + /** + * A test started. + * + * @param PHPUnit_Framework_Test $test + * @access public + */ + public function startTest(PHPUnit_Framework_Test $test) + { + if ($test instanceof $this->testTypeOfInterest) { + $class = get_class($test); + + if ($this->testClass != $class) { + if ($this->testClass != '') { + $this->doEndClass(); + } + + $this->currentTestClassPrettified = $this->prettifier->prettifyTestClass($class); + $this->startClass($class); + + $this->testClass = $class; + $this->tests = array(); + } + + $this->currentTestMethodPrettified = $this->prettifier->prettifyTestMethod($test->getName()); + $this->testStatus = PHPUnit_Runner_BaseTestRunner::STATUS_PASSED; + } + } + + /** + * A test ended. + * + * @param PHPUnit_Framework_Test $test + * @param float $time + * @access public + */ + public function endTest(PHPUnit_Framework_Test $test, $time) + { + if ($test instanceof $this->testTypeOfInterest) { + if (!isset($this->tests[$this->currentTestMethodPrettified])) { + if ($this->testStatus == PHPUnit_Runner_BaseTestRunner::STATUS_PASSED) { + $this->tests[$this->currentTestMethodPrettified]['success'] = 1; + $this->tests[$this->currentTestMethodPrettified]['failure'] = 0; + } else { + $this->tests[$this->currentTestMethodPrettified]['success'] = 0; + $this->tests[$this->currentTestMethodPrettified]['failure'] = 1; + } + } else { + if ($this->testStatus == PHPUnit_Runner_BaseTestRunner::STATUS_PASSED) { + $this->tests[$this->currentTestMethodPrettified]['success']++; + } else { + $this->tests[$this->currentTestMethodPrettified]['failure']++; + } + } + + $this->currentTestClassPrettified = NULL; + $this->currentTestMethodPrettified = NULL; + } + } + + /** + * @access protected + * @since Method available since Release 2.3.0 + */ + protected function doEndClass() + { + foreach ($this->tests as $name => $data) { + if ($data['failure'] == 0) { + $this->onTest($name); + } + } + + $this->endClass($this->testClass); + } + + /** + * Handler for 'start run' event. + * + * @access protected + */ + protected function startRun() + { + } + + /** + * Handler for 'start class' event. + * + * @param string $name + * @access protected + */ + protected function startClass($name) + { + } + + /** + * Handler for 'on test' event. + * + * @param string $name + * @access protected + */ + protected function onTest($name) + { + } + + /** + * Handler for 'end class' event. + * + * @param string $name + * @access protected + */ + protected function endClass($name) + { + } + + /** + * Handler for 'end run' event. + * + * @access protected + */ + protected function endRun() + { + } +} + +require_once 'PHPUnit/Util/TestDox/ResultPrinter/HTML.php'; +require_once 'PHPUnit/Util/TestDox/ResultPrinter/Text.php'; +?> Property changes on: test/PHPUnit/Util/TestDox/ResultPrinter.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/Class.php =================================================================== --- test/PHPUnit/Util/Class.php (revision 0) +++ test/PHPUnit/Util/Class.php (revision 0) @@ -0,0 +1,417 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: Class.php 1985 2007-12-26 18:11:55Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 3.1.0 + */ + +require_once 'PHPUnit/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Class helpers. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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.0 + */ +class PHPUnit_Util_Class +{ + protected static $buffer = array(); + protected static $fileClassMap = array(); + protected static $fileFunctionMap = array(); + + /** + * Starts the collection of loaded classes. + * + * @access public + * @static + */ + public static function collectStart() + { + self::$buffer = get_declared_classes(); + } + + /** + * Stops the collection of loaded classes and + * returns the names of the loaded classes. + * + * @return array + * @access public + * @static + */ + public static function collectEnd() + { + return array_values( + array_diff(get_declared_classes(), self::$buffer) + ); + } + + /** + * Stops the collection of loaded classes and + * returns the names of the files that declare the loaded classes. + * + * @return array + * @access public + * @static + */ + public static function collectEndAsFiles() + { + $result = self::collectEnd(); + $count = count($result); + + for ($i = 0; $i < $count; $i++) { + $class = new ReflectionClass($result[$i]); + + if ($class->isUserDefined()) { + $file = $class->getFileName(); + + if (file_exists($file)) { + $result[$i] = $file; + } else { + unset($result[$i]); + } + } + } + + return $result; + } + + /** + * Returns the names of the classes declared in a sourcefile. + * + * @param string $filename + * @param string $commonPath + * @param boolean $clearCache + * @return array + * @access public + * @static + */ + public static function getClassesInFile($filename, $commonPath = '', $clearCache = FALSE) + { + if ($commonPath != '') { + $filename = str_replace($commonPath, '', $filename); + } + + if ($clearCache) { + self::$fileClassMap = array(); + } + + if (empty(self::$fileClassMap)) { + $classes = array_merge(get_declared_classes(), get_declared_interfaces()); + + foreach ($classes as $className) { + $class = new ReflectionClass($className); + + if ($class->isUserDefined()) { + $file = $class->getFileName(); + + if ($commonPath != '') { + $file = str_replace($commonPath, '', $file); + } + + if (!isset(self::$fileClassMap[$file])) { + self::$fileClassMap[$file] = array($class); + } else { + self::$fileClassMap[$file][] = $class; + } + } + } + } + + return isset(self::$fileClassMap[$filename]) ? self::$fileClassMap[$filename] : array(); + } + + /** + * Returns the names of the classes declared in a sourcefile. + * + * @param string $filename + * @param string $commonPath + * @param boolean $clearCache + * @return array + * @access public + * @static + * @since Class available since Release 3.2.0 + * @todo Find a better place for this method. + */ + public static function getFunctionsInFile($filename, $commonPath = '', $clearCache = FALSE) + { + if ($commonPath != '') { + $filename = str_replace($commonPath, '', $filename); + } + + if ($clearCache) { + self::$fileFunctionMap = array(); + } + + if (empty(self::$fileFunctionMap)) { + $functions = get_defined_functions(); + + foreach ($functions['user'] as $functionName) { + $function = new ReflectionFunction($functionName); + + $file = $function->getFileName(); + + if ($commonPath != '') { + $file = str_replace($commonPath, '', $file); + } + + if (!isset(self::$fileFunctionMap[$file])) { + self::$fileFunctionMap[$file] = array($function); + } else { + self::$fileFunctionMap[$file][] = $function; + } + } + } + + return isset(self::$fileFunctionMap[$filename]) ? self::$fileFunctionMap[$filename] : array(); + } + + /** + * Returns the class hierarchy for a given class. + * + * @param string $className + * @return array + * @access public + * @static + */ + public static function getHierarchy($className) + { + $classes = array($className); + $done = FALSE; + + while (!$done) { + $class = new ReflectionClass($classes[count($classes)-1]); + $parent = $class->getParentClass(); + + if ($parent !== FALSE) { + $classes[] = $parent->getName(); + } else { + $done = TRUE; + } + } + + return $classes; + } + + /** + * Returns the signature of a method. + * + * @param ReflectionClass $method + * @return string + * @access public + * @static + * @since Class available since Release 3.2.0 + */ + public static function getMethodSignature(ReflectionMethod $method) + { + if ($method->isPrivate()) { + $modifier = 'private'; + } + + else if ($method->isProtected()) { + $modifier = 'protected'; + } + + else { + $modifier = 'public'; + } + + if ($method->isStatic()) { + $modifier .= ' static'; + } + + if ($method->returnsReference()) { + $reference = '&'; + } else { + $reference = ''; + } + + return sprintf( + '%s function %s%s(%s)', + + $modifier, + $reference, + $method->getName(), + self::getMethodParameters($method) + ); + } + + /** + * Returns the parameters of a method. + * + * @param ReflectionClass $method + * @return string + * @access public + * @static + * @since Class available since Release 3.2.0 + */ + public static function getMethodParameters(ReflectionMethod $method) + { + $parameters = array(); + + foreach ($method->getParameters() as $parameter) { + $name = '$' . $parameter->getName(); + $typeHint = ''; + + if ($parameter->isArray()) { + $typeHint = 'array '; + } else { + try { + $class = $parameter->getClass(); + } + + catch (ReflectionException $e) { + $class = FALSE; + } + + if ($class) { + $typeHint = $class->getName() . ' '; + } + } + + $default = ''; + + if ($parameter->isDefaultValueAvailable()) { + $value = $parameter->getDefaultValue(); + $default = ' = ' . var_export($value, TRUE); + } + + $ref = ''; + + if ($parameter->isPassedByReference()) { + $ref = '&'; + } + + $parameters[] = $typeHint . $ref . $name . $default; + } + + return join(', ', $parameters); + } + + /** + * Returns the sourcecode of a user-defined class. + * + * @param string $className + * @param string $methodName + * @return mixed + * @access public + * @static + */ + public static function getMethodSource($className, $methodName) + { + if ($className != 'global') { + $function = new ReflectionMethod($className, $methodName); + } else { + $function = new ReflectionFunction($methodName); + } + + $filename = $function->getFileName(); + + if (file_exists($filename)) { + $file = file($filename); + $result = ''; + + for ($line = $function->getStartLine() - 1; $line <= $function->getEndLine() - 1; $line++) { + $result .= $file[$line]; + } + + return $result; + } else { + return FALSE; + } + } + + /** + * Returns the package information of a user-defined class. + * + * @param string $className + * @return array + * @access public + * @static + */ + public static function getPackageInformation($className) + { + $result = array( + 'fullPackage' => '', + 'category' => '', + 'package' => '', + 'subpackage' => '' + ); + + $class = new ReflectionClass($className); + $docComment = $class->getDocComment(); + + if (preg_match('/@category[\s]+([\.\w]+)/', $docComment, $matches)) { + $result['category'] = $matches[1]; + } + + if (preg_match('/@package[\s]+([\.\w]+)/', $docComment, $matches)) { + $result['package'] = $matches[1]; + $result['fullPackage'] = $matches[1]; + } + + if (preg_match('/@subpackage[\s]+([\.\w]+)/', $docComment, $matches)) { + $result['subpackage'] = $matches[1]; + $result['fullPackage'] .= '.' . $matches[1]; + } + + if (empty($result['fullPackage'])) { + $tmp = explode('_', $className); + + if (count($tmp) > 1) { + unset($tmp[count($tmp)-1]); + + $result['fullPackage'] = join('.', $tmp); + } + } + + return $result; + } +} +?> Property changes on: test/PHPUnit/Util/Class.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/Fileloader.php =================================================================== --- test/PHPUnit/Util/Fileloader.php (revision 0) +++ test/PHPUnit/Util/Fileloader.php (revision 0) @@ -0,0 +1,212 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: Fileloader.php 2092 2008-01-14 16:40:53Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 2.3.0 + */ + +require_once 'PHPUnit/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Utility methods to load PHP sourcefiles. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://www.phpunit.de/ + * @since Class available since Release 2.3.0 + */ +class PHPUnit_Util_Fileloader +{ + /** + * Path to the PHP interpreter that is to be used. + * + * @var string $phpBinary + * @access public + * @static + */ + public static $phpBinary = NULL; + + /** + * Checks if a PHP sourcefile is readable and is optionally checked for + * syntax errors through the syntaxCheck() method. The sourcefile is + * loaded through the load() method. + * + * @param string $filename + * @param boolean $syntaxCheck + * @throws RuntimeException + * @access public + * @static + */ + public static function checkAndLoad($filename, $syntaxCheck = TRUE) + { + if (!is_readable($filename)) { + $filename = './' . $filename; + } + + if (!is_readable($filename)) { + throw new RuntimeException( + sprintf( + 'File "%s" could not be found or is not readable.', + + str_replace('./', '', $filename) + ) + ); + } + + if ($syntaxCheck) { + self::syntaxCheck($filename); + } + + self::load($filename); + } + + /** + * Loads a PHP sourcefile. + * + * When the Xdebug extension is loaded and its "xdebug.collect_vars" + * configuration directive is enabled, all global variables declared + * in the loaded PHP sourcefile will be added to $GLOBALS. + * + * @param string $filename + * @access protected + * @static + * @since Method available since Release 3.0.0 + */ + protected static function load($filename) + { + $xdebugLoaded = extension_loaded('xdebug'); + $xdebugCollectVars = $xdebugLoaded && ini_get('xdebug.collect_vars') == '1'; + + if ($xdebugCollectVars) { + $variables = xdebug_get_declared_vars(); + } + + include_once $filename; + + if ($xdebugCollectVars) { + $variables = array_values( + array_diff(xdebug_get_declared_vars(), $variables) + ); + + foreach ($variables as $variable) { + if (isset($$variable)) { + $GLOBALS[$variable] = $$variable; + } + } + } + } + + /** + * Uses a separate process to perform a syntax check on a PHP sourcefile. + * + * PHPUnit_Util_Fileloader::$phpBinary contains the path to the PHP + * interpreter used for this. If unset, the following assumptions will + * be made: + * + * 1. When the PHP CLI/CGI binary configured with the PEAR Installer + * (php_bin configuration value) is readable, it will be used. + * + * 2. When PHPUnit is run using the CLI SAPI and the $_SERVER['_'] + * variable does not contain the string "PHPUnit", $_SERVER['_'] + * is assumed to contain the path to the current PHP interpreter + * and that will be used. + * + * 3. When PHPUnit is run using the CLI SAPI and the $_SERVER['_'] + * variable contains the string "PHPUnit", the file that $_SERVER['_'] + * points is assumed to be the PHPUnit TextUI CLI wrapper script + * "phpunit" and the binary set up using #! on that file's first + * line of code is assumed to contain the path to the current PHP + * interpreter and that will be used. + * + * 4. The current PHP interpreter is assumed to be in the $PATH and + * to be invokable through "php". + * + * @param string $filename + * @throws RuntimeException + * @access protected + * @static + * @since Method available since Release 3.0.0 + */ + protected static function syntaxCheck($filename) + { + if (self::$phpBinary === NULL) { + if (is_readable('@php_bin@')) { + self::$phpBinary = '@php_bin@'; + } + + else if (PHP_SAPI == 'cli' && isset($_SERVER['_'])) { + self::$phpBinary = $_SERVER['_']; + + if (strpos(self::$phpBinary, 'phpunit') !== FALSE) { + $file = file(self::$phpBinary); + $tmp = explode(' ', $file[0]); + self::$phpBinary = trim($tmp[1]); + } + } + + if (!is_readable(self::$phpBinary)) { + self::$phpBinary = 'php'; + } else { + self::$phpBinary = escapeshellarg(self::$phpBinary); + } + } + + $command = self::$phpBinary . ' -l ' . escapeshellarg($filename); + + if (DIRECTORY_SEPARATOR == '\\') { + $command = '"' . $command . '"'; + } + + $output = shell_exec($command); + + if (strpos($output, 'Errors parsing') !== FALSE) { + throw new RuntimeException($output); + } + } +} +?> Property changes on: test/PHPUnit/Util/Fileloader.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/Metrics.php =================================================================== --- test/PHPUnit/Util/Metrics.php (revision 0) +++ test/PHPUnit/Util/Metrics.php (revision 0) @@ -0,0 +1,71 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: Metrics.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'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Abstract base class for metrics classes. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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_Metrics +{ +} + +require_once 'PHPUnit/Util/Metrics/Project.php'; +require_once 'PHPUnit/Util/Metrics/File.php'; +require_once 'PHPUnit/Util/Metrics/Class.php'; +require_once 'PHPUnit/Util/Metrics/Function.php'; +?> Property changes on: test/PHPUnit/Util/Metrics.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/Configuration.php =================================================================== --- test/PHPUnit/Util/Configuration.php (revision 0) +++ test/PHPUnit/Util/Configuration.php (revision 0) @@ -0,0 +1,551 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: Configuration.php 2111 2008-01-15 09:55:15Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 3.2.0 + */ + +require_once 'PHPUnit/Util/Filter.php'; +require_once 'PHPUnit/Runner/IncludePathTestCollector.php'; +require_once 'PHPUnit/Util/XML.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Wrapper for the PHPUnit XML configuration file. + * + * Example XML configuration file: + * + * + * + * + * + * /path/to/files + * /path/to/MyTest.php + * + * + * + * + * name + * + * + * name + * + * + * + * + * + * /path/to/files + * /path/to/file + * + * /path/to/files + * /path/to/file + * + * + * + * /path/to/files + * /path/to/file + * + * /path/to/files + * /path/to/file + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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_Configuration +{ + protected $document; + protected $xpath; + + /** + * Loads a PHPUnit configuration file. + * + * @param string $filename + * @access public + */ + public function __construct($filename) + { + $this->document = PHPUnit_Util_XML::load($filename); + $this->xpath = new DOMXPath($this->document); + } + + /** + * Returns the configuration for SUT filtering. + * + * @return array + * @access public + * @since Method available since Release 3.2.1 + */ + public function getFilterConfiguration() + { + $addUncoveredFilesFromWhitelist = TRUE; + + $tmp = $this->xpath->query('filter/whitelist'); + + if ($tmp->length == 1 && + $tmp->item(0)->hasAttribute('addUncoveredFilesFromWhitelist')) { + $addUncoveredFilesFromWhitelist = $this->getBoolean( + (string)$tmp->item(0)->getAttribute('addUncoveredFilesFromWhitelist'), + TRUE + ); + } + + return array( + 'blacklist' => array( + 'include' => array( + 'directory' => $this->readFilterDirectories( + 'filter/blacklist/directory' + ), + 'file' => $this->readFilterFiles( + 'filter/blacklist/file' + ) + ), + 'exclude' => array( + 'directory' => $this->readFilterDirectories( + 'filter/blacklist/exclude/directory' + ), + 'file' => $this->readFilterFiles( + 'filter/blacklist/exclude/file' + ) + ) + ), + 'whitelist' => array( + 'addUncoveredFilesFromWhitelist' => $addUncoveredFilesFromWhitelist, + 'include' => array( + 'directory' => $this->readFilterDirectories( + 'filter/whitelist/directory' + ), + 'file' => $this->readFilterFiles( + 'filter/whitelist/file' + ) + ), + 'exclude' => array( + 'directory' => $this->readFilterDirectories( + 'filter/whitelist/exclude/directory' + ), + 'file' => $this->readFilterFiles( + 'filter/whitelist/exclude/file' + ) + ) + ) + ); + } + + /** + * Returns the configuration for groups. + * + * @return array + * @access public + * @since Method available since Release 3.2.1 + */ + public function getGroupConfiguration() + { + $groups = array( + 'include' => array(), + 'exclude' => array() + ); + + foreach ($this->xpath->query('groups/include/group') as $group) { + $groups['include'][] = (string)$group->nodeValue; + } + + foreach ($this->xpath->query('groups/exclude/group') as $group) { + $groups['exclude'][] = (string)$group->nodeValue; + } + + return $groups; + } + + /** + * Returns the logging configuration. + * + * @return array + * @access public + */ + public function getLoggingConfiguration() + { + $result = array(); + + foreach ($this->xpath->query('logging/log') as $log) { + $type = (string)$log->getAttribute('type'); + $target = (string)$log->getAttribute('target'); + + if ($type == 'coverage-html') { + if ($log->hasAttribute('charset')) { + $result['charset'] = (string)$log->getAttribute('charset'); + } + + if ($log->hasAttribute('lowUpperBound')) { + $result['lowUpperBound'] = (string)$log->getAttribute('lowUpperBound'); + } + + if ($log->hasAttribute('highLowerBound')) { + $result['highLowerBound'] = (string)$log->getAttribute('highLowerBound'); + } + + if ($log->hasAttribute('yui')) { + $result['yui'] = $this->getBoolean( + (string)$log->getAttribute('yui'), + FALSE + ); + } + + if ($log->hasAttribute('highlight')) { + $result['highlight'] = $this->getBoolean( + (string)$log->getAttribute('highlight'), + FALSE + ); + } + } + + else if ($type == 'pmd-xml') { + if ($log->hasAttribute('cpdMinLines')) { + $result['cpdMinLines'] = (string)$log->getAttribute('cpdMinLines'); + } + + if ($log->hasAttribute('cpdMinMatches')) { + $result['cpdMinMatches'] = (string)$log->getAttribute('cpdMinMatches'); + } + } + + else if ($type == 'test-xml') { + if ($log->hasAttribute('logIncompleteSkipped')) { + $result['logIncompleteSkipped'] = $this->getBoolean( + (string)$log->getAttribute('logIncompleteSkipped'), + FALSE + ); + } + } + + $result[$type] = $target; + } + + return $result; + } + + /** + * Returns the PHP configuration. + * + * @return array + * @access public + * @since Method available since Release 3.2.1 + */ + public function getPHPConfiguration() + { + $result = array( + 'ini' => array(), + 'var' => array() + ); + + foreach ($this->xpath->query('php/ini') as $ini) { + $name = (string)$ini->getAttribute('name'); + $value = (string)$ini->getAttribute('value'); + + $result['ini'][$name] = $value; + } + + foreach ($this->xpath->query('php/var') as $var) { + $name = (string)$var->getAttribute('name'); + $value = (string)$var->getAttribute('value'); + + if (strtolower($value) == 'false') { + $value = FALSE; + } + + else if (strtolower($value) == 'true') { + $value = TRUE; + } + + $result['var'][$name] = $value; + } + + return $result; + } + + /** + * Returns the configuration for PMD rules. + * + * @return array + * @access public + */ + public function getPMDConfiguration() + { + $result = array(); + + foreach ($this->xpath->query('logging/pmd/rule') as $rule) { + $class = (string)$rule->getAttribute('class'); + + $threshold = (string)$rule->getAttribute('threshold'); + $threshold = explode(',', $threshold); + + if (count($threshold) == 1) { + $threshold = $threshold[0]; + } + + $priority = (int)$rule->getAttribute('priority'); + + $result[$class] = array( + 'threshold' => $threshold, + 'priority' => $priority + ); + } + + return $result; + } + + /** + * Returns the SeleniumTestCase browser configuration. + * + * @return array + * @access public + * @since Method available since Release 3.2.9 + */ + public function getSeleniumBrowserConfiguration() + { + $result = array(); + + foreach ($this->xpath->query('selenium/browser') as $config) { + $name = (string)$config->getAttribute('name'); + $browser = (string)$config->getAttribute('browser'); + + if ($config->hasAttribute('host')) { + $host = (string)$config->getAttribute('host'); + } else { + $host = 'localhost'; + } + + if ($config->hasAttribute('port')) { + $host = (int)$config->getAttribute('port'); + } else { + $host = 4444; + } + + if ($config->hasAttribute('timeout')) { + $host = (int)$config->getAttribute('timeout'); + } else { + $host = 30000; + } + + $result[] = array( + 'name' => $name, + 'browser' => $browser, + 'host' => $host, + 'port' => $port, + 'timeout' => $timeout + ); + } + + return $result; + } + + /** + * Returns the test suite configuration. + * + * @return PHPUnit_Framework_TestSuite + * @access public + * @since Method available since Release 3.2.1 + */ + public function getTestSuiteConfiguration() + { + $testSuiteNode = $this->xpath->query('testsuite'); + + if ($testSuiteNode->length > 0) { + $testSuiteNode = $testSuiteNode->item(0); + + if ($testSuiteNode->hasAttribute('name')) { + $suite = new PHPUnit_Framework_TestSuite( + (string)$testSuiteNode->getAttribute('name') + ); + } else { + $suite = new PHPUnit_Framework_TestSuite; + } + + foreach ($this->xpath->query('testsuite/directory') as $directoryNode) { + if ($directoryNode->hasAttribute('suffix')) { + $suffix = (string)$directoryNode->getAttribute('suffix'); + } else { + $suffix = 'Test.php'; + } + + $testCollector = new PHPUnit_Runner_IncludePathTestCollector( + array((string)$directoryNode->nodeValue), + $suffix + ); + + $suite->addTestFiles($testCollector->collectTests()); + } + + foreach ($this->xpath->query('testsuite/file') as $fileNode) { + $suite->addTestFile((string)$fileNode->nodeValue); + } + + return $suite; + } + } + + /** + * @param string $value + * @param boolean $default + * @return boolean + * @access protected + * @since Method available since Release 3.2.3 + */ + protected function getBoolean($value, $default) + { + if (strtolower($value) == 'false') { + return FALSE; + } + + else if (strtolower($value) == 'true') { + return TRUE; + } + + return $default; + } + + /** + * @param string $query + * @return array + * @access protected + * @since Method available since Release 3.2.3 + */ + protected function readFilterDirectories($query) + { + $directories = array(); + + foreach ($this->xpath->query($query) as $directory) { + if ($directory->hasAttribute('suffix')) { + $suffix = (string)$directory->getAttribute('suffix'); + } else { + $suffix = '.php'; + } + + $directories[] = array( + 'path' => (string)$directory->nodeValue, + 'suffix' => $suffix + ); + } + + return $directories; + } + + /** + * @param string $query + * @return array + * @access protected + * @since Method available since Release 3.2.3 + */ + protected function readFilterFiles($query) + { + $files = array(); + + foreach ($this->xpath->query($query) as $file) { + $files[] = (string)$file->nodeValue; + } + + return $files; + } +} +?> Property changes on: test/PHPUnit/Util/Configuration.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/Template.php =================================================================== --- test/PHPUnit/Util/Template.php (revision 0) +++ test/PHPUnit/Util/Template.php (revision 0) @@ -0,0 +1,172 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: Template.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/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class PHPUnit_Util_Template +{ + /** + * @var string + * @access protected + */ + protected static $date = ''; + + /** + * @var string + * @access protected + */ + protected $template = ''; + + /** + * @var array + * @access protected + */ + protected $values = array(); + + /** + * Constructor. + * + * @param string $file + * @throws InvalidArgumentException + * @access public + */ + public function __construct($file = '') { + $this->setFile($file); + } + + /** + * Sets the template file. + * + * @param string $file + * @throws InvalidArgumentException + * @access public + */ + public function setFile($file) { + if ($file != '' && file_exists($file)) { + $this->template = file_get_contents($file); + } else { + throw new InvalidArgumentException( + 'Template file could not be loaded.' + ); + } + } + + /** + * Sets one or more template variables. + * + * @param array $values + * @param boolean $merge + * @access public + */ + public function setVar(array $values, $merge = TRUE) { + if (!$merge || empty($this->values)) { + $this->values = $values; + } else { + $this->values = array_merge($this->values, $values); + } + } + + /** + * Renders the template and returns the result. + * + * @return string + * @access public + */ + public function render() { + $keys = array(); + + foreach ($this->values as $key => $value) { + $keys[] = '{' . $key . '}'; + } + + return str_replace($keys, $this->values, $this->template); + } + + /** + * Renders the template and writes the result to a file. + * + * @param string $target + * @access public + */ + public function renderTo($target) { + if ($fp = @fopen($target, 'wt')) { + fwrite($fp, $this->render()); + fclose($fp); + } else { + throw new RuntimeException('Could not write to ' . $target . '.'); + } + } + + /** + * Returns the cached result of date('D M j G:i:s T Y'). + * + * @return string + * @access public + * @since Method available since Release 3.0.1 + */ + public static function getDate() { + if (self::$date == '') { + self::$date = date('D M j G:i:s T Y'); + } + + return self::$date; + } +} +?> Property changes on: test/PHPUnit/Util/Template.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/Report.php =================================================================== --- test/PHPUnit/Util/Report.php (revision 0) +++ test/PHPUnit/Util/Report.php (revision 0) @@ -0,0 +1,346 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @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 + * @copyright 2002-2008 Sebastian Bergmann + * @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, + * + * + * Array + * ( + * [Money.php] => Array + * ( + * ... + * ) + * + * [MoneyBag.php] => Array + * ( + * ... + * ) + * ) + * + * + * is transformed into + * + * + * Array + * ( + * [.] => Array + * ( + * [Money.php] => Array + * ( + * ... + * ) + * + * [MoneyBag.php] => Array + * ( + * ... + * ) + * ) + * ) + * + * + * @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, + * + * + * Array + * ( + * [/home/sb/PHPUnit/Samples/Money/Money.php] => Array + * ( + * ... + * ) + * + * [/home/sb/PHPUnit/Samples/Money/MoneyBag.php] => Array + * ( + * ... + * ) + * ) + * + * + * is reduced to + * + * + * Array + * ( + * [Money.php] => Array + * ( + * ... + * ) + * + * [MoneyBag.php] => Array + * ( + * ... + * ) + * ) + * + * + * @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); + } + } +} +?> Property changes on: test/PHPUnit/Util/Report.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/Test.php =================================================================== --- test/PHPUnit/Util/Test.php (revision 0) +++ test/PHPUnit/Util/Test.php (revision 0) @@ -0,0 +1,242 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: Test.php 1997 2007-12-27 05:07:58Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Test helpers. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class PHPUnit_Util_Test +{ + /** + * @param PHPUnit_Framework_Test $test + * @param boolean $asString + * @return mixed + * @access public + * @static + */ + public static function describe(PHPUnit_Framework_Test $test, $asString = TRUE) + { + if ($asString) { + if ($test instanceof PHPUnit_Framework_SelfDescribing) { + return $test->toString(); + } else { + return get_class($test); + } + } else { + if ($test instanceof PHPUnit_Framework_TestCase) { + return array( + get_class($test), $test->getName() + ); + } + + else if ($test instanceof PHPUnit_Framework_SelfDescribing) { + return array('', $test->toString()); + } + + else { + return array('', get_class($test)); + } + } + } + + /** + * @param PHPUnit_Framework_Test $test + * @param PHPUnit_Framework_TestResult $result + * @return mixed + * @access public + * @static + */ + public static function lookupResult(PHPUnit_Framework_Test $test, PHPUnit_Framework_TestResult $result) + { + $testName = self::describe($test); + + foreach ($result->errors() as $error) { + if ($testName == self::describe($error->failedTest())) { + return $error; + } + } + + foreach ($result->failures() as $failure) { + if ($testName == self::describe($failure->failedTest())) { + return $failure; + } + } + + foreach ($result->notImplemented() as $notImplemented) { + if ($testName == self::describe($notImplemented->failedTest())) { + return $notImplemented; + } + } + + foreach ($result->skipped() as $skipped) { + if ($testName == self::describe($skipped->failedTest())) { + return $skipped; + } + } + + return PHPUnit_Runner_BaseTestRunner::STATUS_PASSED; + } + + /** + * Returns the files and lines a test method wants to cover. + * + * @param string $className + * @param string $methodName + * @return array + * @access public + * @static + * @since Method available since Release 3.2.0 + */ + public static function getLinesToBeCovered($className, $methodName) + { + $result = array(); + + try { + $class = new ReflectionClass($className); + $method = new ReflectionMethod($className, $methodName); + $docComment = $class->getDocComment() . $method->getDocComment(); + + if (preg_match_all('/@covers[\s]+([\:\.\w]+)/', $docComment, $matches)) { + foreach ($matches[1] as $method) { + if (strpos($method, '::') !== FALSE) { + list($className, $methodName) = explode('::', $method); + + $_method = new ReflectionMethod($className, $methodName); + $fileName = $_method->getFileName(); + $startLine = $_method->getStartLine(); + $endLine = $_method->getEndLine(); + + if (!isset($result[$fileName])) { + $result[$fileName] = array(); + } + + $result[$fileName] = array_merge( + $result[$fileName], + range($startLine, $endLine) + ); + } + } + } + } + + catch (ReflectionException $e) { + } + + return $result; + } + + /** + * Returns the groups for a test class or method. + * + * @param Reflector $reflector + * @param array $groups + * @return array + * @access public + * @static + * @since Method available since Release 3.2.0 + */ + public static function getGroups(Reflector $reflector, array $groups = array()) + { + $docComment = $reflector->getDocComment(); + + if (preg_match_all('/@group[\s]+([\.\w]+)/', $docComment, $matches)) { + $groups = array_merge($groups, $matches[1]); + } + + return $groups; + } + + /** + * Returns the provided data for a method. + * + * @param string $className + * @param string $methodName + * @return array + * @access public + * @static + * @since Method available since Release 3.2.0 + */ + public static function getProvidedData($className, $methodName) + { + $method = new ReflectionMethod($className, $methodName); + $docComment = $method->getDocComment(); + + if (preg_match('/@dataProvider[\s]+([:\.\w]+)/', $docComment, $matches)) { + try { + $dataProvider = explode('::', $matches[1]); + $dataProviderMethodName = array_pop($dataProvider); + + if (!empty($dataProvider)) { + $dataProviderClassName = join('::', $dataProvider); + } else { + $dataProviderClassName = $className; + } + + $dataProviderMethod = new ReflectionMethod( + $dataProviderClassName, $dataProviderMethodName + ); + + return $dataProviderMethod->invoke(NULL); + } + + catch (ReflectionException $e) { + } + } + } +} +?> Property changes on: test/PHPUnit/Util/Test.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/Metrics/File.php =================================================================== --- test/PHPUnit/Util/Metrics/File.php (revision 0) +++ test/PHPUnit/Util/Metrics/File.php (revision 0) @@ -0,0 +1,347 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: File.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/Class.php'; +require_once 'PHPUnit/Util/Metrics.php'; +require_once 'PHPUnit/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * File-Level Metrics. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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_File extends PHPUnit_Util_Metrics +{ + protected $coverage = 0; + protected $loc = 0; + protected $cloc = 0; + protected $ncloc = 0; + protected $locExecutable = 0; + protected $locExecuted = 0; + + protected $filename; + protected $classes = array(); + protected $functions = array(); + protected $lines = array(); + protected $tokens = array(); + + protected static $cache = array(); + + /** + * Constructor. + * + * @param string $filename + * @param array $codeCoverage + * @throws RuntimeException + * @access protected + */ + protected function __construct($filename, &$codeCoverage = array()) + { + if (!file_exists($filename)) { + throw new RuntimeException( + sprintf( + 'File "%s" not found.', + $filename + ) + ); + } + + $this->filename = $filename; + $this->lines = file($filename); + $this->tokens = token_get_all(file_get_contents($filename)); + + $this->countLines(); + $this->setCoverage($codeCoverage); + + foreach (PHPUnit_Util_Class::getClassesInFile($filename) as $class) { + $this->classes[$class->getName()] = PHPUnit_Util_Metrics_Class::factory($class, $codeCoverage); + } + + foreach (PHPUnit_Util_Class::getFunctionsInFile($filename) as $function) { + $this->functions[$function->getName()] = PHPUnit_Util_Metrics_Function::factory($function, $codeCoverage); + } + } + + /** + * Factory. + * + * @param string $filename + * @param array $codeCoverage + * @return PHPUnit_Util_Metrics_File + * @access public + * @static + */ + public static function factory($filename, &$codeCoverage = array()) + { + if (!isset(self::$cache[$filename])) { + self::$cache[$filename] = new PHPUnit_Util_Metrics_File($filename, $codeCoverage); + } + + else if (!empty($codeCoverage) && self::$cache[$filename]->getCoverage() == 0) { + self::$cache[$filename]->setCoverage($codeCoverage); + } + + return self::$cache[$filename]; + } + + /** + * @param array $codeCoverage + * @access public + */ + public function setCoverage(array &$codeCoverage) + { + if (!empty($codeCoverage)) { + $this->calculateCodeCoverage($codeCoverage); + + foreach ($this->classes as $class) { + $class->setCoverage($codeCoverage); + } + + foreach ($this->functions as $function) { + $function->setCoverage($codeCoverage); + } + } + } + + /** + * Returns the path to the file. + * + * @return string + * @access public + */ + public function getPath() + { + return $this->filename; + } + + /** + * Classes. + * + * @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]; + } + + /** + * 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]; + } + + /** + * Lines. + * + * @return array + * @access public + */ + public function getLines() + { + return $this->lines; + } + + /** + * Tokens. + * + * @return array + * @access public + */ + public function getTokens() + { + return $this->tokens; + } + + /** + * Returns the Code Coverage for the file. + * + * @return float + * @access public + */ + public function getCoverage() + { + return $this->coverage; + } + + /** + * Lines of Code (LOC). + * + * @return int + * @access public + */ + public function getLoc() + { + return $this->loc; + } + + /** + * Executable Lines of Code (ELOC). + * + * @return int + * @access public + */ + public function getLocExecutable() + { + return $this->locExecutable; + } + + /** + * Executed Lines of Code. + * + * @return int + * @access public + */ + public function getLocExecuted() + { + return $this->locExecuted; + } + + /** + * Comment Lines of Code (CLOC). + * + * @return int + * @access public + */ + public function getCloc() + { + return $this->cloc; + } + + /** + * Non-Comment Lines of Code (NCLOC). + * + * @return int + * @access public + */ + public function getNcloc() + { + return $this->ncloc; + } + + /** + * Calculates the Code Coverage for the class. + * + * @param array $codeCoverage + * @access protected + */ + protected function calculateCodeCoverage(&$codeCoverage) + { + $statistics = PHPUnit_Util_CodeCoverage::getStatistics( + $codeCoverage, + $this->filename, + 1, + count($this->lines) + ); + + $this->coverage = $statistics['coverage']; + $this->loc = $statistics['loc']; + $this->locExecutable = $statistics['locExecutable']; + $this->locExecuted = $statistics['locExecuted']; + } + + /** + * @access protected + */ + protected function countLines() + { + $this->loc = count($this->lines); + $this->cloc = 0; + + foreach ($this->tokens as $i => $token) { + if (is_string($token)) { + continue; + } + + list ($token, $value) = $token; + + if ($token == T_COMMENT || $token == T_DOC_COMMENT) { + $this->cloc += count(explode("\n", $value)); + } + } + + $this->ncloc = $this->loc - $this->cloc; + } +} +?> Property changes on: test/PHPUnit/Util/Metrics/File.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/Metrics/Class.php =================================================================== --- test/PHPUnit/Util/Metrics/Class.php (revision 0) +++ test/PHPUnit/Util/Metrics/Class.php (revision 0) @@ -0,0 +1,771 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: Class.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/Class.php'; +require_once 'PHPUnit/Util/Metrics.php'; +require_once 'PHPUnit/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Class-Level Metrics. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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_Class extends PHPUnit_Util_Metrics +{ + protected $aif = 0; + protected $ahf = 0; + protected $ca = 0; + protected $ce = 0; + protected $coverage = 0; + protected $dit = 0; + protected $i = 0; + protected $impl = 0; + protected $loc = 0; + protected $locExecutable = 0; + protected $locExecuted = 0; + protected $mif = 0; + protected $mhf = 0; + protected $noc = 0; + protected $pf = 0; + protected $vars = 0; + protected $varsNp = 0; + protected $varsI = 0; + protected $wmc = 0; + protected $wmcNp = 0; + protected $wmcI = 0; + + protected $project; + protected $package = ''; + protected $class; + protected $methods = array(); + protected $inheritedMethods = array(); + protected $dependencies = array(); + protected $publicMethods = 0; + + protected static $cache = array(); + protected static $nocCache = array(); + + /** + * Constructor. + * + * @param ReflectionClass $class + * @param array $codeCoverage + * @access protected + */ + protected function __construct(ReflectionClass $class, &$codeCoverage = array()) + { + $this->class = $class; + + $className = $class->getName(); + + $packageInformation = PHPUnit_Util_Class::getPackageInformation($className); + + if (!empty($packageInformation['fullPackage'])) { + $this->package = $packageInformation['fullPackage']; + } + + $this->setCoverage($codeCoverage); + + $this->dit = count(PHPUnit_Util_Class::getHierarchy($class->getName())) - 1; + $this->impl = count($class->getInterfaces()); + + foreach ($this->class->getMethods() as $method) { + if ($method->getDeclaringClass()->getName() == $className) { + $this->methods[$method->getName()] = PHPUnit_Util_Metrics_Function::factory($method, $codeCoverage); + } else { + $this->inheritedMethods[$method->getName()] = PHPUnit_Util_Metrics_Function::factory($method, $codeCoverage); + } + } + + $this->calculateAttributeMetrics(); + $this->calculateMethodMetrics(); + $this->calculateNumberOfChildren(); + $this->calculatePolymorphismFactor(); + $this->calculateDependencies(); + } + + /** + * Factory. + * + * @param ReflectionClass $class + * @param array $codeCoverage + * @return PHPUnit_Util_Metrics_Class + * @access public + * @static + */ + public static function factory(ReflectionClass $class, &$codeCoverage = array()) + { + $className = $class->getName(); + + if (!isset(self::$cache[$className])) { + self::$cache[$className] = new PHPUnit_Util_Metrics_Class($class, $codeCoverage); + } + + else if (!empty($codeCoverage) && self::$cache[$className]->getCoverage() == 0) { + self::$cache[$className]->setCoverage($codeCoverage); + } + + return self::$cache[$className]; + } + + /** + * @param array $codeCoverage + * @access public + */ + public function setCoverage(array &$codeCoverage) + { + if (!empty($codeCoverage)) { + $this->calculateCodeCoverage($codeCoverage); + + foreach ($this->methods as $method) { + $method->setCoverage($codeCoverage); + } + } + } + + /** + * @param PHPUnit_Util_Metrics_Project $project + * @access public + */ + public function setProject(PHPUnit_Util_Metrics_Project $project) + { + $this->project = $project; + + $this->ca = 0; + $this->ce = 0; + $this->i = 0; + } + + /** + * Returns the class. + * + * @return ReflectionClass + * @access public + */ + public function getClass() + { + return $this->class; + } + + /** + * Returns the package of this class. + * + * @return string + * @access public + */ + public function getPackage() + { + return $this->package; + } + + /** + * Returns the methods of this class. + * + * @return array + * @access public + */ + public function getMethods() + { + return $this->methods; + } + + /** + * Returns the names of the classes this class depends on. + * + * @return array + * @access public + */ + public function getDependencies() + { + return $this->dependencies; + } + + /** + * Lines of Code (LOC). + * + * @return int + * @access public + */ + public function getLoc() + { + return $this->loc; + } + + /** + * Executable Lines of Code (ELOC). + * + * @return int + * @access public + */ + public function getLocExecutable() + { + return $this->locExecutable; + } + + /** + * Executed Lines of Code. + * + * @return int + * @access public + */ + public function getLocExecuted() + { + return $this->locExecuted; + } + + /** + * Returns the Number of Public Methods of the class. + * + * @return integer + * @access public + */ + public function getPublicMethods() + { + return $this->publicMethods; + } + + /** + * Returns the Attribute Inheritance Factor (AIF) for the class. + * + * @return integer + * @access public + * @see http://www.aivosto.com/project/help/pm-oo-mood.html + */ + public function getAIF() + { + return $this->aif; + } + + /** + * Returns the Attribute Hiding Factor (AHF) for the class. + * + * @return integer + * @access public + * @see http://www.aivosto.com/project/help/pm-oo-mood.html + */ + public function getAHF() + { + return $this->ahf; + } + + /** + * Returns the Afferent Couplings (Ca) for the class. + * + * The number of other classes that depend upon a class is an indicator of + * the class' responsibility. + * + * @return integer + * @access public + */ + public function getCa() + { + $this->calculateDependencyMetrics(); + + return $this->ca; + } + + /** + * Returns the Efferent Couplings (Ce) for the class. + * + * The number of other classes that the class depends upon is an indicator + * of the class' independence. + * + * @return integer + * @access public + */ + public function getCe() + { + $this->calculateDependencyMetrics(); + + return $this->ce; + } + + /** + * Returns the Class Size (CSZ) of the class. + * + * @return integer + * @access public + * @see http://www.aivosto.com/project/help/pm-oo-misc.html + */ + public function getCSZ() + { + return count($this->methods) + $this->vars; + } + + /** + * Returns the Class Interface Size (CIS) of the class. + * + * @return integer + * @access public + * @see http://www.aivosto.com/project/help/pm-oo-misc.html + */ + public function getCIS() + { + return $this->publicMethods + $this->varsNp; + } + + /** + * Returns the Code Coverage for the class. + * + * @return float + * @access public + */ + public function getCoverage() + { + return $this->coverage; + } + + /** + * Returns the Depth of Inheritance Tree (DIT) for the class. + * + * @return integer + * @access public + * @see http://www.aivosto.com/project/help/pm-oo-ck.html + */ + public function getDIT() + { + return $this->dit; + } + + /** + * Returns the Instability (I) for the class. + * + * The ratio of efferent coupling (Ce) to total coupling (Ce + Ca) such that + * I = Ce / (Ce + Ca). This metric is an indicator of the class' resilience + * to change. + * + * The range for this metric is 0 to 1, with I=0 indicating a completely + * stable class and I=1 indicating a completely instable class. + * + * @return float + * @access public + */ + public function getI() + { + $this->calculateDependencyMetrics(); + + return $this->i; + } + + /** + * Returns the Number of Interfaces Implemented by the class (IMPL). + * + * @return integer + * @access public + * @see http://www.aivosto.com/project/help/pm-oo-misc.html + */ + public function getIMPL() + { + return $this->impl; + } + + /** + * Returns the Method Inheritance Factor (MIF) for the class. + * + * @return float + * @access public + * @see http://www.aivosto.com/project/help/pm-oo-mood.html + */ + public function getMIF() + { + return $this->mif; + } + + /** + * Returns the Method Hiding Factor (MHF) for the class. + * + * @return float + * @access public + * @see http://www.aivosto.com/project/help/pm-oo-mood.html + */ + public function getMHF() + { + return $this->mhf; + } + + /** + * Returns the Number of Children (NOC) for the class. + * + * @return integer + * @access public + * @see http://www.aivosto.com/project/help/pm-oo-ck.html + */ + public function getNOC() + { + return $this->noc; + } + + /** + * Returns the Polymorphism Factor (PF) for the class. + * + * @return float + * @access public + * @see http://www.aivosto.com/project/help/pm-oo-mood.html + */ + public function getPF() + { + return $this->pf; + } + + /** + * Returns the Number of Variables (VARS) defined by the class. + * + * @return integer + * @access public + * @see http://www.aivosto.com/project/help/pm-oo-misc.html + */ + public function getVARS() + { + return $this->vars; + } + + /** + * Returns the Number of Non-Private Variables (VARSnp) defined by the class. + * + * @return integer + * @access public + * @see http://www.aivosto.com/project/help/pm-oo-misc.html + */ + public function getVARSnp() + { + return $this->varsNp; + } + + /** + * Returns the Number of Variables (VARSi) defined and inherited by the class. + * + * @return integer + * @access public + * @see http://www.aivosto.com/project/help/pm-oo-misc.html + */ + public function getVARSi() + { + return $this->varsI; + } + + /** + * Returns the Weighted Methods Per Class (WMC) for the class. + * + * @return integer + * @access public + * @see http://www.aivosto.com/project/help/pm-oo-ck.html + */ + public function getWMC() + { + return $this->wmc; + } + + /** + * Returns the Weighted Non-Private Methods Per Class (WMCnp) for the class. + * + * @return integer + * @access public + * @see http://www.aivosto.com/project/help/pm-oo-misc.html + */ + public function getWMCnp() + { + return $this->wmcNp; + } + + /** + * Returns the Weighted Inherited Methods Per Class (WMCi) for the class. + * + * @return integer + * @access public + * @see http://www.aivosto.com/project/help/pm-oo-misc.html + */ + public function getWMCi() + { + return $this->wmcI; + } + + /** + * Calculates the Attribute Inheritance Factor (AIF) and + * Attribute Hiding Factor (AHF) metrics for the class. + * + * @access protected + */ + protected function calculateAttributeMetrics() + { + $attributes = 0; + $hiddenAttributes = 0; + $inheritedAttributes = 0; + + foreach ($this->class->getProperties() as $attribute) { + if ($attribute->isPublic()) { + $this->varsNp++; + } else { + $hiddenAttributes++; + } + + if ($attribute->getDeclaringClass()->getName() == $this->class->getName()) { + $this->vars++; + } else { + $inheritedAttributes++; + } + + $this->varsI++; + $attributes++; + } + + if ($attributes > 0) { + $this->aif = (100 * $inheritedAttributes) / $attributes; + $this->ahf = (100 * $hiddenAttributes) / $attributes; + } + } + + /** + * Calculates the Method Inheritance Factor (MIF) + * Method Hiding Factor (MHF), Weighted Methods Per Class (WMC), + * Weighted Non-Private Methods Per Class (WMCnp), and + * Weighted Inherited Methods Per Class (WMCi) metrics for the class. + * + * @access protected + */ + protected function calculateMethodMetrics() + { + $numMethods = 0; + $hiddenMethods = 0; + $inheritedMethods = 0; + + $methods = array_merge($this->methods, $this->inheritedMethods); + + foreach ($methods as $method) { + $ccn = $method->getCCN(); + + if ($method->getMethod()->getDeclaringClass()->getName() == $this->class->getName()) { + $this->wmc += $ccn; + + if ($method->getMethod()->isPublic()) { + $this->publicMethods++; + $this->wmcNp += $ccn; + } + } else { + $inheritedMethods++; + } + + if (!$method->getMethod()->isPublic()) { + $hiddenMethods++; + } + + $this->wmcI += $ccn; + $numMethods++; + } + + if ($numMethods > 0) { + $this->mif = (100 * $inheritedMethods) / $numMethods; + $this->mhf = (100 * $hiddenMethods) / $numMethods; + } + } + + /** + * Calculates the Number of Children (NOC) metric for the class. + * + * @access protected + */ + protected function calculateNumberOfChildren() + { + $className = $this->class->getName(); + + if (!isset(self::$nocCache[$className])) { + self::$nocCache = array(); + } + + if (empty(self::$nocCache)) { + foreach (get_declared_classes() as $_className) { + $class = new ReflectionClass($_className); + $parent = $class->getParentClass(); + + if ($parent !== FALSE) { + $parentName = $parent->getName(); + + if (isset(self::$nocCache[$parentName])) { + self::$nocCache[$parentName]++; + } else { + self::$nocCache[$parentName] = 1; + } + } + } + } + + if (isset(self::$nocCache[$className])) { + $this->noc = self::$nocCache[$className]; + } + } + + /** + * Calculates the Polymorphism Factor (PF) metric for the class. + * + * @param ReflectionClass $class + * @access protected + */ + protected function calculatePolymorphismFactor() + { + $parentClass = $this->class->getParentClass(); + + if ($parentClass !== FALSE) { + $overridableMethods = array(); + + foreach ($parentClass->getMethods() as $method) { + if (!$method->isPrivate() && !$method->isFinal() && !$method->isAbstract()) { + $overridableMethods[] = $method->getName(); + } + } + + if (!empty($overridableMethods)) { + $overriddenMethods = 0; + + foreach ($this->class->getMethods() as $method) { + if ($method->getDeclaringClass()->getName() == $this->class->getName()) { + $methodName = $method->getName(); + + if (in_array($methodName, $overridableMethods)) { + $overriddenMethods++; + } + } + } + + $this->pf = (100 * $overriddenMethods) / count($overridableMethods); + } + } + } + + /** + * Calculates the Code Coverage for the class. + * + * @param array $codeCoverage + * @access protected + */ + protected function calculateCodeCoverage(&$codeCoverage) + { + $statistics = PHPUnit_Util_CodeCoverage::getStatistics( + $codeCoverage, + $this->class->getFileName(), + $this->class->getStartLine(), + $this->class->getEndLine() + ); + + $this->coverage = $statistics['coverage']; + $this->loc = $statistics['loc']; + $this->locExecutable = $statistics['locExecutable']; + $this->locExecuted = $statistics['locExecuted']; + } + + /** + * Calculates the dependencies for this class. + * + * @access protected + */ + protected function calculateDependencies() + { + $parent = $this->class->getParentClass(); + + if ($parent && $parent->isUserDefined() && !in_array($parent->getName(), $this->dependencies)) { + $this->dependencies[] = $parent->getName(); + } + + $interfaces = $this->class->getInterfaces(); + + foreach ($interfaces as $interface) { + if ($interface->isUserDefined() && !in_array($interface->getName(), $this->dependencies)) { + $this->dependencies[] = $interface->getName(); + } + } + + $methods = array_merge($this->methods, $this->inheritedMethods); + + foreach ($methods as $method) { + foreach ($method->getDependencies() as $dependency) { + if (!in_array($dependency, $this->dependencies)) { + $this->dependencies[] = $dependency; + } + } + } + } + + /** + * Calculates the dependency-based metrics for this class. + * + * @access protected + */ + protected function calculateDependencyMetrics() + { + if ($this->ca == 0 && $this->ce == 0 && $this->i == 0) { + $className = $this->class->getName(); + $dependencies = $this->project->getDependencies(); + + foreach ($dependencies[$className] as $dependency) { + if ($dependency > 0) { + $this->ce++; + } + } + + unset($dependencies[$className]); + + foreach ($dependencies as $_className => $_dependencies) { + if ($_dependencies[$className] > 0) { + $this->ca++; + } + } + + $sum = $this->ce + $this->ca; + + if ($sum > 0) { + $this->i = $this->ce / $sum; + } + } + } +} +?> Property changes on: test/PHPUnit/Util/Metrics/Class.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/Metrics/Function.php =================================================================== --- test/PHPUnit/Util/Metrics/Function.php (revision 0) +++ test/PHPUnit/Util/Metrics/Function.php (revision 0) @@ -0,0 +1,522 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: Function.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/Class.php'; +require_once 'PHPUnit/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Function- and Method-Level Metrics. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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_Function extends PHPUnit_Util_Metrics +{ + protected $ccn = 1; + protected $npath = 1; + protected $coverage = 0; + protected $crap; + protected $loc = 0; + protected $locExecutable = 0; + protected $locExecuted = 0; + protected $parameters = 0; + + protected $function; + protected $scope; + protected $tokens; + + protected $dependencies = array(); + + protected static $cache = array(); + + /** + * Constructor. + * + * @param string $scope + * @param ReflectionFunction|ReflectionMethod $function + * @param array $codeCoverage + * @access protected + */ + protected function __construct($scope, $function, &$codeCoverage = array()) + { + $this->scope = $scope; + $this->function = $function; + + $source = PHPUnit_Util_Class::getMethodSource( + $scope, $function->getName() + ); + + if ($source !== FALSE) { + $this->tokens = token_get_all(''); + $this->parameters = $function->getNumberOfParameters(); + + $this->calculateCCN(); + $this->calculateNPath(); + $this->calculateDependencies(); + } + + $this->setCoverage($codeCoverage); + } + + /** + * Factory. + * + * @param ReflectionFunction|ReflectionMethod $function + * @param array $codeCoverage + * @return PHPUnit_Util_Metrics_Method + * @access public + * @static + */ + public static function factory($function, &$codeCoverage = array()) + { + if ($function instanceof ReflectionMethod) { + $scope = $function->getDeclaringClass()->getName(); + } else { + $scope = 'global'; + } + + $name = $function->getName(); + + if (!isset(self::$cache[$scope][$name])) { + self::$cache[$scope][$name] = new PHPUnit_Util_Metrics_Function($scope, $function, $codeCoverage); + } + + else if (!empty($codeCoverage) && self::$cache[$scope][$name]->getCoverage() == 0) { + self::$cache[$scope][$name]->setCoverage($codeCoverage); + } + + return self::$cache[$scope][$name]; + } + + /** + * @param array $codeCoverage + * @access public + */ + public function setCoverage(array &$codeCoverage) + { + if (!empty($codeCoverage)) { + $this->calculateCodeCoverage($codeCoverage); + $this->calculateCrapIndex(); + } + } + + /** + * Returns the function. + * + * @return ReflectionFunction + * @access public + */ + public function getFunction() + { + return $this->function; + } + + /** + * Returns the method. + * Alias for getFunction(). + * + * @return ReflectionMethod + * @access public + */ + public function getMethod() + { + return $this->function; + } + + /** + * Returns the names of the classes this function or method depends on. + * + * @return array + * @access public + */ + public function getDependencies() + { + return $this->dependencies; + } + + /** + * Lines of Code (LOC). + * + * @return int + * @access public + */ + public function getLoc() + { + return $this->loc; + } + + /** + * Executable Lines of Code (ELOC). + * + * @return int + * @access public + */ + public function getLocExecutable() + { + return $this->locExecutable; + } + + /** + * Executed Lines of Code. + * + * @return int + * @access public + */ + public function getLocExecuted() + { + return $this->locExecuted; + } + + /** + * Number of Parameters. + * + * @return int + * @access public + */ + public function getParameters() + { + return $this->parameters; + } + + /** + * Returns the Cyclomatic Complexity Number (CCN) for the method. + * This is also known as the McCabe metric. + * + * Each method has a minimum value of 1 per default. For each of the + * following PHP keywords/statements this value gets incremented by one: + * + * - if + * - for + * - foreach + * - while + * - case + * - catch + * - AND, && + * - OR, || + * - ? + * + * Note that 'else', 'default', and 'finally' don't increment the value + * any further. On the other hand, a simple method with a 'switch' + * statement and a huge block of 'case 'statements can have a surprisingly + * high value (still it has the same value when converting a 'switch' + * block to an equivalent sequence of 'if' statements). + * + * @return integer + * @access public + * @see http://en.wikipedia.org/wiki/Cyclomatic_complexity + */ + public function getCCN() + { + return $this->ccn; + } + + /** + * Returns the Change Risk Analysis and Predictions (CRAP) index for the + * method. + * + * @return float + * @access public + * @see http://www.artima.com/weblogs/viewpost.jsp?thread=210575 + */ + public function getCrapIndex() + { + return $this->crap; + } + + /** + * Returns the Code Coverage for the method. + * + * @return float + * @access public + */ + public function getCoverage() + { + return $this->coverage; + } + + /** + * Returns the NPath Complexity for the method. + * + * @return integer + * @access public + */ + public function getNPath() + { + return $this->npath; + } + + /** + * Calculates the Cyclomatic Complexity Number (CCN) for the method. + * + * @access protected + */ + protected function calculateCCN() + { + foreach ($this->tokens as $token) { + if (is_string($token)) { + $token = trim($token); + + if ($token == '?') { + $this->ccn++; + } + + continue; + } + + list ($token, $value) = $token; + + switch ($token) { + case T_IF: + case T_FOR: + case T_FOREACH: + case T_WHILE: + case T_CASE: + case T_CATCH: + case T_BOOLEAN_AND: + case T_LOGICAL_AND: + case T_BOOLEAN_OR: + case T_LOGICAL_OR: { + $this->ccn++; + } + break; + } + } + } + + /** + * Calculates the NPath Complexity for the method. + * + * @access protected + */ + protected function calculateNPath() + { + $npathStack = array(); + $stack = array(); + + foreach ($this->tokens as $token) { + if (is_string($token)) { + $token = trim($token); + + if ($token == '?') { + $this->npath = ($this->npath + 1) * $this->npath; + } + + if ($token == '{') { + if (isset($scope)) { + array_push($stack, $scope); + array_push($npathStack, $this->npath); + $this->npath = 1; + } else { + array_push($stack, NULL); + } + } + + if ($token == '}') { + $scope = array_pop($stack); + + if ($scope !== NULL) { + switch ($scope) { + case T_WHILE: + case T_DO: + case T_FOR: + case T_FOREACH: + case T_IF: + case T_TRY: + case T_SWITCH: { + $this->npath = ($this->npath + 1) * array_pop($npathStack); + } + break; + + case T_ELSE: + case T_CATCH: + case T_CASE: { + $this->npath = ($this->npath - 1) + array_pop($npathStack); + } + break; + } + } + } + + continue; + } + + list ($token, $value) = $token; + + switch ($token) { + case T_WHILE: + case T_DO: + case T_FOR: + case T_FOREACH: + case T_IF: + case T_TRY: + case T_SWITCH: + case T_ELSE: + case T_CATCH: + case T_CASE: { + $scope = $token; + } + break; + } + } + } + + /** + * Calculates the Code Coverage for the method. + * + * @param array $codeCoverage + * @access protected + */ + protected function calculateCodeCoverage(&$codeCoverage) + { + $statistics = PHPUnit_Util_CodeCoverage::getStatistics( + $codeCoverage, + $this->function->getFileName(), + $this->function->getStartLine(), + $this->function->getEndLine() + ); + + $this->coverage = $statistics['coverage']; + $this->loc = $statistics['loc']; + $this->locExecutable = $statistics['locExecutable']; + $this->locExecuted = $statistics['locExecuted']; + } + + /** + * Calculates the Change Risk Analysis and Predictions (CRAP) index for the + * method. + * + * @access public + */ + protected function calculateCrapIndex() + { + if ($this->coverage == 0) { + $this->crap = pow($this->ccn, 2) + $this->ccn; + } + + else if ($this->coverage >= 95) { + $this->crap = $this->ccn; + } + + else { + $this->crap = pow($this->ccn, 2) * (pow(1 - $this->coverage/100, 3) + $this->ccn); + } + } + + /** + * Calculates the dependencies for this function or method. + * + * @access public + */ + protected function calculateDependencies() + { + foreach ($this->function->getParameters() as $parameter) { + try { + $class = $parameter->getClass(); + + if ($class) { + $className = $class->getName(); + + if ($className != $this->scope && !in_array($className, $this->dependencies)) { + $this->dependencies[] = $className; + } + } + } + + catch (ReflectionException $e) { + } + } + + $inNew = FALSE; + + foreach ($this->tokens as $token) { + if (is_string($token)) { + if (trim($token) == ';') { + $inNew = FALSE; + } + + continue; + } + + list ($token, $value) = $token; + + switch ($token) { + case T_NEW: { + $inNew = TRUE; + } + break; + + case T_STRING: { + if ($inNew) { + if ($value != $this->scope && class_exists($value, FALSE)) { + try { + $class = new ReflectionClass($value); + + if ($class->isUserDefined() && !in_array($value, $this->dependencies)) { + $this->dependencies[] = $value; + } + } + + catch (ReflectionException $e) { + } + } + } + + $inNew = FALSE; + } + break; + } + } + } +} +?> Property changes on: test/PHPUnit/Util/Metrics/Function.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/Metrics/Project.php =================================================================== --- test/PHPUnit/Util/Metrics/Project.php (revision 0) +++ test/PHPUnit/Util/Metrics/Project.php (revision 0) @@ -0,0 +1,485 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @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 + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ + 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; + } + } + } +} +?> Property changes on: test/PHPUnit/Util/Metrics/Project.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/Timer.php =================================================================== --- test/PHPUnit/Util/Timer.php (revision 0) +++ test/PHPUnit/Util/Timer.php (revision 0) @@ -0,0 +1,136 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: Timer.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/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Utility class for timing. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class PHPUnit_Util_Timer +{ + protected static $startTimes = array(); + + /** + * Starts the timer. + * + * @access public + * @static + */ + public static function start() + { + array_push(self::$startTimes, microtime(TRUE)); + } + + /** + * Returns the currently elapsed time. + * + * @return float + * @access public + * @static + */ + public static function current() + { + return microtime(TRUE) - self::$startTimes[count(self::$startTimes)-1]; + } + + /** + * Stops the timer and returns the elapsed time. + * + * @access public + * @static + */ + public static function stop() + { + return microtime(TRUE) - array_pop(self::$startTimes); + } + + /** + * Formats elapsed time (in seconds) to a string. + * + * @param float $time + * @return float + * @access public + * @static + */ + public static function secondsToTimeString($time) + { + $buffer = ''; + + $hours = sprintf('%02d', ($time >= 3600) ? floor($time / 3600) : 0); + $minutes = sprintf('%02d', ($time >= 60) ? floor($time / 60) - 60 * $hours : 0); + $seconds = sprintf('%02d', $time - 60 * 60 * $hours - 60 * $minutes); + + if ($hours == 0 && $minutes == 0) { + $seconds = sprintf('%1d', $seconds); + + $buffer .= $seconds . ' second'; + + if ($seconds != '1') { + $buffer .= 's'; + } + } else { + if ($hours > 0) { + $buffer = $hours . ':'; + } + + $buffer .= $minutes . ':' . $seconds; + } + + return $buffer; + } +} +?> Property changes on: test/PHPUnit/Util/Timer.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/Type.php =================================================================== --- test/PHPUnit/Util/Type.php (revision 0) +++ test/PHPUnit/Util/Type.php (revision 0) @@ -0,0 +1,197 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: Type.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/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Utility class for textual type (and value) representation. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class PHPUnit_Util_Type +{ + public static function isType($type) + { + return in_array( + $type, + array( + 'numeric', + 'integer', + 'int', + 'float', + 'string', + 'boolean', + 'bool', + 'null', + 'array', + 'object', + 'resource' + ) + ); + } + + public static function shortenedExport($value) + { + if (is_string($value)) { + return self::shortenedString($value); + } + + elseif (is_array($value)) { + if (count($value) == 0) { + return 'array()'; + } + + $a1 = array_slice($value, 0, 1, TRUE); + $k1 = key($a1); + $v1 = $a1[$k1]; + + if (is_string($v1)) { + $v1 = self::shortenedString($v1); + } + + elseif (is_array($v1)) { + $v1 = 'array(...)'; + } else { + $v1 = self::toString($v1); + } + + $a2 = FALSE; + + if (count($value) > 1) { + $a2 = array_slice($value, -1, 1, TRUE); + $k2 = key($a2); + $v2 = $a2[$k2]; + + if (is_string($v2)) { + $v2 = self::shortenedString($v2); + } + + elseif (is_array($v2)) { + $v2 = 'array(...)'; + } else { + $v2 = self::toString($v2); + } + } + + $text = 'array( ' . self::toString($k1) . ' => ' . $v1; + + if ($a2 !== FALSE) { + $text .= ', ..., ' . self::toString($k2) . ' => ' . $v2 . ' )'; + } else { + $text .= ' )'; + } + + return $text; + } + + elseif (is_object($value)) { + return get_class($value) . '(...)'; + } + + return self::toString($value); + } + + public static function shortenedString($string) + { + $string = preg_replace('#\n|\r\n|\r#', ' ', $string); + + if (strlen($string) > 14) { + return PHPUnit_Util_Type::toString( + substr($string, 0, 7) . '...' . substr($string, -7) + ); + } else { + return PHPUnit_Util_Type::toString($string); + } + } + + public static function toString($value, $short = FALSE) + { + if (is_array($value) || is_object($value)) { + if (!$short) { + return "\n" . print_r($value, TRUE); + } else { + if (is_array($value)) { + return ''; + } else { + return '<' . get_class($value) . '>'; + } + } + } + + if (is_string($value) && strpos($value, "\n") !== FALSE) { + return ''; + } + + if (!is_null($value)) { + $type = gettype($value) . ':'; + } else { + $type = ''; + $value = 'null'; + } + + if (is_bool($value)) { + if ($value === TRUE) { + $value = 'true'; + } + + else if ($value === FALSE) { + $value = 'false'; + } + } + + return '<' . $type . $value . '>'; + } +} +?> Property changes on: test/PHPUnit/Util/Type.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/PDO.php =================================================================== --- test/PHPUnit/Util/PDO.php (revision 0) +++ test/PHPUnit/Util/PDO.php (revision 0) @@ -0,0 +1,357 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @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 + * @copyright 2002-2008 Sebastian Bergmann + * @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: + * + * phptype(dbsyntax)://username:password@protocol+hostspec/database?option=8&another=true + * + * + * Most variations are allowed: + * + * 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 + * + * + * 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; + } +} +?> Property changes on: test/PHPUnit/Util/PDO.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/Printer.php =================================================================== --- test/PHPUnit/Util/Printer.php (revision 0) +++ test/PHPUnit/Util/Printer.php (revision 0) @@ -0,0 +1,149 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @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 + * @copyright 2002-2008 Sebastian Bergmann + * @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; + } + } +} +?> Property changes on: test/PHPUnit/Util/Printer.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/Filesystem.php =================================================================== --- test/PHPUnit/Util/Filesystem.php (revision 0) +++ test/PHPUnit/Util/Filesystem.php (revision 0) @@ -0,0 +1,160 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: Filesystem.php 2050 2008-01-09 14:54:58Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Filesystem helpers. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class PHPUnit_Util_Filesystem +{ + /** + * Wrapper for file_exists() that searches the include_path. + * + * @param string $file + * @return mixed + * @access public + * @static + * @author Mattis Stordalen Flister + * @since Method available since Release 3.2.9 + */ + public static function fileExistsInIncludePath($file) { + $paths = explode(PATH_SEPARATOR, get_include_path()); + + foreach ($paths as $path) { + $fullpath = $path . DIRECTORY_SEPARATOR . $file; + + if (file_exists($fullpath)) { + return realpath($fullpath); + } + } + + return FALSE; + } + + /** + * Returns the common path of a set of files. + * + * @param array $paths + * @return string + * @access public + * @static + * @since Method available since Release 3.1.0 + */ + public static function getCommonPath(array $paths) + { + $count = count($paths); + + if ($count == 1) { + return dirname($paths[0]) . DIRECTORY_SEPARATOR; + } + + $_paths = array(); + + for ($i = 0; $i < $count; $i++) { + $_paths[$i] = explode(DIRECTORY_SEPARATOR, $paths[$i]); + + if (empty($_paths[$i][0])) { + $_paths[$i][0] = DIRECTORY_SEPARATOR; + } + } + + $common = ''; + $done = FALSE; + $j = 0; + $count--; + + while (!$done) { + for ($i = 0; $i < $count; $i++) { + if ($_paths[$i][$j] != $_paths[$i+1][$j]) { + $done = TRUE; + break; + } + } + + if (!$done) { + $common .= $_paths[0][$j]; + + if ($j > 0) { + $common .= DIRECTORY_SEPARATOR; + } + } + + $j++; + } + + return $common; + } + + /** + * Returns a filesystem safe version of the passed filename. + * This function does not operate on full paths, just filenames. + * + * @param string $filename + * @return string + * @access public + * @static + * @author Michael Lively Jr. + */ + public static function getSafeFilename($filename) + { + /* characters allowed: A-Z, a-z, 0-9, _ and . */ + return preg_replace('#[^\w.]#', '_', $filename); + } +} +?> Property changes on: test/PHPUnit/Util/Filesystem.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/Skeleton.php =================================================================== --- test/PHPUnit/Util/Skeleton.php (revision 0) +++ test/PHPUnit/Util/Skeleton.php (revision 0) @@ -0,0 +1,394 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: Skeleton.php 1985 2007-12-26 18:11:55Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 2.1.0 + */ + +require_once 'PHPUnit/Util/Filter.php'; +require_once 'PHPUnit/Util/Template.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Generator for TestCase skeletons. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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.1.0 + */ +class PHPUnit_Util_Skeleton +{ + /** + * @var string + * @access protected + */ + protected $className; + + /** + * @var string + * @access protected + */ + protected $classSourceFile; + + /** + * @var string + * @access protected + */ + protected $testSourceFile; + + /** + * @var array + * @access protected + */ + protected $methodNameCounter = array(); + + /** + * Constructor. + * + * @param string $className + * @param string $classSourceFile + * @throws RuntimeException + * @access public + */ + public function __construct($className, $classSourceFile = '') + { + $this->className = $className; + $this->testSourceFile = $className . 'Test.php'; + + if (class_exists($className)) { + $this->classSourceFile = ''; + } + + else if (empty($classSourceFile) && is_file($className . '.php')) { + $this->classSourceFile = $className . '.php'; + } + + else if (empty($classSourceFile) || + is_file(str_replace('_', '/', $className) . '.php')) { + $this->classSourceFile = str_replace('_', '/', $className) . '.php'; + $this->testSourceFile = str_replace('_', '/', $className) . 'Test.php'; + } + + else if (empty($classSourceFile)) { + throw new RuntimeException( + sprintf( + 'Neither "%s.php" nor "%s.php" could be opened.', + $className, + str_replace('_', '/', $className) + ) + ); + } + + else if (!is_file($classSourceFile)) { + throw new RuntimeException( + sprintf( + '"%s" could not be opened.', + + $classSourceFile + ) + ); + } else { + $this->classSourceFile = $classSourceFile; + } + + if ($this->classSourceFile != '') { + include_once $this->classSourceFile; + } + + if (!class_exists($className)) { + throw new RuntimeException( + sprintf( + 'Could not find class "%s" in "%s".', + + $className, + realpath($this->classSourceFile) + ) + ); + } + } + + /** + * Generates the test class' source. + * + * @param boolean $verbose + * @return mixed + * @access public + */ + public function generate($verbose = FALSE) + { + $class = new ReflectionClass($this->className); + $methods = ''; + $incompleteMethods = ''; + + foreach ($class->getMethods() as $method) { + if (!$method->isConstructor() && + !$method->isAbstract() && + $method->isPublic() && + $method->getDeclaringClass()->getName() == $this->className) { + $assertAnnotationFound = FALSE; + + if (preg_match_all('/@assert(.*)$/Um', $method->getDocComment(), $annotations)) { + foreach ($annotations[1] as $annotation) { + if (preg_match('/\((.*)\)\s+([^\s]*)\s+(.*)/', $annotation, $matches)) { + switch ($matches[2]) { + case '==': { + $assertion = 'Equals'; + } + break; + + case '!=': { + $assertion = 'NotEquals'; + } + break; + + case '===': { + $assertion = 'Same'; + } + break; + + case '!==': { + $assertion = 'NotSame'; + } + break; + + case '>': { + $assertion = 'GreaterThan'; + } + break; + + case '>=': { + $assertion = 'GreaterThanOrEqual'; + } + break; + + case '<': { + $assertion = 'LessThan'; + } + break; + + case '<=': { + $assertion = 'LessThanOrEqual'; + } + break; + + case 'throws': { + $assertion = 'exception'; + } + break; + + default: { + throw new RuntimeException; + } + } + + if ($assertion == 'exception') { + $template = 'TestMethodException'; + } + + else if ($assertion == 'Equals' && strtolower($matches[3]) == 'true') { + $assertion = 'True'; + $template = 'TestMethodBool'; + } + + else if ($assertion == 'NotEquals' && strtolower($matches[3]) == 'true') { + $assertion = 'False'; + $template = 'TestMethodBool'; + } + + else if ($assertion == 'Equals' && strtolower($matches[3]) == 'false') { + $assertion = 'False'; + $template = 'TestMethodBool'; + } + + else if ($assertion == 'NotEquals' && strtolower($matches[3]) == 'false') { + $assertion = 'True'; + $template = 'TestMethodBool'; + } + + else { + $template = 'TestMethod'; + } + + if ($method->isStatic()) { + $template .= 'Static'; + } + + $methodTemplate = new PHPUnit_Util_Template( + sprintf( + '%s%sSkeleton%s%s.tpl', + + dirname(__FILE__), + DIRECTORY_SEPARATOR, + DIRECTORY_SEPARATOR, + $template + ) + ); + + $origMethodName = $method->getName(); + $methodName = ucfirst($origMethodName); + + if (isset($this->methodNameCounter[$methodName])) { + $this->methodNameCounter[$methodName]++; + } else { + $this->methodNameCounter[$methodName] = 1; + } + + if ($this->methodNameCounter[$methodName] > 1) { + $methodName .= $this->methodNameCounter[$methodName]; + } + + $methodTemplate->setVar( + array( + 'annotation' => trim($annotation), + 'arguments' => $matches[1], + 'assertion' => isset($assertion) ? $assertion : '', + 'expected' => $matches[3], + 'origMethodName' => $origMethodName, + 'className' => $this->className, + 'methodName' => $methodName + ) + ); + + $methods .= $methodTemplate->render(); + + $assertAnnotationFound = TRUE; + } + } + } + + if (!$assertAnnotationFound) { + $methodTemplate = new PHPUnit_Util_Template( + sprintf( + '%s%sSkeleton%sIncompleteTestMethod.tpl', + + dirname(__FILE__), + DIRECTORY_SEPARATOR, + DIRECTORY_SEPARATOR + ) + ); + + $methodTemplate->setVar( + array( + 'methodName' => ucfirst($method->getName()) + ) + ); + + $incompleteMethods .= $methodTemplate->render(); + } + } + } + + $classTemplate = new PHPUnit_Util_Template( + sprintf( + '%s%sSkeleton%sTestClass.tpl', + + dirname(__FILE__), + DIRECTORY_SEPARATOR, + DIRECTORY_SEPARATOR + ) + ); + + if ($this->classSourceFile != '') { + $requireClassFile = sprintf( + "\n\nrequire_once '%s';", + + $this->classSourceFile + ); + } else { + $requireClassFile = ''; + } + + $classTemplate->setVar( + array( + 'className' => $this->className, + 'requireClassFile' => $requireClassFile, + 'methods' => $methods . $incompleteMethods, + 'date' => date('Y-m-d'), + 'time' => date('H:i:s') + ) + ); + + if (!$verbose) { + return $classTemplate->render(); + } else { + return array( + 'code' => $classTemplate->render(), + 'incomplete' => empty($methods) + ); + } + } + + /** + * Generates the test class and writes it to a source file. + * + * @param string $file + * @access public + */ + public function write($file = '') + { + if ($file == '') { + $file = $this->testSourceFile; + } + + if ($fp = @fopen($file, 'wt')) { + @fwrite($fp, $this->generate()); + @fclose($fp); + } + } + + /** + * @return string + * @access public + * @since Method available since Release 3.0.0 + */ + public function getTestSourceFile() + { + return $this->testSourceFile; + } +} +?> Property changes on: test/PHPUnit/Util/Skeleton.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/Report/Node/File.php =================================================================== --- test/PHPUnit/Util/Report/Node/File.php (revision 0) +++ test/PHPUnit/Util/Report/Node/File.php (revision 0) @@ -0,0 +1,842 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: File.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'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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_File extends PHPUnit_Util_Report_Node +{ + /** + * @var array + * @access protected + */ + protected $codeLines; + + /** + * @var array + * @access protected + */ + protected $codeLinesFillup = array(); + + /** + * @var array + * @access protected + */ + protected $executedLines; + + /** + * @var boolean + * @access protected + */ + protected $yui = TRUE; + + /** + * @var boolean + * @access protected + */ + protected $highlight = FALSE; + + /** + * @var integer + * @access protected + */ + protected $numExecutableLines = 0; + + /** + * @var integer + * @access protected + */ + protected $numExecutedLines = 0; + + /** + * @var array + * @access protected + */ + protected $classes = array(); + + /** + * @var integer + * @access protected + */ + protected $numClasses = 0; + + /** + * @var integer + * @access protected + */ + protected $numCalledClasses = 0; + + /** + * @var integer + * @access protected + */ + protected $numMethods = 0; + + /** + * @var integer + * @access protected + */ + protected $numCalledMethods = 0; + + /** + * @var string + * @access protected + */ + protected $yuiPanelJS = ''; + + /** + * Constructor. + * + * @param string $name + * @param PHPUnit_Util_Report_Node $parent + * @param array $executedLines + * @param boolean $yui + * @param boolean $highlight + * @throws RuntimeException + * @access public + */ + public function __construct($name, PHPUnit_Util_Report_Node $parent = NULL, array $executedLines, $yui = TRUE, $highlight = FALSE) + { + parent::__construct($name, $parent); + + $path = $this->getPath(); + + if (!file_exists($path)) { + throw new RuntimeException; + } + + $this->executedLines = $executedLines; + $this->highlight = $highlight; + $this->yui = $yui; + $this->codeLines = $this->loadFile($path); + + $this->calculateStatistics(); + } + + /** + * Returns the classes of this node. + * + * @return array + * @access public + */ + public function getClasses() + { + return $this->classes; + } + + /** + * Returns the number of executable lines. + * + * @return integer + * @access public + */ + public function getNumExecutableLines() + { + return $this->numExecutableLines; + } + + /** + * Returns the number of executed lines. + * + * @return integer + * @access public + */ + public function getNumExecutedLines() + { + return $this->numExecutedLines; + } + + /** + * Returns the number of classes. + * + * @return integer + * @access public + */ + public function 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() + { + return $this->numCalledClasses; + } + + /** + * Returns the number of methods. + * + * @return integer + * @access public + */ + public function getNumMethods() + { + return $this->numMethods; + } + + /** + * Returns the number of methods that has been called at least once. + * + * @return integer + * @access public + */ + public function 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) + { + if ($this->yui) { + $template = new PHPUnit_Util_Template( + PHPUnit_Util_Report::$templatePath . 'file.html' + ); + + $yuiTemplate = new PHPUnit_Util_Template( + PHPUnit_Util_Report::$templatePath . 'yui_item.js' + ); + } else { + $template = new PHPUnit_Util_Template( + PHPUnit_Util_Report::$templatePath . 'file_no_yui.html' + ); + } + + $i = 1; + $lines = ''; + $ignore = FALSE; + + foreach ($this->codeLines as $line) { + if (strpos($line, '@codeCoverageIgnore') !== FALSE) { + if (strpos($line, '@codeCoverageIgnoreStart') !== FALSE) { + $ignore = TRUE; + } + + else if (strpos($line, '@codeCoverageIgnoreEnd') !== FALSE) { + $ignore = FALSE; + } + } + + $css = ''; + + if (!$ignore && isset($this->executedLines[$i])) { + $count = ''; + + // Array: Line is executable and was executed. + // count(Array) = Number of tests that hit this line. + if (is_array($this->executedLines[$i])) { + $color = 'lineCov'; + $numTests = count($this->executedLines[$i]); + $count = sprintf('%8d', $numTests); + + if ($this->yui) { + $buffer = ''; + + foreach ($this->executedLines[$i] as $test) { + if (!isset($test->__liHtml)) { + $test->__liHtml = ''; + + if ($test instanceof PHPUnit_Framework_SelfDescribing) { + $testName = $test->toString(); + + if ($test instanceof PHPUnit_Framework_TestCase) { + switch ($test->getStatus()) { + case PHPUnit_Runner_BaseTestRunner::STATUS_PASSED: { + $testCSS = ' class=\"testPassed\"'; + } + break; + + case PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE: { + $testCSS = ' class=\"testFailure\"'; + } + break; + + case PHPUnit_Runner_BaseTestRunner::STATUS_ERROR: { + $testCSS = ' class=\"testError\"'; + } + break; + + case PHPUnit_Runner_BaseTestRunner::STATUS_INCOMPLETE: + case PHPUnit_Runner_BaseTestRunner::STATUS_SKIPPED: { + $testCSS = ' class=\"testIncomplete\"'; + } + break; + + default: { + $testCSS = ''; + } + } + } + } + + $test->__liHtml .= sprintf( + '%s', + + $testCSS, + $testName + ); + } + + $buffer .= $test->__liHtml; + } + + if ($numTests > 1) { + $header = $numTests . ' tests cover'; + } else { + $header = '1 test covers'; + } + + $header .= ' line ' . $i; + + $yuiTemplate->setVar( + array( + 'line' => $i, + 'header' => $header, + 'tests' => $buffer + ), + FALSE + ); + + $this->yuiPanelJS .= $yuiTemplate->render(); + } + } + + // -1: Line is executable and was not executed. + else if ($this->executedLines[$i] == -1) { + $color = 'lineNoCov'; + $count = sprintf('%8d', 0); + } + + // -2: Line is dead code. + else { + $color = 'lineDeadCode'; + $count = ' '; + } + + $css = sprintf( + ' %s : ', + + $color, + $count + ); + } + + $fillup = array_shift($this->codeLinesFillup); + + if ($fillup > 0) { + $line .= str_repeat(' ', $fillup); + } + + $lines .= sprintf( + '
%8d %s%s%s' . "\n", + + $i, + $i, + $i, + $i, + $i, + !empty($css) ? $css : ' : ', + !$this->highlight ? htmlspecialchars($line) : $line, + !empty($css) ? '' : '' + ); + + $i++; + } + + $items = ''; + + foreach ($this->classes as $className => $classData) { + $numCalledClasses = $classData['executedLines'] > 0 ? 1 : 0; + $calledClassesPercent = $numCalledClasses == 1 ? 100 : 0; + + $numCalledMethods = 0; + $numMethods = count($classData['methods']); + + foreach ($classData['methods'] as $method) { + if ($method['executedLines'] > 0) { + $numCalledMethods++; + } + } + + $items .= $this->doRenderItem( + array( + 'name' => sprintf( + '%s', + + $classData['startLine'], + $className + ), + 'numClasses' => 1, + 'numCalledClasses' => $numCalledClasses, + 'calledClassesPercent' => sprintf('%01.2f', $calledClassesPercent), + 'numMethods' => $numMethods, + 'numCalledMethods' => $numCalledMethods, + 'calledMethodsPercent' => $this->calculatePercent( + $numCalledMethods, $numMethods + ), + 'numExecutableLines' => $classData['executableLines'], + 'numExecutedLines' => $classData['executedLines'], + 'executedLinesPercent' => $this->calculatePercent( + $classData['executedLines'], $classData['executableLines'] + ) + ), + $lowUpperBound, + $highLowerBound + ); + + foreach ($classData['methods'] as $methodName => $methodData) { + $numCalledMethods = $methodData['executedLines'] > 0 ? 1 : 0; + $calledMethodsPercent = $numCalledMethods == 1 ? 100 : 0; + + $items .= $this->doRenderItem( + array( + 'name' => sprintf( + ' %s', + + $methodData['startLine'], + PHPUnit_Util_Class::getMethodSignature( + new ReflectionMethod($className, $methodName) + ) + ), + 'numClasses' => '', + 'numCalledClasses' => '', + 'calledClassesPercent' => '', + 'numMethods' => 1, + 'numCalledMethods' => $numCalledMethods, + 'calledMethodsPercent' => sprintf('%01.2f', $calledMethodsPercent), + 'numExecutableLines' => $methodData['executableLines'], + 'numExecutedLines' => $methodData['executedLines'], + 'executedLinesPercent' => $this->calculatePercent( + $methodData['executedLines'], $methodData['executableLines'] + ) + ), + $lowUpperBound, + $highLowerBound, + 'method_item.html' + ); + } + } + + $this->setTemplateVars($template, $title, $charset); + + $template->setVar( + array( + 'lines' => $lines, + 'total_item' => $this->renderTotalItem($lowUpperBound, $highLowerBound, FALSE), + 'items' => $items, + 'yuiPanelJS' => $this->yuiPanelJS + ) + ); + + $cleanId = PHPUnit_Util_Filesystem::getSafeFilename($this->getId()); + $template->renderTo($target . $cleanId . '.html'); + } + + /** + * Calculates coverage statistics for the file. + * + * @access protected + */ + protected function calculateStatistics() + { + $classes = PHPUnit_Util_Class::getClassesInFile($this->getPath()); + + $startLines = array(); + $endLines = array(); + + foreach ($classes as $class) { + if (!$class->isInterface()) { + $className = $class->getName(); + $classStartLine = $class->getStartLine(); + $classEndLine = $class->getEndLine(); + + $this->classes[$className] = array( + 'methods' => array(), + 'startLine' => $classStartLine, + 'executableLines' => 0, + 'executedLines' => 0 + ); + + $startLines[$classStartLine] = &$this->classes[$className]; + $endLines[$classEndLine] = &$this->classes[$className]; + + foreach ($class->getMethods() as $method) { + if (!$method->isAbstract() && + $method->getDeclaringClass()->getName() == $className) { + $methodName = $method->getName(); + $methodStartLine = $method->getStartLine(); + $methodEndLine = $method->getEndLine(); + + $this->classes[$className]['methods'][$methodName] = array( + 'startLine' => $methodStartLine, + 'executableLines' => 0, + 'executedLines' => 0 + ); + + $startLines[$methodStartLine] = &$this->classes[$className]['methods'][$methodName]; + $endLines[$methodEndLine] = &$this->classes[$className]['methods'][$methodName]; + + $this->numMethods++; + } + } + + $this->numClasses++; + } + } + + $ignoreStart = -1; + $lineNumber = 1; + + foreach ($this->codeLines as $line) { + if (isset($startLines[$lineNumber])) { + // Start line of a class. + if (isset($startLines[$lineNumber]['methods'])) { + $currentClass = &$startLines[$lineNumber]; + } + + // Start line of a method. + else { + $currentMethod = &$startLines[$lineNumber]; + } + } + + if (strpos($line, '@codeCoverageIgnore') !== FALSE) { + if (strpos($line, '@codeCoverageIgnoreStart') !== FALSE) { + $ignoreStart = $line; + } + + else if (strpos($line, '@codeCoverageIgnoreEnd') !== FALSE) { + $ignoreStart = -1; + } + } + + if (isset($this->executedLines[$lineNumber])) { + // Array: Line is executable and was executed. + if (is_array($this->executedLines[$lineNumber])) { + if (isset($currentClass)) { + $currentClass['executableLines']++; + $currentClass['executedLines']++; + } + + if (isset($currentMethod)) { + $currentMethod['executableLines']++; + $currentMethod['executedLines']++; + } + + $this->numExecutableLines++; + $this->numExecutedLines++; + } + + // -1: Line is executable and was not executed. + else if ($this->executedLines[$lineNumber] == -1) { + if (isset($currentClass)) { + $currentClass['executableLines']++; + } + + if (isset($currentMethod)) { + $currentMethod['executableLines']++; + } + + $this->numExecutableLines++; + + if ($ignoreStart != -1 && $line > $ignoreStart) { + if (isset($currentClass)) { + $currentClass['executedLines']++; + } + + if (isset($currentMethod)) { + $currentMethod['executedLines']++; + } + + $this->numExecutedLines++; + } + } + } + + if (isset($endLines[$lineNumber])) { + // End line of a class. + if (isset($endLines[$lineNumber]['methods'])) { + unset($currentClass); + } + + // End line of a method. + else { + unset($currentMethod); + } + } + + $lineNumber++; + } + + foreach ($this->classes as $class) { + foreach ($class['methods'] as $method) { + if ($method['executedLines'] > 0) { + $this->numCalledMethods++; + } + } + + if ($class['executedLines'] > 0) { + $this->numCalledClasses++; + } + } + } + + /** + * @author Aidan Lister + * @author Sebastian Bergmann + * @param string $file + * @return array + * @access protected + */ + protected function loadFile($file) + { + $lines = explode("\n", str_replace("\t", ' ', file_get_contents($file))); + $result = array(); + + if (count($lines) == 0) { + return $result; + } + + $lines = array_map('rtrim', $lines); + $linesLength = array_map('strlen', $lines); + $width = max($linesLength); + + foreach ($linesLength as $line => $length) { + $this->codeLinesFillup[$line] = $width - $length; + } + + if (!$this->highlight) { + return $lines; + } + + $tokens = token_get_all(file_get_contents($file)); + $stringFlag = FALSE; + $i = 0; + $result[$i] = ''; + + foreach ($tokens as $j => $token) { + if (is_string($token)) { + if ($token === '"' && $tokens[$j - 1] !== '\\') { + $result[$i] .= sprintf( + '%s', + + htmlspecialchars($token) + ); + + $stringFlag = !$stringFlag; + } else { + $result[$i] .= sprintf( + '%s', + + htmlspecialchars($token) + ); + } + + continue; + } + + list ($token, $value) = $token; + + $value = str_replace( + array("\t", ' '), + array('    ', ' '), + htmlspecialchars($value) + ); + + if ($value === "\n") { + $result[++$i] = ''; + } else { + $lines = explode("\n", $value); + + foreach ($lines as $jj => $line) { + $line = trim($line); + + if ($line !== '') { + if ($stringFlag) { + $colour = 'string'; + } else { + switch ($token) { + case T_INLINE_HTML: { + $colour = 'html'; + } + break; + + case T_COMMENT: + case T_DOC_COMMENT: { + $colour = 'comment'; + } + break; + + case T_ABSTRACT: + case T_ARRAY: + case T_ARRAY_CAST: + case T_AS: + case T_BOOLEAN_AND: + case T_BOOLEAN_OR: + case T_BOOL_CAST: + case T_BREAK: + case T_CASE: + case T_CATCH: + case T_CLASS: + case T_CLONE: + case T_CONCAT_EQUAL: + case T_CONTINUE: + case T_DEFAULT: + case T_DOUBLE_ARROW: + case T_DOUBLE_CAST: + case T_ECHO: + case T_ELSE: + case T_ELSEIF: + case T_EMPTY: + case T_ENDDECLARE: + case T_ENDFOR: + case T_ENDFOREACH: + case T_ENDIF: + case T_ENDSWITCH: + case T_ENDWHILE: + case T_END_HEREDOC: + case T_EXIT: + case T_EXTENDS: + case T_FINAL: + case T_FOREACH: + case T_FUNCTION: + case T_GLOBAL: + case T_IF: + case T_INC: + case T_INCLUDE: + case T_INCLUDE_ONCE: + case T_INSTANCEOF: + case T_INT_CAST: + case T_ISSET: + case T_IS_EQUAL: + case T_IS_IDENTICAL: + case T_IS_NOT_IDENTICAL: + case T_IS_SMALLER_OR_EQUAL: + case T_NEW: + case T_OBJECT_CAST: + case T_OBJECT_OPERATOR: + case T_PAAMAYIM_NEKUDOTAYIM: + case T_PRIVATE: + case T_PROTECTED: + case T_PUBLIC: + case T_REQUIRE: + case T_REQUIRE_ONCE: + case T_RETURN: + case T_SL: + case T_SL_EQUAL: + case T_SR: + case T_SR_EQUAL: + case T_START_HEREDOC: + case T_STATIC: + case T_STRING_CAST: + case T_THROW: + case T_TRY: + case T_UNSET_CAST: + case T_VAR: + case T_WHILE: { + $colour = 'keyword'; + } + break; + + default: { + $colour = 'default'; + } + } + } + + $result[$i] .= sprintf( + '%s', + + $colour, + $line + ); + } + + if (isset($lines[$jj + 1])) { + $result[++$i] = ''; + } + } + } + } + + unset($result[count($result)-1]); + + return $result; + } +} +?> Property changes on: test/PHPUnit/Util/Report/Node/File.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/Report/Node/Directory.php =================================================================== --- test/PHPUnit/Util/Report/Node/Directory.php (revision 0) +++ test/PHPUnit/Util/Report/Node/Directory.php (revision 0) @@ -0,0 +1,429 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @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 + * @copyright 2002-2008 Sebastian Bergmann + * @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; + } +} +?> Property changes on: test/PHPUnit/Util/Report/Node/Directory.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/Report/Node.php =================================================================== --- test/PHPUnit/Util/Report/Node.php (revision 0) +++ test/PHPUnit/Util/Report/Node.php (revision 0) @@ -0,0 +1,486 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @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 + * @copyright 2002-2008 Sebastian Bergmann + * @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%s', + $parent, + $cleanId, + $name + ); + } else { + return sprintf( + '%s', + $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') . + " \n" . + '  ' . "\n" . + " \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); +} +?> Property changes on: test/PHPUnit/Util/Report/Node.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/Report/Template/file.html =================================================================== --- test/PHPUnit/Util/Report/Template/file.html (revision 0) +++ test/PHPUnit/Util/Report/Template/file.html (revision 0) @@ -0,0 +1,118 @@ + + + + + + {title} + + + + + + + + + + + + + + + + + + +
{title}
+ + + + + + + + + +
Current file:{link}
Legend: + executed + not executed + dead code +
+
+ +
+ +
+ + + + + + + + + + + +{total_item}{items} +
 Coverage
 ClassesMethodsLines
+
+ +
+ + + + + + + + +

+
+{lines}
+
+
+ + + + +
Generated by PHPUnit {phpunit_version} and Xdebug {xdebug_version} at {date}.
+ +
+ + + + Property changes on: test/PHPUnit/Util/Report/Template/file.html ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/Report/Template/yahoo-dom-event.js =================================================================== --- test/PHPUnit/Util/Report/Template/yahoo-dom-event.js (revision 0) +++ test/PHPUnit/Util/Report/Template/yahoo-dom-event.js (revision 0) @@ -0,0 +1 @@ +if(typeof YAHOO=="undefined"){var YAHOO={};}YAHOO.namespace=function(){var A=arguments,E=null,C,B,D;for(C=0;C0)?C.dump(A[D],G-1):J);}else{I.push(A[D]);}I.push(H);}if(I.length>1){I.pop();}I.push("]");}else{I.push("{");for(D in A){if(C.hasOwnProperty(A,D)){I.push(D+E);if(C.isObject(A[D])){I.push((G>0)?C.dump(A[D],G-1):J);}else{I.push(A[D]);}I.push(H);}}if(I.length>1){I.pop();}I.push("}");}return I.join("");},substitute:function(Q,B,J){var G,F,E,M,N,P,D=YAHOO.lang,L=[],C,H="dump",K=" ",A="{",O="}";for(;;){G=Q.lastIndexOf(A);if(G<0){break;}F=Q.indexOf(O,G);if(G+1>=F){break;}C=Q.substring(G+1,F);M=C;P=null;E=M.indexOf(K);if(E>-1){P=M.substring(E+1);M=M.substring(0,E);}N=B[M];if(J){N=J(M,N,P);}if(D.isObject(N)){if(D.isArray(N)){N=D.dump(N,parseInt(P,10));}else{P=P||"";var I=P.indexOf(H);if(I>-1){P=P.substring(4);}if(N.toString===Object.prototype.toString||I>-1){N=D.dump(N,parseInt(P,10));}else{N=N.toString();}}}else{if(!D.isString(N)&&!D.isNumber(N)){N="~-"+L.length+"-~";L[L.length]=C;}}Q=Q.substring(0,G)+N+Q.substring(F+1);}for(G=L.length-1;G>=0;G=G-1){Q=Q.replace(new RegExp("~-"+G+"-~"),"{"+L[G]+"}","g");}return Q;},trim:function(A){try{return A.replace(/^\s+|\s+$/g,"");}catch(B){return A;}},merge:function(){var C={},A=arguments,B;for(B=0;B=this.left&&A.right<=this.right&&A.top>=this.top&&A.bottom<=this.bottom);};YAHOO.util.Region.prototype.getArea=function(){return((this.bottom-this.top)*(this.right-this.left));};YAHOO.util.Region.prototype.intersect=function(E){var C=Math.max(this.top,E.top);var D=Math.min(this.right,E.right);var A=Math.min(this.bottom,E.bottom);var B=Math.max(this.left,E.left);if(A>=C&&D>=B){return new YAHOO.util.Region(C,D,A,B);}else{return null;}};YAHOO.util.Region.prototype.union=function(E){var C=Math.min(this.top,E.top);var D=Math.max(this.right,E.right);var A=Math.max(this.bottom,E.bottom);var B=Math.min(this.left,E.left);return new YAHOO.util.Region(C,D,A,B);};YAHOO.util.Region.prototype.toString=function(){return("Region {top: "+this.top+", right: "+this.right+", bottom: "+this.bottom+", left: "+this.left+"}");};YAHOO.util.Region.getRegion=function(D){var F=YAHOO.util.Dom.getXY(D);var C=F[1];var E=F[0]+D.offsetWidth;var A=F[1]+D.offsetHeight;var B=F[0];return new YAHOO.util.Region(C,E,A,B);};YAHOO.util.Point=function(A,B){if(YAHOO.lang.isArray(A)){B=A[1];A=A[0];}this.x=this.right=this.left=this[0]=A;this.y=this.top=this.bottom=this[1]=B;};YAHOO.util.Point.prototype=new YAHOO.util.Region();YAHOO.register("dom",YAHOO.util.Dom,{version:"2.3.1",build:"541"});YAHOO.util.CustomEvent=function(D,B,C,A){this.type=D;this.scope=B||window;this.silent=C;this.signature=A||YAHOO.util.CustomEvent.LIST;this.subscribers=[];if(!this.silent){}var E="_YUICEOnSubscribe";if(D!==E){this.subscribeEvent=new YAHOO.util.CustomEvent(E,this,true);}this.lastError=null;};YAHOO.util.CustomEvent.LIST=0;YAHOO.util.CustomEvent.FLAT=1;YAHOO.util.CustomEvent.prototype={subscribe:function(B,C,A){if(!B){throw new Error("Invalid callback for subscriber to '"+this.type+"'");}if(this.subscribeEvent){this.subscribeEvent.fire(B,C,A);}this.subscribers.push(new YAHOO.util.Subscriber(B,C,A));},unsubscribe:function(D,F){if(!D){return this.unsubscribeAll();}var E=false;for(var B=0,A=this.subscribers.length;B0){B=H[0];}try{G=L.fn.call(K,B,L.obj);}catch(F){this.lastError=F;}}else{try{G=L.fn.call(K,this.type,H,L.obj);}catch(F){this.lastError=F;}}if(false===G){if(!this.silent){}return false;}}}if(I){var J=[],C=this.subscribers;for(D=0,E=C.length;D=0){Q=I[R];}if(!M||!Q){return false;}if(this.useLegacyEvent(M,L)){var O=this.getLegacyIndex(M,L);var N=E[O];if(N){for(P=0,S=N.length;P0);}var P=[];var R=function(T,U){var S=T;if(U.override){if(U.override===true){S=U.obj;}else{S=U.override;}}U.fn.call(S,U.obj);};var M,L,O,N;for(M=0,L=F.length;M0){for(var R=0,S=T.length;R0){O=I.length;while(O){N=O-1;M=I[N];if(M){R.removeListener(M[R.EL],M[R.TYPE],M[R.FN],N);}O=O-1;}M=null;R.clearCache();}for(P=0,L=G.length;P");B=document.getElementById("_yui_eu_dr");}if(B){B.onreadystatechange=function(){if("complete"===this.readyState){this.parentNode.removeChild(this);YAHOO.util.Event._ready();}};}else{}B=null;}else{if(D.webkit){D._drwatch=setInterval(function(){var F=document.readyState;if("loaded"==F||"complete"==F){clearInterval(D._drwatch);D._drwatch=null;D._ready();}},D.POLL_INTERVAL);}else{D._simpleAdd(document,"DOMContentLoaded",D._ready);}}D._simpleAdd(window,"load",D._load);D._simpleAdd(window,"unload",D._unload);D._tryPreloadAttach();})();}YAHOO.util.EventProvider=function(){};YAHOO.util.EventProvider.prototype={__yui_events:null,__yui_subscribers:null,subscribe:function(A,C,F,E){this.__yui_events=this.__yui_events||{};var D=this.__yui_events[A];if(D){D.subscribe(C,F,E);}else{this.__yui_subscribers=this.__yui_subscribers||{};var B=this.__yui_subscribers;if(!B[A]){B[A]=[];}B[A].push({fn:C,obj:F,override:E});}},unsubscribe:function(C,E,G){this.__yui_events=this.__yui_events||{};var A=this.__yui_events;if(C){var F=A[C];if(F){return F.unsubscribe(E,G);}}else{var B=true;for(var D in A){if(YAHOO.lang.hasOwnProperty(A,D)){B=B&&A[D].unsubscribe(E,G);}}return B;}return false;},unsubscribeAll:function(A){return this.unsubscribe(A);},createEvent:function(G,D){this.__yui_events=this.__yui_events||{};var A=D||{};var I=this.__yui_events;if(I[G]){}else{var H=A.scope||this;var E=(A.silent);var B=new YAHOO.util.CustomEvent(G,H,E,YAHOO.util.CustomEvent.FLAT);I[G]=B;if(A.onSubscribeCallback){B.subscribeEvent.subscribe(A.onSubscribeCallback);}this.__yui_subscribers=this.__yui_subscribers||{};var F=this.__yui_subscribers[G];if(F){for(var C=0;C{tests}", + "footer": "" + }, Property changes on: test/PHPUnit/Util/Report/Template/yui_item.js ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/Report/Template/item.html =================================================================== --- test/PHPUnit/Util/Report/Template/item.html (revision 0) +++ test/PHPUnit/Util/Report/Template/item.html (revision 0) @@ -0,0 +1,31 @@ + + {name} + + + + + +
{classes_called_percent} %{classes_called_percent}%
+ + {classes_called_percent}% + {num_called_classes} / {num_classes} + + + + + +
{methods_called_percent} %{methods_called_percent}%
+ + {methods_called_percent}% + {num_called_methods} / {num_methods} + + + + + +
{lines_executed_percent} %{lines_executed_percent}%
+ + {lines_executed_percent}% + {num_executed_lines} / {num_executable_lines} + + Property changes on: test/PHPUnit/Util/Report/Template/item.html ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/Report/Template/method_item.html =================================================================== --- test/PHPUnit/Util/Report/Template/method_item.html (revision 0) +++ test/PHPUnit/Util/Report/Template/method_item.html (revision 0) @@ -0,0 +1,22 @@ + + {name} + + + + + +
{methods_called_percent} %{methods_called_percent}%
+ + {methods_called_percent}% + {num_called_methods} / {num_methods} + + + + + +
{lines_executed_percent} %{lines_executed_percent}%
+ + {lines_executed_percent}% + {num_executed_lines} / {num_executable_lines} + + Property changes on: test/PHPUnit/Util/Report/Template/method_item.html ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/Report/Template/file_no_yui.html =================================================================== --- test/PHPUnit/Util/Report/Template/file_no_yui.html (revision 0) +++ test/PHPUnit/Util/Report/Template/file_no_yui.html (revision 0) @@ -0,0 +1,79 @@ + + + + + + {title} + + + + + + + + + + + + + + + +
{title}
+ + + + + + + + + +
Current file:{link}
Legend: + executed + not executed + dead code +
+
+ +
+ +
+ + + + + + + + + + + +{total_item}{items} +
 Coverage
 ClassesMethodsLines
+
+ +
+ + + + + + + + +

+
+{lines}
+
+
+ + + + +
Generated by PHPUnit {phpunit_version} and Xdebug {xdebug_version} at {date}.
+ +
+ + Property changes on: test/PHPUnit/Util/Report/Template/file_no_yui.html ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/Report/Template/directory.html =================================================================== --- test/PHPUnit/Util/Report/Template/directory.html (revision 0) +++ test/PHPUnit/Util/Report/Template/directory.html (revision 0) @@ -0,0 +1,71 @@ + + + + + + {title} + + + + + + + + + + + + + + +
{title}
+ + + + + + + + + +
Current directory:{link}
Legend: + + Low: 0% to {low_upper_bound}% + + + Medium: {low_upper_bound}% to {high_lower_bound}% + + + High: {high_lower_bound}% to 100% + +
+
+ +
+ +
+ + + + + + + + + + + +{total_item}{items} +
 Coverage
 ClassesMethodsLines
+
+ +
+ + + + +
Generated by PHPUnit {phpunit_version} and Xdebug {xdebug_version} at {date}.
+ +
+ + Property changes on: test/PHPUnit/Util/Report/Template/directory.html ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/Report/Template/container.css =================================================================== --- test/PHPUnit/Util/Report/Template/container.css (revision 0) +++ test/PHPUnit/Util/Report/Template/container.css (revision 0) @@ -0,0 +1 @@ +/**/.yui-overlay,.yui-panel-container{visibility:hidden;position:absolute;z-index:2}.yui-tt{visibility:hidden;position:absolute;color:#333;background-color:#FDFFB4;font-family:arial,helvetica,verdana,sans-serif;padding:2px;border:1px solid #FCC90D;font:100% sans-serif;width:auto}/**/.yui-tt-shadow{display:none}* html body.masked select{visibility:hidden}* html div.yui-panel-container select{visibility:inherit}* html div.drag select{visibility:hidden}* html div.hide-select select{visibility:hidden}.mask{z-index:1;display:none;position:absolute;top:0;left:0;-moz-opacity:0.5;opacity:.50;filter:alpha(opacity=50);background-color:#CCC}/**/.hide-scrollbars,.hide-scrollbars *{overflow:hidden}.hide-scrollbars select{display:none}.show-scrollbars{overflow:auto}.yui-panel-container.show-scrollbars{overflow:visible}.yui-panel-container.show-scrollbars .underlay{overflow:auto}.yui-panel-container.focused{}/**/.yui-panel-container .underlay{position:absolute;top:0;right:0;bottom:0;left:0}.yui-panel-container.matte{padding:3px;background-color:#fff}.yui-panel-container.shadow .underlay{top:3px;bottom:-3px;right:-3px;left:3px;background-color:#000;opacity:.12;filter:alpha(opacity=12);/**/}.yui-panel{visibility:hidden;border-collapse:separate;position:relative;left:0;top:0;font:1em Arial;background-color:#FFF;border:1px solid #000;z-index:1;overflow:hidden}.yui-panel .hd{background-color:#3d77cb;color:#FFF;font-size:100%;line-height:100%;border:1px solid #FFF;border-bottom:1px solid #000;font-weight:bold;padding:4px;white-space:nowrap}.yui-panel .bd{overflow:hidden;padding:4px}.yui-panel .bd p{margin:0 0 1em}.yui-panel .container-close{position:absolute;top:5px;right:4px;z-index:6;height:12px;width:12px;margin:0px;padding:0px;background:url(close12_1.gif) no-repeat;cursor:pointer;visibility:inherit}.yui-panel .ft{padding:4px;overflow:hidden}.yui-simple-dialog .bd .yui-icon{background-repeat:no-repeat;width:16px;height:16px;margin-right:10px;float:left}.yui-simple-dialog .bd span.blckicon{background:url("blck16_1.gif") no-repeat}.yui-simple-dialog .bd span.alrticon{background:url("alrt16_1.gif") no-repeat}.yui-simple-dialog .bd span.hlpicon{background:url("hlp16_1.gif") no-repeat}.yui-simple-dialog .bd span.infoicon{background:url("info16_1.gif") no-repeat}.yui-simple-dialog .bd span.warnicon{background:url("warn16_1.gif") no-repeat}.yui-simple-dialog .bd span.tipicon{background:url("tip16_1.gif") no-repeat}.yui-dialog .ft,.yui-simple-dialog .ft{padding-bottom:5px;padding-right:5px;text-align:right}.yui-dialog form,.yui-simple-dialog form{margin:0}.button-group button{font:100 76% verdana;text-decoration:none;background-color:#E4E4E4;color:#333;cursor:hand;vertical-align:middle;border:2px solid #797979;border-top-color:#FFF;border-left-color:#FFF;margin:2px;padding:2px}.button-group button.default{font-weight:bold}.button-group button:hover,.button-group button.hover{border:2px solid #90A029;background-color:#EBF09E;border-top-color:#FFF;border-left-color:#FFF}.button-group button:active{border:2px solid #E4E4E4;background-color:#BBB;border-top-color:#333;border-left-color:#333} \ No newline at end of file Property changes on: test/PHPUnit/Util/Report/Template/container.css ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/Report/Template/snow.png =================================================================== Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Property changes on: test/PHPUnit/Util/Report/Template/snow.png ___________________________________________________________________ Name: svn:executable + * Name: svn:mime-type + application/octet-stream Index: test/PHPUnit/Util/Report/Template/scarlet_red.png =================================================================== Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Property changes on: test/PHPUnit/Util/Report/Template/scarlet_red.png ___________________________________________________________________ Name: svn:executable + * Name: svn:mime-type + application/octet-stream Index: test/PHPUnit/Util/Report/Template/container-min.js =================================================================== --- test/PHPUnit/Util/Report/Template/container-min.js (revision 0) +++ test/PHPUnit/Util/Report/Template/container-min.js (revision 0) @@ -0,0 +1 @@ +(function(){YAHOO.util.Config=function(D){if(D){this.init(D);}if(!D){}};var B=YAHOO.lang,C=YAHOO.util.CustomEvent,A=YAHOO.util.Config;A.CONFIG_CHANGED_EVENT="configChanged";A.BOOLEAN_TYPE="boolean";A.prototype={owner:null,queueInProgress:false,config:null,initialConfig:null,eventQueue:null,configChangedEvent:null,init:function(D){this.owner=D;this.configChangedEvent=this.createEvent(A.CONFIG_CHANGED_EVENT);this.configChangedEvent.signature=C.LIST;this.queueInProgress=false;this.config={};this.initialConfig={};this.eventQueue=[];},checkBoolean:function(D){return(typeof D==A.BOOLEAN_TYPE);},checkNumber:function(D){return(!isNaN(D));},fireEvent:function(D,F){var E=this.config[D];if(E&&E.event){E.event.fire(F);}},addProperty:function(E,D){E=E.toLowerCase();this.config[E]=D;D.event=this.createEvent(E,{scope:this.owner});D.event.signature=C.LIST;D.key=E;if(D.handler){D.event.subscribe(D.handler,this.owner);}this.setProperty(E,D.value,true);if(!D.suppressEvent){this.queueProperty(E,D.value);}},getConfig:function(){var D={},F,E;for(F in this.config){E=this.config[F];if(E&&E.event){D[F]=E.value;}}return D;},getProperty:function(D){var E=this.config[D.toLowerCase()];if(E&&E.event){return E.value;}else{return undefined;}},resetProperty:function(D){D=D.toLowerCase();var E=this.config[D];if(E&&E.event){if(this.initialConfig[D]&&!B.isUndefined(this.initialConfig[D])){this.setProperty(D,this.initialConfig[D]);return true;}}else{return false;}},setProperty:function(E,G,D){var F;E=E.toLowerCase();if(this.queueInProgress&&!D){this.queueProperty(E,G);return true;}else{F=this.config[E];if(F&&F.event){if(F.validator&&!F.validator(G)){return false;}else{F.value=G;if(!D){this.fireEvent(E,G);this.configChangedEvent.fire([E,G]);}return true;}}else{return false;}}},queueProperty:function(S,P){S=S.toLowerCase();var R=this.config[S],K=false,J,G,H,I,O,Q,F,M,N,D,L,T,E;if(R&&R.event){if(!B.isUndefined(P)&&R.validator&&!R.validator(P)){return false;}else{if(!B.isUndefined(P)){R.value=P;}else{P=R.value;}K=false;J=this.eventQueue.length;for(L=0;L0){G=F-1;do{D=E.subscribers[G];if(D&&D.obj==I&&D.fn==H){return true;}}while(G--);}return false;};YAHOO.lang.augmentProto(A,YAHOO.util.EventProvider);}());(function(){YAHOO.widget.Module=function(Q,P){if(Q){this.init(Q,P);}else{}};var F=YAHOO.util.Dom,D=YAHOO.util.Config,M=YAHOO.util.Event,L=YAHOO.util.CustomEvent,G=YAHOO.widget.Module,H,O,N,E,A={"BEFORE_INIT":"beforeInit","INIT":"init","APPEND":"append","BEFORE_RENDER":"beforeRender","RENDER":"render","CHANGE_HEADER":"changeHeader","CHANGE_BODY":"changeBody","CHANGE_FOOTER":"changeFooter","CHANGE_CONTENT":"changeContent","DESTORY":"destroy","BEFORE_SHOW":"beforeShow","SHOW":"show","BEFORE_HIDE":"beforeHide","HIDE":"hide"},I={"VISIBLE":{key:"visible",value:true,validator:YAHOO.lang.isBoolean},"EFFECT":{key:"effect",suppressEvent:true,supercedes:["visible"]},"MONITOR_RESIZE":{key:"monitorresize",value:true},"APPEND_TO_DOCUMENT_BODY":{key:"appendtodocumentbody",value:false}};G.IMG_ROOT=null;G.IMG_ROOT_SSL=null;G.CSS_MODULE="yui-module";G.CSS_HEADER="hd";G.CSS_BODY="bd";G.CSS_FOOTER="ft";G.RESIZE_MONITOR_SECURE_URL="javascript:false;";G.textResizeEvent=new L("textResize");function K(){if(!H){H=document.createElement("div");H.innerHTML=("
");O=H.firstChild;N=O.nextSibling;E=N.nextSibling;}return H;}function J(){if(!O){K();}return(O.cloneNode(false));}function B(){if(!N){K();}return(N.cloneNode(false));}function C(){if(!E){K();}return(E.cloneNode(false));}G.prototype={constructor:G,element:null,header:null,body:null,footer:null,id:null,imageRoot:G.IMG_ROOT,initEvents:function(){var P=L.LIST;this.beforeInitEvent=this.createEvent(A.BEFORE_INIT);this.beforeInitEvent.signature=P;this.initEvent=this.createEvent(A.INIT);this.initEvent.signature=P;this.appendEvent=this.createEvent(A.APPEND);this.appendEvent.signature=P;this.beforeRenderEvent=this.createEvent(A.BEFORE_RENDER);this.beforeRenderEvent.signature=P;this.renderEvent=this.createEvent(A.RENDER);this.renderEvent.signature=P;this.changeHeaderEvent=this.createEvent(A.CHANGE_HEADER);this.changeHeaderEvent.signature=P;this.changeBodyEvent=this.createEvent(A.CHANGE_BODY);this.changeBodyEvent.signature=P;this.changeFooterEvent=this.createEvent(A.CHANGE_FOOTER);this.changeFooterEvent.signature=P;this.changeContentEvent=this.createEvent(A.CHANGE_CONTENT);this.changeContentEvent.signature=P;this.destroyEvent=this.createEvent(A.DESTORY);this.destroyEvent.signature=P;this.beforeShowEvent=this.createEvent(A.BEFORE_SHOW);this.beforeShowEvent.signature=P;this.showEvent=this.createEvent(A.SHOW);this.showEvent.signature=P;this.beforeHideEvent=this.createEvent(A.BEFORE_HIDE);this.beforeHideEvent.signature=P;this.hideEvent=this.createEvent(A.HIDE);this.hideEvent.signature=P;},platform:function(){var P=navigator.userAgent.toLowerCase();if(P.indexOf("windows")!=-1||P.indexOf("win32")!=-1){return"windows";}else{if(P.indexOf("macintosh")!=-1){return"mac";}else{return false;}}}(),browser:function(){var P=navigator.userAgent.toLowerCase();if(P.indexOf("opera")!=-1){return"opera";}else{if(P.indexOf("msie 7")!=-1){return"ie7";}else{if(P.indexOf("msie")!=-1){return"ie";}else{if(P.indexOf("safari")!=-1){return"safari";}else{if(P.indexOf("gecko")!=-1){return"gecko";}else{return false;}}}}}}(),isSecure:function(){if(window.location.href.toLowerCase().indexOf("https")===0){return true;}else{return false;}}(),initDefaultConfig:function(){this.cfg.addProperty(I.VISIBLE.key,{handler:this.configVisible,value:I.VISIBLE.value,validator:I.VISIBLE.validator});this.cfg.addProperty(I.EFFECT.key,{suppressEvent:I.EFFECT.suppressEvent,supercedes:I.EFFECT.supercedes});this.cfg.addProperty(I.MONITOR_RESIZE.key,{handler:this.configMonitorResize,value:I.MONITOR_RESIZE.value});this.cfg.addProperty(I.APPEND_TO_DOCUMENT_BODY.key,{value:I.APPEND_TO_DOCUMENT_BODY.value});},init:function(V,U){var R,T,W;this.initEvents();this.beforeInitEvent.fire(G);this.cfg=new D(this);if(this.isSecure){this.imageRoot=G.IMG_ROOT_SSL;}if(typeof V=="string"){R=V;V=document.getElementById(V);if(!V){V=(K()).cloneNode(false);V.id=R;}}this.element=V;if(V.id){this.id=V.id;}W=this.element.firstChild;if(W){var Q=false,P=false,S=false;do{if(1==W.nodeType){if(!Q&&F.hasClass(W,G.CSS_HEADER)){this.header=W;Q=true;}else{if(!P&&F.hasClass(W,G.CSS_BODY)){this.body=W;P=true;}else{if(!S&&F.hasClass(W,G.CSS_FOOTER)){this.footer=W;S=true;}}}}}while((W=W.nextSibling));}this.initDefaultConfig();F.addClass(this.element,G.CSS_MODULE);if(U){this.cfg.applyConfig(U,true);}if(!D.alreadySubscribed(this.renderEvent,this.cfg.fireQueue,this.cfg)){this.renderEvent.subscribe(this.cfg.fireQueue,this.cfg,true);}this.initEvent.fire(G);},initResizeMonitor:function(){var P,Q,S;function T(){G.textResizeEvent.fire();}if(!YAHOO.env.ua.opera){Q=F.get("_yuiResizeMonitor");if(!Q){Q=document.createElement("iframe");if(this.isSecure&&G.RESIZE_MONITOR_SECURE_URL&&YAHOO.env.ua.ie){Q.src=G.RESIZE_MONITOR_SECURE_URL;}if(YAHOO.env.ua.gecko){S="";Q.src="data:text/html;charset=utf-8,"+encodeURIComponent(S);}Q.id="_yuiResizeMonitor";Q.style.position="absolute";Q.style.visibility="hidden";var R=document.body.firstChild;if(R){document.body.insertBefore(Q,R);}else{document.body.appendChild(Q);}Q.style.width="10em";Q.style.height="10em";Q.style.top=(-1*Q.offsetHeight)+"px";Q.style.left=(-1*Q.offsetWidth)+"px";Q.style.borderWidth="0";Q.style.visibility="visible";if(YAHOO.env.ua.webkit){P=Q.contentWindow.document;P.open();P.close();}}if(Q&&Q.contentWindow){G.textResizeEvent.subscribe(this.onDomResize,this,true);if(!G.textResizeInitialized){if(!M.on(Q.contentWindow,"resize",T)){M.on(Q,"resize",T);}G.textResizeInitialized=true;}this.resizeMonitor=Q;}}},onDomResize:function(S,R){var Q=-1*this.resizeMonitor.offsetWidth,P=-1*this.resizeMonitor.offsetHeight;this.resizeMonitor.style.top=P+"px";this.resizeMonitor.style.left=Q+"px";},setHeader:function(Q){var P=this.header||(this.header=J());if(typeof Q=="string"){P.innerHTML=Q;}else{P.innerHTML="";P.appendChild(Q);}this.changeHeaderEvent.fire(Q);this.changeContentEvent.fire();},appendToHeader:function(Q){var P=this.header||(this.header=J());P.appendChild(Q);this.changeHeaderEvent.fire(Q);this.changeContentEvent.fire();},setBody:function(Q){var P=this.body||(this.body=B());if(typeof Q=="string"){P.innerHTML=Q;}else{P.innerHTML="";P.appendChild(Q);}this.changeBodyEvent.fire(Q);this.changeContentEvent.fire();},appendToBody:function(Q){var P=this.body||(this.body=B());P.appendChild(Q);this.changeBodyEvent.fire(Q);this.changeContentEvent.fire();},setFooter:function(Q){var P=this.footer||(this.footer=C());if(typeof Q=="string"){P.innerHTML=Q;}else{P.innerHTML="";P.appendChild(Q);}this.changeFooterEvent.fire(Q);this.changeContentEvent.fire();},appendToFooter:function(Q){var P=this.footer||(this.footer=C());P.appendChild(Q);this.changeFooterEvent.fire(Q);this.changeContentEvent.fire();},render:function(R,P){var S=this,T;function Q(U){if(typeof U=="string"){U=document.getElementById(U);}if(U){S._addToParent(U,S.element);S.appendEvent.fire();}}this.beforeRenderEvent.fire();if(!P){P=this.element;}if(R){Q(R);}else{if(!F.inDocument(this.element)){return false;}}if(this.header&&!F.inDocument(this.header)){T=P.firstChild;if(T){P.insertBefore(this.header,T);}else{P.appendChild(this.header);}}if(this.body&&!F.inDocument(this.body)){if(this.footer&&F.isAncestor(this.moduleElement,this.footer)){P.insertBefore(this.body,this.footer);}else{P.appendChild(this.body);}}if(this.footer&&!F.inDocument(this.footer)){P.appendChild(this.footer);}this.renderEvent.fire();return true;},destroy:function(){var P,Q;if(this.element){M.purgeElement(this.element,true);P=this.element.parentNode;}if(P){P.removeChild(this.element);}this.element=null;this.header=null;this.body=null;this.footer=null;G.textResizeEvent.unsubscribe(this.onDomResize,this);this.cfg.destroy();this.cfg=null;this.destroyEvent.fire();for(Q in this){if(Q instanceof L){Q.unsubscribeAll();}}},show:function(){this.cfg.setProperty("visible",true);},hide:function(){this.cfg.setProperty("visible",false);},configVisible:function(Q,P,R){var S=P[0];if(S){this.beforeShowEvent.fire();F.setStyle(this.element,"display","block");this.showEvent.fire();}else{this.beforeHideEvent.fire();F.setStyle(this.element,"display","none");this.hideEvent.fire();}},configMonitorResize:function(R,Q,S){var P=Q[0];if(P){this.initResizeMonitor();}else{G.textResizeEvent.unsubscribe(this.onDomResize,this,true);this.resizeMonitor=null;}},_addToParent:function(P,Q){if(!this.cfg.getProperty("appendtodocumentbody")&&P===document.body&&P.firstChild){P.insertBefore(Q,P.firstChild);}else{P.appendChild(Q);}},toString:function(){return"Module "+this.id;}};YAHOO.lang.augmentProto(G,YAHOO.util.EventProvider);}());(function(){YAHOO.widget.Overlay=function(L,K){YAHOO.widget.Overlay.superclass.constructor.call(this,L,K);};var F=YAHOO.lang,I=YAHOO.util.CustomEvent,E=YAHOO.widget.Module,J=YAHOO.util.Event,D=YAHOO.util.Dom,C=YAHOO.util.Config,B=YAHOO.widget.Overlay,G,A={"BEFORE_MOVE":"beforeMove","MOVE":"move"},H={"X":{key:"x",validator:F.isNumber,suppressEvent:true,supercedes:["iframe"]},"Y":{key:"y",validator:F.isNumber,suppressEvent:true,supercedes:["iframe"]},"XY":{key:"xy",suppressEvent:true,supercedes:["iframe"]},"CONTEXT":{key:"context",suppressEvent:true,supercedes:["iframe"]},"FIXED_CENTER":{key:"fixedcenter",value:false,validator:F.isBoolean,supercedes:["iframe","visible"]},"WIDTH":{key:"width",suppressEvent:true,supercedes:["context","fixedcenter","iframe"]},"HEIGHT":{key:"height",suppressEvent:true,supercedes:["context","fixedcenter","iframe"]},"ZINDEX":{key:"zindex",value:null},"CONSTRAIN_TO_VIEWPORT":{key:"constraintoviewport",value:false,validator:F.isBoolean,supercedes:["iframe","x","y","xy"]},"IFRAME":{key:"iframe",value:(YAHOO.env.ua.ie==6?true:false),validator:F.isBoolean,supercedes:["zindex"]}};B.IFRAME_SRC="javascript:false;";B.IFRAME_OFFSET=3;B.TOP_LEFT="tl";B.TOP_RIGHT="tr";B.BOTTOM_LEFT="bl";B.BOTTOM_RIGHT="br";B.CSS_OVERLAY="yui-overlay";B.windowScrollEvent=new I("windowScroll");B.windowResizeEvent=new I("windowResize");B.windowScrollHandler=function(K){if(YAHOO.env.ua.ie){if(!window.scrollEnd){window.scrollEnd=-1;}clearTimeout(window.scrollEnd);window.scrollEnd=setTimeout(function(){B.windowScrollEvent.fire();},1);}else{B.windowScrollEvent.fire();}};B.windowResizeHandler=function(K){if(YAHOO.env.ua.ie){if(!window.resizeEnd){window.resizeEnd=-1;}clearTimeout(window.resizeEnd);window.resizeEnd=setTimeout(function(){B.windowResizeEvent.fire();},100);}else{B.windowResizeEvent.fire();}};B._initialized=null;if(B._initialized===null){J.on(window,"scroll",B.windowScrollHandler);J.on(window,"resize",B.windowResizeHandler);B._initialized=true;}YAHOO.extend(B,E,{init:function(L,K){B.superclass.init.call(this,L);this.beforeInitEvent.fire(B);D.addClass(this.element,B.CSS_OVERLAY);if(K){this.cfg.applyConfig(K,true);}if(this.platform=="mac"&&YAHOO.env.ua.gecko){if(!C.alreadySubscribed(this.showEvent,this.showMacGeckoScrollbars,this)){this.showEvent.subscribe(this.showMacGeckoScrollbars,this,true);}if(!C.alreadySubscribed(this.hideEvent,this.hideMacGeckoScrollbars,this)){this.hideEvent.subscribe(this.hideMacGeckoScrollbars,this,true);}}this.initEvent.fire(B);},initEvents:function(){B.superclass.initEvents.call(this);var K=I.LIST;this.beforeMoveEvent=this.createEvent(A.BEFORE_MOVE);this.beforeMoveEvent.signature=K;this.moveEvent=this.createEvent(A.MOVE);this.moveEvent.signature=K;},initDefaultConfig:function(){B.superclass.initDefaultConfig.call(this);this.cfg.addProperty(H.X.key,{handler:this.configX,validator:H.X.validator,suppressEvent:H.X.suppressEvent,supercedes:H.X.supercedes});this.cfg.addProperty(H.Y.key,{handler:this.configY,validator:H.Y.validator,suppressEvent:H.Y.suppressEvent,supercedes:H.Y.supercedes});this.cfg.addProperty(H.XY.key,{handler:this.configXY,suppressEvent:H.XY.suppressEvent,supercedes:H.XY.supercedes});this.cfg.addProperty(H.CONTEXT.key,{handler:this.configContext,suppressEvent:H.CONTEXT.suppressEvent,supercedes:H.CONTEXT.supercedes});this.cfg.addProperty(H.FIXED_CENTER.key,{handler:this.configFixedCenter,value:H.FIXED_CENTER.value,validator:H.FIXED_CENTER.validator,supercedes:H.FIXED_CENTER.supercedes});this.cfg.addProperty(H.WIDTH.key,{handler:this.configWidth,suppressEvent:H.WIDTH.suppressEvent,supercedes:H.WIDTH.supercedes});this.cfg.addProperty(H.HEIGHT.key,{handler:this.configHeight,suppressEvent:H.HEIGHT.suppressEvent,supercedes:H.HEIGHT.supercedes});this.cfg.addProperty(H.ZINDEX.key,{handler:this.configzIndex,value:H.ZINDEX.value});this.cfg.addProperty(H.CONSTRAIN_TO_VIEWPORT.key,{handler:this.configConstrainToViewport,value:H.CONSTRAIN_TO_VIEWPORT.value,validator:H.CONSTRAIN_TO_VIEWPORT.validator,supercedes:H.CONSTRAIN_TO_VIEWPORT.supercedes});this.cfg.addProperty(H.IFRAME.key,{handler:this.configIframe,value:H.IFRAME.value,validator:H.IFRAME.validator,supercedes:H.IFRAME.supercedes});},moveTo:function(K,L){this.cfg.setProperty("xy",[K,L]);},hideMacGeckoScrollbars:function(){D.removeClass(this.element,"show-scrollbars");D.addClass(this.element,"hide-scrollbars");},showMacGeckoScrollbars:function(){D.removeClass(this.element,"hide-scrollbars");D.addClass(this.element,"show-scrollbars");},configVisible:function(N,K,T){var M=K[0],O=D.getStyle(this.element,"visibility"),U=this.cfg.getProperty("effect"),R=[],Q=(this.platform=="mac"&&YAHOO.env.ua.gecko),b=C.alreadySubscribed,S,L,a,Y,X,W,Z,V,P;if(O=="inherit"){a=this.element.parentNode;while(a.nodeType!=9&&a.nodeType!=11){O=D.getStyle(a,"visibility");if(O!="inherit"){break;}a=a.parentNode;}if(O=="inherit"){O="visible";}}if(U){if(U instanceof Array){V=U.length;for(Y=0;YY){W=Y;}}if(VK){V=K;}}this.cfg.setProperty("x",W,true);this.cfg.setProperty("y",V,true);this.cfg.setProperty("xy",[W,V],true);},center:function(){var Q=D.getDocumentScrollLeft(),O=D.getDocumentScrollTop(),L=D.getClientWidth(),P=D.getClientHeight(),N=this.element.offsetWidth,M=this.element.offsetHeight,K=(L/2)-(N/2)+Q,R=(P/2)-(M/2)+O;this.cfg.setProperty("xy",[parseInt(K,10),parseInt(R,10)]);this.cfg.refireEvent("iframe");},syncPosition:function(){var K=D.getXY(this.element);this.cfg.setProperty("x",K[0],true);this.cfg.setProperty("y",K[1],true);this.cfg.setProperty("xy",K,true);},onDomResize:function(M,L){var K=this;B.superclass.onDomResize.call(this,M,L);setTimeout(function(){K.syncPosition();K.cfg.refireEvent("iframe");K.cfg.refireEvent("context");},0);},bringToTop:function(){var N=[],M=this.element;function P(T,S){var V=D.getStyle(T,"zIndex"),U=D.getStyle(S,"zIndex"),R=(!V||isNaN(V))?0:parseInt(V,10),Q=(!U||isNaN(U))?0:parseInt(U,10);if(R>Q){return-1;}else{if(R0){J=K-1;do{this.overlays[J].blur();}while(J--);}};this._onOverlayBlur=function(K,J){H=null;};var G=this.cfg.getProperty("overlays");if(!this.overlays){this.overlays=[];}if(G){this.register(G);this.overlays.sort(this.compareZIndexDesc);}},_onOverlayElementFocus:function(I){var G=C.getTarget(I),H=this.close;if(H&&(G==H||E.isAncestor(H,G))){this.blur();}else{this.focus();}},_onOverlayDestroy:function(H,G,I){this.remove(I);},register:function(G){var K=this,L,I,H,J;if(G instanceof D){G.cfg.addProperty("manager",{value:this});G.focusEvent=G.createEvent("focus");G.focusEvent.signature=F.LIST;G.blurEvent=G.createEvent("blur");G.blurEvent.signature=F.LIST;G.focus=function(){K.focus(this);};G.blur=function(){if(K.getActive()==this){E.removeClass(this.element,A.CSS_FOCUSED);this.blurEvent.fire();}};G.blurEvent.subscribe(K._onOverlayBlur);G.hideEvent.subscribe(G.blur);G.destroyEvent.subscribe(this._onOverlayDestroy,G,this);C.on(G.element,this.cfg.getProperty("focusevent"),this._onOverlayElementFocus,null,G);L=E.getStyle(G.element,"zIndex");if(!isNaN(L)){G.cfg.setProperty("zIndex",parseInt(L,10));}else{G.cfg.setProperty("zIndex",0);}this.overlays.push(G);this.bringToTop(G);return true;}else{if(G instanceof Array){I=0;J=G.length;for(H=0;H0){return true;}}else{return false;}}},bringToTop:function(K){var H=this.find(K),J,G,I;if(H){I=this.overlays;I.sort(this.compareZIndexDesc);G=I[0];if(G){J=E.getStyle(G.element,"zIndex");if(!isNaN(J)&&G!=H){H.cfg.setProperty("zIndex",(parseInt(J,10)+2));}I.sort(this.compareZIndexDesc);}}},find:function(G){var I=this.overlays,J=I.length,H;if(J>0){H=J-1;if(G instanceof D){do{if(I[H]==G){return I[H];}}while(H--);}else{if(typeof G=="string"){do{if(I[H].id==G){return I[H];}}while(H--);}}return null;}},compareZIndexDesc:function(J,I){var H=(J.cfg)?J.cfg.getProperty("zIndex"):null,G=(I.cfg)?I.cfg.getProperty("zIndex"):null;if(H===null&&G===null){return 0;}else{if(H===null){return 1;}else{if(G===null){return-1;}else{if(H>G){return-1;}else{if(H0){G=I-1;do{H[G].show();}while(G--);}},hideAll:function(){var H=this.overlays,I=H.length,G;if(I>0){G=I-1;do{H[G].hide();}while(G--);}},toString:function(){return"OverlayManager";}};}());(function(){YAHOO.widget.Tooltip=function(L,K){YAHOO.widget.Tooltip.superclass.constructor.call(this,L,K);};var D=YAHOO.lang,J=YAHOO.util.Event,B=YAHOO.util.Dom,F=YAHOO.widget.Tooltip,E,G={"PREVENT_OVERLAP":{key:"preventoverlap",value:true,validator:D.isBoolean,supercedes:["x","y","xy"]},"SHOW_DELAY":{key:"showdelay",value:200,validator:D.isNumber},"AUTO_DISMISS_DELAY":{key:"autodismissdelay",value:5000,validator:D.isNumber},"HIDE_DELAY":{key:"hidedelay",value:250,validator:D.isNumber},"TEXT":{key:"text",suppressEvent:true},"CONTAINER":{key:"container"}};F.CSS_TOOLTIP="yui-tt";function H(L,K,M){var P=M[0],N=M[1],O=this.cfg,Q=O.getProperty("width");if(Q==N){O.setProperty("width",P);}this.unsubscribe("hide",this._onHide,M);}function C(L,K){var M=document.body,Q=this.cfg,P=Q.getProperty("width"),N,O;if((!P||P=="auto")&&(Q.getProperty("container")!=M||Q.getProperty("x")>=B.getViewportWidth()||Q.getProperty("y")>=B.getViewportHeight())){O=this.element.cloneNode(true);O.style.visibility="hidden";O.style.top="0px";O.style.left="0px";M.appendChild(O);N=(O.offsetWidth+"px");M.removeChild(O);O=null;Q.setProperty("width",N);Q.refireEvent("xy");this.subscribe("hide",H,[(P||""),N]);}}function A(L,K,M){this.render(M);}function I(){J.onDOMReady(A,this.cfg.getProperty("container"),this);}YAHOO.extend(F,YAHOO.widget.Overlay,{init:function(L,K){F.superclass.init.call(this,L);this.beforeInitEvent.fire(F);B.addClass(this.element,F.CSS_TOOLTIP);if(K){this.cfg.applyConfig(K,true);}this.cfg.queueProperty("visible",false);this.cfg.queueProperty("constraintoviewport",true);this.setBody("");this.subscribe("beforeShow",C);this.subscribe("init",I);this.subscribe("render",this.onRender);this.initEvent.fire(F);},initDefaultConfig:function(){F.superclass.initDefaultConfig.call(this);this.cfg.addProperty(G.PREVENT_OVERLAP.key,{value:G.PREVENT_OVERLAP.value,validator:G.PREVENT_OVERLAP.validator,supercedes:G.PREVENT_OVERLAP.supercedes});this.cfg.addProperty(G.SHOW_DELAY.key,{handler:this.configShowDelay,value:200,validator:G.SHOW_DELAY.validator});this.cfg.addProperty(G.AUTO_DISMISS_DELAY.key,{handler:this.configAutoDismissDelay,value:G.AUTO_DISMISS_DELAY.value,validator:G.AUTO_DISMISS_DELAY.validator});this.cfg.addProperty(G.HIDE_DELAY.key,{handler:this.configHideDelay,value:G.HIDE_DELAY.value,validator:G.HIDE_DELAY.validator});this.cfg.addProperty(G.TEXT.key,{handler:this.configText,suppressEvent:G.TEXT.suppressEvent});this.cfg.addProperty(G.CONTAINER.key,{handler:this.configContainer,value:document.body});},configText:function(L,K,M){var N=K[0];if(N){this.setBody(N);}},configContainer:function(M,L,N){var K=L[0];if(typeof K=="string"){this.cfg.setProperty("container",document.getElementById(K),true);}},_removeEventListeners:function(){var N=this._context,K,M,L;if(N){K=N.length;if(K>0){L=K-1;do{M=N[L];J.removeListener(M,"mouseover",this.onContextMouseOver);J.removeListener(M,"mousemove",this.onContextMouseMove);J.removeListener(M,"mouseout",this.onContextMouseOut);}while(L--);}}},configContext:function(P,L,Q){var O=L[0],R,K,N,M;if(O){if(!(O instanceof Array)){if(typeof O=="string"){this.cfg.setProperty("context",[document.getElementById(O)],true);}else{this.cfg.setProperty("context",[O],true);}O=this.cfg.getProperty("context");}this._removeEventListeners();this._context=O;R=this._context;if(R){K=R.length;if(K>0){M=K-1;do{N=R[M];J.on(N,"mouseover",this.onContextMouseOver,this);J.on(N,"mousemove",this.onContextMouseMove,this);J.on(N,"mouseout",this.onContextMouseOut,this);}while(M--);}}}},onContextMouseMove:function(L,K){K.pageX=J.getPageX(L);K.pageY=J.getPageY(L);},onContextMouseOver:function(M,L){var K=this;if(L.hideProcId){clearTimeout(L.hideProcId);L.hideProcId=null;}J.on(K,"mousemove",L.onContextMouseMove,L);if(K.title){L._tempTitle=K.title;K.title="";}L.showProcId=L.doShow(M,K);},onContextMouseOut:function(M,L){var K=this;if(L._tempTitle){K.title=L._tempTitle;L._tempTitle=null;}if(L.showProcId){clearTimeout(L.showProcId);L.showProcId=null;}if(L.hideProcId){clearTimeout(L.hideProcId);L.hideProcId=null;}L.hideProcId=setTimeout(function(){L.hide();},L.cfg.getProperty("hidedelay"));},doShow:function(M,K){var N=25,L=this;if(YAHOO.env.ua.opera&&K.tagName&&K.tagName.toUpperCase()=="A"){N+=12;}return setTimeout(function(){if(L._tempTitle){L.setBody(L._tempTitle);}else{L.cfg.refireEvent("text");}L.moveTo(L.pageX,L.pageY+N);if(L.cfg.getProperty("preventoverlap")){L.preventOverlap(L.pageX,L.pageY);}J.removeListener(K,"mousemove",L.onContextMouseMove);L.show();L.hideProcId=L.doHide();},this.cfg.getProperty("showdelay"));},doHide:function(){var K=this;return setTimeout(function(){K.hide();},this.cfg.getProperty("autodismissdelay"));},preventOverlap:function(O,N){var K=this.element.offsetHeight,M=new YAHOO.util.Point(O,N),L=B.getRegion(this.element);L.top-=5;L.left-=5;L.right+=5;L.bottom+=5;if(L.contains(M)){this.cfg.setProperty("y",(N-K-5));}},onRender:function(O,N){function P(){var S=this.element,R=this._shadow;if(R){R.style.width=(S.offsetWidth+6)+"px";R.style.height=(S.offsetHeight+1)+"px";}}function L(){B.addClass(this._shadow,"yui-tt-shadow-visible");}function K(){B.removeClass(this._shadow,"yui-tt-shadow-visible");}function Q(){var T=this._shadow,S,R,V,U;if(!T){S=this.element;R=YAHOO.widget.Module;V=YAHOO.env.ua.ie;U=this;if(!E){E=document.createElement("div");E.className="yui-tt-shadow";}T=E.cloneNode(false);S.appendChild(T);this._shadow=T;L.call(this);this.subscribe("beforeShow",L);this.subscribe("beforeHide",K);if(V==6||(V==7&&document.compatMode=="BackCompat")){window.setTimeout(function(){P.call(U);},0);this.cfg.subscribeToConfigEvent("width",P);this.cfg.subscribeToConfigEvent("height",P);this.subscribe("changeContent",P);R.textResizeEvent.subscribe(P,this,true);this.subscribe("destroy",function(){R.textResizeEvent.unsubscribe(P,this);});}}}function M(){Q.call(this);this.unsubscribe("beforeShow",M);}if(this.cfg.getProperty("visible")){Q.call(this);}else{this.subscribe("beforeShow",M);}},destroy:function(){this._removeEventListeners();F.superclass.destroy.call(this);},toString:function(){return"Tooltip "+this.id;}});}());(function(){YAHOO.widget.Panel=function(U,T){YAHOO.widget.Panel.superclass.constructor.call(this,U,T);};var G=YAHOO.lang,N=YAHOO.util.DD,A=YAHOO.util.Dom,S=YAHOO.util.Event,I=YAHOO.widget.Overlay,L=YAHOO.util.CustomEvent,J=YAHOO.util.Config,O=YAHOO.widget.Panel,H,Q,D,E={"SHOW_MASK":"showMask","HIDE_MASK":"hideMask","DRAG":"drag"},M={"CLOSE":{key:"close",value:true,validator:G.isBoolean,supercedes:["visible"]},"DRAGGABLE":{key:"draggable",value:(N?true:false),validator:G.isBoolean,supercedes:["visible"]},"UNDERLAY":{key:"underlay",value:"shadow",supercedes:["visible"]},"MODAL":{key:"modal",value:false,validator:G.isBoolean,supercedes:["visible","zindex"]},"KEY_LISTENERS":{key:"keylisteners",suppressEvent:true,supercedes:["visible"]}};O.CSS_PANEL="yui-panel";O.CSS_PANEL_CONTAINER="yui-panel-container";function K(U,T){if(!this.header){this.setHeader(" ");}}function R(U,T,V){var Y=V[0],W=V[1],X=this.cfg,Z=X.getProperty("width");if(Z==W){X.setProperty("width",Y);}this.unsubscribe("hide",R,V);}function C(U,T){var Y=YAHOO.env.ua.ie,X,W,V;if(Y==6||(Y==7&&document.compatMode=="BackCompat")){X=this.cfg;W=X.getProperty("width");if(!W||W=="auto"){V=(this.element.offsetWidth+"px");X.setProperty("width",V);this.subscribe("hide",R,[(W||""),V]);}}}function F(){this.blur();}function P(V,U){var W=this;function T(Z){var Y=Z.tagName.toUpperCase(),X=false;switch(Y){case"A":case"BUTTON":case"SELECT":case"TEXTAREA":if(!A.isAncestor(W.element,Z)){S.on(Z,"focus",F,Z,true);X=true;}break;case"INPUT":if(Z.type!="hidden"&&!A.isAncestor(W.element,Z)){S.on(Z,"focus",F,Z,true);X=true;}break;}return X;}this.focusableElements=A.getElementsBy(T);}function B(V,U){var Y=this.focusableElements,T=Y.length,W,X;for(X=0;X0){K=L-1;do{M=N[K];if(YAHOO.widget.Button&&M instanceof YAHOO.widget.Button){M.destroy();}else{if(M.tagName.toUpperCase()=="BUTTON"){J.purgeElement(M);J.purgeElement(M,false);}}}while(K--);}}}YAHOO.extend(F,YAHOO.widget.Panel,{form:null,initDefaultConfig:function(){F.superclass.initDefaultConfig.call(this);this.callback={success:null,failure:null,argument:null};this.cfg.addProperty(G.POST_METHOD.key,{handler:this.configPostMethod,value:G.POST_METHOD.value,validator:function(K){if(K!="form"&&K!="async"&&K!="none"&&K!="manual"){return false;}else{return true;}}});this.cfg.addProperty(G.BUTTONS.key,{handler:this.configButtons,value:G.BUTTONS.value});},initEvents:function(){F.superclass.initEvents.call(this);var K=I.LIST;this.beforeSubmitEvent=this.createEvent(A.BEFORE_SUBMIT);this.beforeSubmitEvent.signature=K;this.submitEvent=this.createEvent(A.SUBMIT);this.submitEvent.signature=K;this.manualSubmitEvent=this.createEvent(A.MANUAL_SUBMIT);this.manualSubmitEvent.signature=K;this.asyncSubmitEvent=this.createEvent(A.ASYNC_SUBMIT);this.asyncSubmitEvent.signature=K;this.formSubmitEvent=this.createEvent(A.FORM_SUBMIT);this.formSubmitEvent.signature=K;this.cancelEvent=this.createEvent(A.CANCEL);this.cancelEvent.signature=K;},init:function(L,K){F.superclass.init.call(this,L);this.beforeInitEvent.fire(F);D.addClass(this.element,F.CSS_DIALOG);this.cfg.setProperty("visible",false);if(K){this.cfg.applyConfig(K,true);}this.showEvent.subscribe(this.focusFirst,this,true);this.beforeHideEvent.subscribe(this.blurButtons,this,true);this.subscribe("changeBody",this.registerForm);this.initEvent.fire(F);},doSubmit:function(){var Q=this.form,O=false,N=false,P,K,M,L;switch(this.cfg.getProperty("postmethod")){case"async":P=Q.elements;K=P.length;if(K>0){M=K-1;do{if(P[M].type=="file"){O=true;break;}}while(M--);}if(O&&YAHOO.env.ua.ie&&this.isSecure){N=true;}L=(Q.getAttribute("method")||"POST").toUpperCase();H.setForm(Q,O,N);H.asyncRequest(L,Q.getAttribute("action"),this.callback);this.asyncSubmitEvent.fire();break;case"form":Q.submit();this.formSubmitEvent.fire();break;case"none":case"manual":this.manualSubmitEvent.fire();break;}},registerForm:function(){var M=this.element.getElementsByTagName("form")[0],L=this,K,N;if(this.form){if(this.form==M&&D.isAncestor(this.element,this.form)){return;}else{J.purgeElement(this.form);this.form=null;}}if(!M){M=document.createElement("form");M.name="frm_"+this.id;this.body.appendChild(M);}if(M){this.form=M;J.on(M,"submit",function(O){J.stopEvent(O);this.submit();this.form.blur();},this,true);this.firstFormElement=function(){var Q,P,O=M.elements.length;for(Q=0;Q=0;Q--){P=M.elements[Q];if(P.focus&&!P.disabled&&P.type!="hidden"){return P;}}return null;}();if(this.cfg.getProperty("modal")){K=this.firstFormElement||this.firstButton;if(K){this.preventBackTab=new B(K,{shift:true,keys:9},{fn:L.focusLast,scope:L,correctScope:true});this.showEvent.subscribe(this.preventBackTab.enable,this.preventBackTab,true);this.hideEvent.subscribe(this.preventBackTab.disable,this.preventBackTab,true);}N=this.lastButton||this.lastFormElement;if(N){this.preventTabOut=new B(N,{shift:false,keys:9},{fn:L.focusFirst,scope:L,correctScope:true});this.showEvent.subscribe(this.preventTabOut.enable,this.preventTabOut,true);this.hideEvent.subscribe(this.preventTabOut.disable,this.preventTabOut,true);}}}},configClose:function(M,K,N){var O=K[0];function L(Q,P){P.cancel();}if(O){if(!this.close){this.close=document.createElement("div");D.addClass(this.close,"container-close");this.close.innerHTML=" ";this.innerElement.appendChild(this.close);J.on(this.close,"click",L,this);}else{this.close.style.display="block";}}else{if(this.close){this.close.style.display="none";}}},configButtons:function(U,T,O){var P=YAHOO.widget.Button,W=T[0],M=this.innerElement,V,R,L,S,Q,K,N;C.call(this);this._aButtons=null;if(E.isArray(W)){Q=document.createElement("span");Q.className="button-group";S=W.length;this._aButtons=[];for(N=0;N0){K=(M-1);do{O=P[K];if(O){L=O.htmlButton;if(L){try{L.blur();}catch(N){}}}}while(K--);}}},focusFirstButton:function(){var N=this.cfg.getProperty("buttons"),M,K;if(N&&E.isArray(N)){M=N[0];if(M){K=M.htmlButton;if(K){try{K.focus();}catch(L){}}}}},focusLastButton:function(){var O=this.cfg.getProperty("buttons"),L,N,K;if(O&&E.isArray(O)){L=O.length;if(L>0){N=O[(L-1)];if(N){K=N.htmlButton;if(K){try{K.focus();}catch(M){}}}}}},configPostMethod:function(M,L,N){var K=L[0];this.registerForm();},validate:function(){return true;},submit:function(){if(this.validate()){this.beforeSubmitEvent.fire();this.doSubmit();this.submitEvent.fire();this.hide();return true;}else{return false;}},cancel:function(){this.cancelEvent.fire();this.hide();},getData:function(){var a=this.form,M,T,W,O,U,R,Q,L,X,N,Y,b,K,P,c,Z,V;function S(e){var d=e.tagName.toUpperCase();return((d=="INPUT"||d=="TEXTAREA"||d=="SELECT")&&e.name==O);}if(a){M=a.elements;T=M.length;W={};for(Z=0;Z0){if(R==1){U=U[0];Q=U.type;L=U.tagName.toUpperCase();switch(L){case"INPUT":if(Q=="checkbox"){W[O]=U.checked;}else{if(Q!="radio"){W[O]=U.value;}}break;case"TEXTAREA":W[O]=U.value;break;case"SELECT":X=U.options;N=X.length;Y=[];for(V=0;V0){L=K[0];if(L){J.purgeElement(L);if(L.parentNode){L.parentNode.removeChild(L);}this.form=null;}}F.superclass.destroy.call(this);},toString:function(){return"Dialog "+this.id;}});}());(function(){YAHOO.widget.SimpleDialog=function(E,D){YAHOO.widget.SimpleDialog.superclass.constructor.call(this,E,D);};var C=YAHOO.util.Dom,B=YAHOO.widget.SimpleDialog,A={"ICON":{key:"icon",value:"none",suppressEvent:true},"TEXT":{key:"text",value:"",suppressEvent:true,supercedes:["icon"]}};B.ICON_BLOCK="blckicon";B.ICON_ALARM="alrticon";B.ICON_HELP="hlpicon";B.ICON_INFO="infoicon";B.ICON_WARN="warnicon";B.ICON_TIP="tipicon";B.ICON_CSS_CLASSNAME="yui-icon";B.CSS_SIMPLEDIALOG="yui-simple-dialog";YAHOO.extend(B,YAHOO.widget.Dialog,{initDefaultConfig:function(){B.superclass.initDefaultConfig.call(this);this.cfg.addProperty(A.ICON.key,{handler:this.configIcon,value:A.ICON.value,suppressEvent:A.ICON.suppressEvent});this.cfg.addProperty(A.TEXT.key,{handler:this.configText,value:A.TEXT.value,suppressEvent:A.TEXT.suppressEvent,supercedes:A.TEXT.supercedes});},init:function(E,D){B.superclass.init.call(this,E);this.beforeInitEvent.fire(B);C.addClass(this.element,B.CSS_SIMPLEDIALOG);this.cfg.queueProperty("postmethod","manual");if(D){this.cfg.applyConfig(D,true);}this.beforeRenderEvent.subscribe(function(){if(!this.body){this.setBody("");}},this,true);this.initEvent.fire(B);},registerForm:function(){B.superclass.registerForm.call(this);this.form.innerHTML+="";},configIcon:function(F,E,J){var K=E[0],D=this.body,I=B.ICON_CSS_CLASSNAME,H,G;if(K&&K!="none"){H=C.getElementsByClassName(I,"*",D);if(H){G=H.parentNode;if(G){G.removeChild(H);H=null;}}if(K.indexOf(".")==-1){H=document.createElement("span");H.className=(I+" "+K);H.innerHTML=" ";}else{H=document.createElement("img");H.src=(this.imageRoot+K);H.className=I;}if(H){D.insertBefore(H,D.firstChild);}}},configText:function(E,D,F){var G=D[0];if(G){this.setBody(G);this.cfg.refireEvent("icon");}},toString:function(){return"SimpleDialog "+this.id;}});}());(function(){YAHOO.widget.ContainerEffect=function(F,I,H,E,G){if(!G){G=YAHOO.util.Anim;}this.overlay=F;this.attrIn=I;this.attrOut=H;this.targetElement=E||F.element;this.animClass=G;};var B=YAHOO.util.Dom,D=YAHOO.util.CustomEvent,C=YAHOO.util.Easing,A=YAHOO.widget.ContainerEffect;A.FADE=function(E,F){var G=new A(E,{attributes:{opacity:{from:0,to:1}},duration:F,method:C.easeIn},{attributes:{opacity:{to:0}},duration:F,method:C.easeOut},E.element);G.handleStartAnimateIn=function(I,H,J){B.addClass(J.overlay.element,"hide-select");if(!J.overlay.underlay){J.overlay.cfg.refireEvent("underlay");}if(J.overlay.underlay){J.initialUnderlayOpacity=B.getStyle(J.overlay.underlay,"opacity");J.overlay.underlay.style.filter=null;}B.setStyle(J.overlay.element,"visibility","visible");B.setStyle(J.overlay.element,"opacity",0);};G.handleCompleteAnimateIn=function(I,H,J){B.removeClass(J.overlay.element,"hide-select");if(J.overlay.element.style.filter){J.overlay.element.style.filter=null;}if(J.overlay.underlay){B.setStyle(J.overlay.underlay,"opacity",J.initialUnderlayOpacity);}J.overlay.cfg.refireEvent("iframe");J.animateInCompleteEvent.fire();};G.handleStartAnimateOut=function(I,H,J){B.addClass(J.overlay.element,"hide-select");if(J.overlay.underlay){J.overlay.underlay.style.filter=null;}};G.handleCompleteAnimateOut=function(I,H,J){B.removeClass(J.overlay.element,"hide-select");if(J.overlay.element.style.filter){J.overlay.element.style.filter=null;}B.setStyle(J.overlay.element,"visibility","hidden");B.setStyle(J.overlay.element,"opacity",1);J.overlay.cfg.refireEvent("iframe");J.animateOutCompleteEvent.fire();};G.init();return G;};A.SLIDE=function(G,I){var F=G.cfg.getProperty("x")||B.getX(G.element),K=G.cfg.getProperty("y")||B.getY(G.element),J=B.getClientWidth(),H=G.element.offsetWidth,E=new A(G,{attributes:{points:{to:[F,K]}},duration:I,method:C.easeIn},{attributes:{points:{to:[(J+25),K]}},duration:I,method:C.easeOut},G.element,YAHOO.util.Motion);E.handleStartAnimateIn=function(M,L,N){N.overlay.element.style.left=((-25)-H)+"px";N.overlay.element.style.top=K+"px";};E.handleTweenAnimateIn=function(O,N,P){var Q=B.getXY(P.overlay.element),M=Q[0],L=Q[1];if(B.getStyle(P.overlay.element,"visibility")=="hidden"&&M. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: Filter.php 2041 2008-01-08 10:00:39Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit/Util/FilterIterator.php'; + +/** + * Utility class for code filtering. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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 + */ +class PHPUnit_Util_Filter +{ + /** + * @var boolean + * @access public + * @static + */ + public static $addUncoveredFilesFromWhitelist = TRUE; + + /** + * @var boolean + * @access public + * @static + */ + public static $filterPHPUnit = TRUE; + + /** + * @var boolean + * @access protected + * @static + */ + protected static $filter = TRUE; + + /** + * @var boolean + * @access protected + * @static + */ + protected static $blackListConverstionForWindowsDone = FALSE; + + /** + * Source files that are blacklisted. + * + * @var array + * @access protected + * @static + */ + protected static $blacklistedFiles = array( + 'DEFAULT' => array(), + 'PHPUNIT' => array(), + 'TESTS' => array(), + 'PEAR' => array( + 'Console/Getopt.php', + 'Image/GraphViz.php', + 'Log/composite.php', + 'Log/console.php', + 'Log/daemon.php', + 'Log/display.php', + 'Log/error_log.php', + 'Log/file.php', + 'Log/mail.php', + 'Log/mcal.php', + 'Log/mdb2.php', + 'Log/null.php', + 'Log/observer.php', + 'Log/sql.php', + 'Log/sqlite.php', + 'Log/syslog.php', + 'Log/win.php', + 'Log.php', + 'PEAR/Installer/Role/Common.php', + 'PEAR/Installer/Role.php', + 'PEAR/Config.php', + 'PEAR/DependencyDB.php', + 'PEAR/Registry.php', + 'PEAR/Remote.php', + 'PEAR/RunTest.php', + 'PEAR/XMLParser.php', + 'PEAR.php', + 'System.php' + ) + ); + + /** + * Source files that are whitelisted. + * + * @var array + * @access protected + * @static + */ + protected static $whitelistedFiles = array(); + + /** + * Adds a directory to the blacklist (recursively). + * + * @param string $directory + * @param string $suffix + * @param string $group + * @access public + * @static + * @since Method available since Release 3.1.5 + */ + public static function addDirectoryToFilter($directory, $suffix = '.php', $group = 'DEFAULT') + { + if (file_exists($directory)) { + foreach (self::getIterator($directory, $suffix) as $file) { + self::addFileToFilter($file->getPathName(), $group); + } + } + } + + /** + * Adds a new file to be filtered (blacklist). + * + * @param string $filename + * @param string $group + * @access public + * @static + * @since Method available since Release 2.1.0 + */ + public static function addFileToFilter($filename, $group = 'DEFAULT') + { + if (file_exists($filename)) { + $filename = realpath($filename); + + if (!isset(self::$blacklistedFiles[$group])) { + self::$blacklistedFiles[$group] = array($filename); + } + + else if (!in_array($filename, self::$blacklistedFiles[$group])) { + self::$blacklistedFiles[$group][] = $filename; + } + } + } + + /** + * Removes a directory from the blacklist (recursively). + * + * @param string $directory + * @param string $suffix + * @param string $group + * @access public + * @static + * @since Method available since Release 3.1.5 + */ + public static function removeDirectoryFromFilter($directory, $suffix = '.php', $group = 'DEFAULT') + { + if (file_exists($directory)) { + foreach (self::getIterator($directory, $suffix) as $file) { + self::removeFileFromFilter($file->getPathName(), $group); + } + } + } + + /** + * Removes a file from the filter (blacklist). + * + * @param string $filename + * @param string $group + * @access public + * @static + * @since Method available since Release 2.1.0 + */ + public static function removeFileFromFilter($filename, $group = 'DEFAULT') + { + if (file_exists($filename)) { + if (isset(self::$blacklistedFiles[$group])) { + $filename = realpath($filename); + + foreach (self::$blacklistedFiles[$group] as $key => $_filename) { + if ($filename == $_filename) { + unset(self::$blacklistedFiles[$group][$key]); + } + } + } + } + } + + /** + * Adds a directory to the whitelist (recursively). + * + * @param string $directory + * @param string $suffix + * @access public + * @static + * @since Method available since Release 3.1.5 + */ + public static function addDirectoryToWhitelist($directory, $suffix = '.php') + { + if (file_exists($directory)) { + foreach (self::getIterator($directory, $suffix) as $file) { + self::addFileToWhitelist($file->getPathName()); + } + } + } + + /** + * Adds a new file to the whitelist. + * + * When the whitelist is empty (default), blacklisting is used. + * When the whitelist is not empty, whitelisting is used. + * + * @param string $filename + * @access public + * @static + * @since Method available since Release 3.1.0 + */ + public static function addFileToWhitelist($filename) + { + if (file_exists($filename)) { + $filename = realpath($filename); + + if (!in_array($filename, self::$whitelistedFiles)) { + self::$whitelistedFiles[] = $filename; + } + } + } + + /** + * Removes a directory from the whitelist (recursively). + * + * @param string $directory + * @param string $suffix + * @access public + * @static + * @since Method available since Release 3.1.5 + */ + public static function removeDirectoryFromWhitelist($directory, $suffix = '.php') + { + if (file_exists($directory)) { + foreach (self::getIterator($directory, $suffix) as $file) { + self::removeFileFromWhitelist($file->getPathName()); + } + } + } + + /** + * Removes a file from the whitelist. + * + * @param string $filename + * @access public + * @static + * @since Method available since Release 3.1.0 + */ + public static function removeFileFromWhitelist($filename) + { + if (file_exists($filename)) { + $filename = realpath($filename); + + foreach (self::$whitelistedFiles as $key => $_filename) { + if ($filename == $_filename) { + unset(self::$whitelistedFiles[$key]); + } + } + } + } + + /** + * Returns data about files within code coverage information, specifically + * which ones will be filtered out and which ones may be whitelisted but not + * touched by coverage. + * + * Returns a two-item array. The first item is an array indexed by filenames + * with a boolean payload of whether they should be filtered out. + * + * The second item is an array of filenames which are + * whitelisted but which are absent from the coverage information. + * + * @param array $codeCoverageInformation + * @param boolean $filterTests + * @return array + * @access public + * @static + */ + public static function getFileCodeCoverageDisposition(array $codeCoverageInformation, $filterTests = TRUE) + { + if (!self::$filter) { + return array(array(), array()); + } + + $isFilteredCache = array(); + $coveredFiles = array(); + + foreach ($codeCoverageInformation as $k => $test) { + foreach (array_keys($test['files']) as $file) { + if (!isset($isFilteredCache[$file])) { + $isFilteredCache[$file] = self::isFiltered( + $file, $filterTests + ); + } + } + } + + $coveredFiles = array_keys($isFilteredCache); + $missedFiles = array_diff(self::$whitelistedFiles,$coveredFiles); + $missedFiles = array_filter($missedFiles,'file_exists'); + + return array($isFilteredCache,$missedFiles); + } + + /** + * @param array $codeCoverageInformation + * @param boolean $addUncoveredFilesFromWhitelist + * @return array + * @access public + * @static + */ + public static function getFilteredCodeCoverage(array $codeCoverageInformation, $filterTests = TRUE) + { + if (self::$filter) { + list($isFilteredCache, $missedFiles) = self::getFileCodeCoverageDisposition( + $codeCoverageInformation, $filterTests + ); + + foreach ($codeCoverageInformation as $k => $test) { + foreach (array_keys($test['files']) as $file) { + if ($isFilteredCache[$file]) { + unset($codeCoverageInformation[$k]['files'][$file]); + } + } + } + + if (self::$addUncoveredFilesFromWhitelist) { + foreach ($missedFiles as $missedFile) { + xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE); + include_once $missedFile; + $coverage = xdebug_get_code_coverage(); + xdebug_stop_code_coverage(); + + if (isset($coverage[$missedFile])) { + foreach ($coverage[$missedFile] as $line => $flag) { + if ($flag > 0) { + $coverage[$missedFile][$line] = -1; + } + } + + $codeCoverageInformation[] = array( + 'test' => NULL, + 'files' => array( + $missedFile => $coverage[$missedFile] + ) + ); + } + } + } + } + + return $codeCoverageInformation; + } + + /** + * Filters stack frames from PHPUnit classes. + * + * @param Exception $e + * @param boolean $filterTests + * @param boolean $asString + * @return string + * @access public + * @static + */ + public static function getFilteredStacktrace(Exception $e, $filterTests = TRUE, $asString = TRUE) + { + if ($asString === TRUE) { + $filteredStacktrace = ''; + } else { + $filteredStacktrace = array(); + } + + foreach ($e->getTrace() as $frame) { + if (!self::$filter || (isset($frame['file']) && !self::isFiltered($frame['file'], $filterTests, TRUE))) { + if ($asString === TRUE) { + $filteredStacktrace .= sprintf( + "%s:%s\n", + + $frame['file'], + isset($frame['line']) ? $frame['line'] : '?' + ); + } else { + $filteredStacktrace[] = $frame; + } + } + } + + return $filteredStacktrace; + } + + /** + * Activates or deactivates filtering. + * + * @param boolean $filter + * @throws InvalidArgumentException + * @access public + * @static + * @since Method available since Release 3.0.0 + */ + public static function setFilter($filter) + { + if (is_bool($filter)) { + self::$filter = $filter; + } else { + throw new InvalidArgumentException; + } + } + + /** + * Returns a PHPUnit_Util_FilterIterator that iterates + * over all files in the given directory that have the + * given suffix. + * + * @param string $directory + * @param string $suffix + * @return Iterator + * @access protected + * @static + * @since Method available since Release 3.1.5 + */ + protected static function getIterator($directory, $suffix) + { + return new PHPUnit_Util_FilterIterator( + new RecursiveIteratorIterator( + new RecursiveDirectoryIterator($directory) + ), + $suffix + ); + } + + /** + * @param string $filename + * @param boolean $filterTests + * @param boolean $ignoreWhitelist + * @return boolean + * @access protected + * @static + * @since Method available since Release 2.1.3 + */ + protected static function isFiltered($filename, $filterTests = TRUE, $ignoreWhitelist = FALSE) + { + $filename = realpath($filename); + + // Use blacklist. + if ($ignoreWhitelist || empty(self::$whitelistedFiles)) { + if (DIRECTORY_SEPARATOR == '\\' && + !self::$blackListConverstionForWindowsDone) { + $count = count(self::$blacklistedFiles['PEAR']); + + for ($i = 0; $i < $count; $i++) { + self::$blacklistedFiles['PEAR'][$i] = str_replace( + '/', '\\', self::$blacklistedFiles['PEAR'][$i] + ); + } + + self::$blackListConverstionForWindowsDone = TRUE; + } + + $blacklistedFiles = array_merge( + self::$blacklistedFiles['DEFAULT'], + self::$blacklistedFiles['PEAR'] + ); + + if ($filterTests) { + $blacklistedFiles = array_merge( + $blacklistedFiles, + self::$blacklistedFiles['TESTS'] + ); + } + + if (self::$filterPHPUnit) { + $blacklistedFiles = array_merge( + $blacklistedFiles, + self::$blacklistedFiles['PHPUNIT'] + ); + } + + if (in_array($filename, $blacklistedFiles)) { + return TRUE; + } + + foreach ($blacklistedFiles as $filteredFile) { + if (strpos($filename, $filteredFile) !== FALSE) { + return TRUE; + } + } + + return FALSE; + } + + // Use whitelist. + else + { + if (in_array($filename, self::$whitelistedFiles)) { + return FALSE; + } + + return TRUE; + } + } +} + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); +?> Property changes on: test/PHPUnit/Util/Filter.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/CodeCoverage.php =================================================================== --- test/PHPUnit/Util/CodeCoverage.php (revision 0) +++ test/PHPUnit/Util/CodeCoverage.php (revision 0) @@ -0,0 +1,255 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: CodeCoverage.php 1985 2007-12-26 18:11:55Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 3.1.0 + */ + +require_once 'PHPUnit/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Code Coverage helpers. + * + * @category Testing + * @package PHPUnit + * @author Sebastian Bergmann + * @copyright 2002-2008 Sebastian Bergmann + * @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.0 + * @abstract + */ +abstract class PHPUnit_Util_CodeCoverage +{ + protected static $lineToTestMap = array(); + protected static $summary = array(); + + /** + * Returns the names of the covered files. + * + * @param array $data + * @return array + * @access public + * @static + */ + public static function getCoveredFiles(array &$data) + { + $files = array(); + + foreach ($data as $test) { + $_files = array_keys($test['files']); + + foreach ($_files as $file) { + if (self::isFile($file) && !in_array($file, $files)) { + $files[] = $file; + } + } + } + + return $files; + } + + /** + * Returns the tests that cover a given line. + * + * @param array $data + * @param string $file + * @param string $line + * @param boolean $clear + * @return array + * @access public + * @static + */ + public static function getCoveringTests(array &$data, $file, $line, $clear = FALSE) + { + if (empty(self::$lineToTestMap) || $clear) { + foreach ($data as $test) { + foreach ($test['files'] as $_file => $lines) { + foreach ($lines as $_line => $flag) { + if ($flag > 0) { + if (!isset(self::$lineToTestMap[$_file][$_line])) { + self::$lineToTestMap[$_file][$_line] = array($test['test']); + } else { + self::$lineToTestMap[$_file][$_line][] = $test['test']; + } + } + } + } + } + } + + if (isset(self::$lineToTestMap[$file][$line])) { + return self::$lineToTestMap[$file][$line]; + } else { + return FALSE; + } + } + + /** + * Returns summarized code coverage data. + * + * Format of the result array: + * + * + * array( + * "/tested/code.php" => array( + * linenumber => number of tests that executed the line + * ) + * ) + * + * + * @param array $data + * @param boolean $clear + * @return array + * @access public + * @static + */ + public static function getSummary(array &$data, $clear = FALSE) + { + if (empty(self::$summary) || $clear) { + $isFileCache = array(); + + foreach ($data as $test) { + foreach ($test['files'] as $file => $lines) { + if (!isset($isFileCache[$file])) { + $isFileCache[$file] = self::isFile($file); + } + + if (!$isFileCache[$file]) { + continue; + } + + $fileSummary = &self::$summary[$file]; + + foreach ($lines as $line => $flag) { + // +1: Line is executable and was executed. + if ($flag == 1) { + if (isset($fileSummary[$line][0])) { + $fileSummary[$line][] = $test['test']; + } + else { + $fileSummary[$line] = array($test['test']); + } + } + + // -1: Line is executable and was not executed. + // -2: Line is dead code. + else if (!isset($fileSummary[$line])) { + $fileSummary[$line] = $flag; + } + } + + unset($fileSummary); + } + } + } + + return self::$summary; + } + + /** + * Returns the coverage statistics for a section of a file. + * + * @param array $data + * @param string $filename + * @param integer $startLine + * @param integer $endLine + * @return array + * @access public + * @static + * @since Method available since Release 3.2.0 + */ + public static function getStatistics(array &$data, $filename, $startLine = 1, $endLine = FALSE) { + $coverage = 0; + $locExecutable = 0; + $locExecuted = 0; + + if (isset($data[$filename])) { + if ($endLine == FALSE) { + $endLine = count(file($filename)); + } + + foreach ($data[$filename] as $line => $_data) { + if ($line >= $startLine && $line <= $endLine) { + if (is_array($_data)) { + $locExecutable++; + $locExecuted++; + } + + else if ($_data == -1) { + $locExecutable++; + } + } + } + + if ($locExecutable > 0) { + $coverage = ($locExecuted / $locExecutable) * 100; + } + } + + return array( + 'coverage' => $coverage, + 'loc' => $endLine - $startLine + 1, + 'locExecutable' => $locExecutable, + 'locExecuted' => $locExecuted + ); + } + + /** + * @param string $file + * @return boolean + * @access protected + * @static + */ + protected static function isFile($file) + { + if (strpos($file, 'eval()\'d code') || strpos($file, 'runtime-created function') || strpos($file, 'assert code')) { + return FALSE; + } + + return TRUE; + } +} +?> Property changes on: test/PHPUnit/Util/CodeCoverage.php ___________________________________________________________________ Name: svn:executable + * Index: test/PHPUnit/Util/ErrorHandler.php =================================================================== --- test/PHPUnit/Util/ErrorHandler.php (revision 0) +++ test/PHPUnit/Util/ErrorHandler.php (revision 0) @@ -0,0 +1,93 @@ +. + * 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 + * @copyright 2002-2008 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id: ErrorHandler.php 1985 2007-12-26 18:11:55Z sb $ + * @link http://www.phpunit.de/ + * @since File available since Release 2.3.0 + */ + +require_once 'PHPUnit/Framework.php'; +require_once 'PHPUnit/Util/Filter.php'; + +PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * @param integer $errno + * @param string $errstr + * @param string $errfile + * @param integer $errline + * @throws PHPUnit_Framework_Error + * @since Function available since Release 2.3.0 + */ +function PHPUnit_Util_ErrorHandler($errno, $errstr, $errfile, $errline) +{ + if (!($errno & error_reporting())) { + return; + } + + $trace = debug_backtrace(); + array_shift($trace); + + foreach ($trace as $frame) { + if ($frame['function'] == '__toString') { + return; + } + } + + if ($errno == E_NOTICE || $errno == E_STRICT) { + if (PHPUnit_Framework_Notice::$enabled !== TRUE) { + return; + } + + $exception = 'PHPUnit_Framework_Notice'; + } else { + $exception = 'PHPUnit_Framework_Error'; + } + + throw new $exception( + $errstr, + $errno, + $errfile, + $errline, + $trace + ); +} +?> Property changes on: test/PHPUnit/Util/ErrorHandler.php ___________________________________________________________________ Name: svn:executable + * Index: test/common/index.php =================================================================== --- test/common/index.php (revision 0) +++ test/common/index.php (revision 0) @@ -0,0 +1,43 @@ + 2 ){ + foreach ($dir as $file){ + if($file != '..' && $file != '.'){ + if(is_dir($file)){ + readDirR($dirName.'/'.$file, $names); + } + $clase = str_replace('.php','',$file); + $names[] = array('path' => $dirName.'/'.$file,'name' => $clase); + } + } + } + +} + +$clases = array(); +readDirR('.', $clases); +$suite = new PHPUnit_Framework_TestSuite(); + +foreach($clases as $clase){ + if(file_exists($clase['path'])){ + @require_once $clase['path']; + if(class_exists($clase['name'])){ + $suite->addTestSuite($clase['name']); + } + } +} + +$result = new PHPUnit_TextUI_TestRunner(); +echo 'TestCases

Test Cases

'; 
+	$result->doRun($suite);
+echo'
' +?> \ No newline at end of file Property changes on: test/common/index.php ___________________________________________________________________ Name: svn:executable + * Index: test/gadgets/GadgetContextTest.php =================================================================== --- test/gadgets/GadgetContextTest.php (revision 0) +++ test/gadgets/GadgetContextTest.php (revision 0) @@ -0,0 +1,390 @@ + 'http://www.google.com/gadget-', + 'libs' => '', + 'synd' => 'default', + 'nocache' => '', + 'container' => 'default', + 'view' => 'default', + 'mid' => '123', + 'bcp' => '' + ); + + /** + * @var gadgetRenderingContext + */ + private $gadgetRenderingContext = 'GADGET'; + /** + * Prepares the environment before running a test. + */ + protected function setUp() { + parent::setUp (); + + $_GET = $this->testData; + $this->GadgetContext = new GadgetContext($this->gadgetRenderingContext); + + } + + /** + * Cleans up the environment after running a test. + */ + protected function tearDown() { + $this->GadgetContext = null; + + parent::tearDown (); + } + + /** + * Constructs the test case. + */ + public function __construct() { + // TODO Auto-generated constructor + + + } + + /** + * Tests GadgetContext->getBlacklist() + */ + public function testGetBlacklist() { + $this->markTestIncomplete ( "getBlacklist test not implemented" ); + + $this->GadgetContext->getBlacklist(/* parameters */); + + } + + /** + * Tests GadgetContext->getCache() + */ + public function testGetCache() { + // TODO Auto-generated GadgetContextTest->testGetCache() + $this->markTestIncomplete ( "getCache test not implemented" ); + + $this->GadgetContext->getCache(/* parameters */); + + } + + /** + * Tests GadgetContext->getContainer() + */ + public function testGetContainer() { + + $this->assertEquals($this->testData['container'],$this->GadgetContext->getContainer()); + + } + + /** + * Tests GadgetContext->getContainerConfig() + */ + public function testGetContainerConfig() { + // TODO Auto-generated GadgetContextTest->testGetContainerConfig() + $this->markTestIncomplete ( "getContainerConfig test not implemented" ); + + $this->GadgetContext->getContainerConfig(/* parameters */); + + } + + /** + * Tests GadgetContext->getFeatureRegistry() + */ + public function testGetFeatureRegistry() { + // TODO Auto-generated GadgetContextTest->testGetFeatureRegistry() + $this->markTestIncomplete ( "getFeatureRegistry test not implemented" ); + + $this->GadgetContext->getFeatureRegistry(/* parameters */); + + } + + /** + * Tests GadgetContext->getForcedJsLibs() + */ + public function testGetForcedJsLibs() { + + $this->assertEquals($this->testData['libs'],$this->GadgetContext->getForcedJsLibs()); + + } + + /** + * Tests GadgetContext->getGadgetId() + */ + public function testGetGadgetId() { + // TODO Auto-generated GadgetContextTest->testGetGadgetId() + $this->markTestIncomplete ( "getGadgetId test not implemented" ); + + $this->GadgetContext->getGadgetId(/* parameters */); + + } + + /** + * Tests GadgetContext->getHttpFetcher() + */ + public function testGetHttpFetcher() { + // TODO Auto-generated GadgetContextTest->testGetHttpFetcher() + $this->markTestIncomplete ( "getHttpFetcher test not implemented" ); + + $this->GadgetContext->getHttpFetcher(/* parameters */); + + } + + /** + * Tests GadgetContext->getIgnoreCache() + */ + public function testGetIgnoreCache() { + // TODO Auto-generated GadgetContextTest->testGetIgnoreCache() + $this->markTestIncomplete ( "getIgnoreCache test not implemented" ); + + $this->GadgetContext->getIgnoreCache(/* parameters */); + + } + + /** + * Tests GadgetContext->getLocale() + */ + public function testGetLocale() { + // TODO Auto-generated GadgetContextTest->testGetLocale() + $this->markTestIncomplete ( "getLocale test not implemented" ); + + $this->GadgetContext->getLocale(/* parameters */); + + } + + /** + * Tests GadgetContext->getModuleId() + */ + public function testGetModuleId() { + $this->assertEquals($this->testData['mid'],$this->GadgetContext->getModuleId()); + + } + + /** + * Tests GadgetContext->getRegistry() + */ + public function testGetRegistry() { + // TODO Auto-generated GadgetContextTest->testGetRegistry() + $this->markTestIncomplete ( "getRegistry test not implemented" ); + + $this->GadgetContext->getRegistry(/* parameters */); + + } + + /** + * Tests GadgetContext->getRenderingContext() + */ + public function testGetRenderingContext() { + + $this->assertEquals($this->gadgetRenderingContext,$this->GadgetContext->getRenderingContext()); + + } + + /** + * Tests GadgetContext->getUrl() + */ + public function testGetUrl() { + + $this->assertEquals($this->testData['url'],$this->GadgetContext->getUrl()); + + } + + /** + * Tests GadgetContext->getUserPrefs() + */ + public function testGetUserPrefs() { + // TODO Auto-generated GadgetContextTest->testGetUserPrefs() + $this->markTestIncomplete ( "getUserPrefs test not implemented" ); + + $this->GadgetContext->getUserPrefs(); + + } + + /** + * Tests GadgetContext->getView() + */ + public function testGetView() { + + $this->assertEquals($this->testData['view'], $this->GadgetContext->getView()); + + } + + /** + * Tests GadgetContext->setBlacklist() + */ + public function testSetBlacklist() { + // TODO Auto-generated GadgetContextTest->testSetBlacklist() + $this->markTestIncomplete ( "setBlacklist test not implemented" ); + + $this->GadgetContext->setBlacklist(/* parameters */); + + } + + /** + * Tests GadgetContext->setCache() + */ + public function testSetCache() { + // TODO Auto-generated GadgetContextTest->testSetCache() + $this->markTestIncomplete ( "setCache test not implemented" ); + + $this->GadgetContext->setCache(/* parameters */); + + } + + /** + * Tests GadgetContext->setContainer() + */ + public function testSetContainer() { + // TODO Auto-generated GadgetContextTest->testSetContainer() + $this->markTestIncomplete ( "setContainer test not implemented" ); + + $this->GadgetContext->setContainer(/* parameters */); + + } + + /** + * Tests GadgetContext->setContainerConfig() + */ + public function testSetContainerConfig() { + // TODO Auto-generated GadgetContextTest->testSetContainerConfig() + $this->markTestIncomplete ( "setContainerConfig test not implemented" ); + + $this->GadgetContext->setContainerConfig(/* parameters */); + + } + + /** + * Tests GadgetContext->setForcedJsLibs() + */ + public function testSetForcedJsLibs() { + // TODO Auto-generated GadgetContextTest->testSetForcedJsLibs() + $this->markTestIncomplete ( "setForcedJsLibs test not implemented" ); + + $this->GadgetContext->setForcedJsLibs(/* parameters */); + + } + + /** + * Tests GadgetContext->setGadgetId() + */ + public function testSetGadgetId() { + // TODO Auto-generated GadgetContextTest->testSetGadgetId() + $this->markTestIncomplete ( "setGadgetId test not implemented" ); + + $this->GadgetContext->setGadgetId(/* parameters */); + + } + + /** + * Tests GadgetContext->setHttpFetcher() + */ + public function testSetHttpFetcher() { + // TODO Auto-generated GadgetContextTest->testSetHttpFetcher() + $this->markTestIncomplete ( "setHttpFetcher test not implemented" ); + + $this->GadgetContext->setHttpFetcher(/* parameters */); + + } + + /** + * Tests GadgetContext->setIgnoreCache() + */ + public function testSetIgnoreCache() { + // TODO Auto-generated GadgetContextTest->testSetIgnoreCache() + $this->markTestIncomplete ( "setIgnoreCache test not implemented" ); + + $this->GadgetContext->setIgnoreCache(/* parameters */); + + } + + /** + * Tests GadgetContext->setLocale() + */ + public function testSetLocale() { + // TODO Auto-generated GadgetContextTest->testSetLocale() + $this->markTestIncomplete ( "setLocale test not implemented" ); + + $this->GadgetContext->setLocale(/* parameters */); + + } + + /** + * Tests GadgetContext->setModuleId() + */ + public function testSetModuleId() { + // TODO Auto-generated GadgetContextTest->testSetModuleId() + $this->markTestIncomplete ( "setModuleId test not implemented" ); + + $this->GadgetContext->setModuleId(/* parameters */); + + } + + /** + * Tests GadgetContext->setRegistry() + */ + public function testSetRegistry() { + // TODO Auto-generated GadgetContextTest->testSetRegistry() + $this->markTestIncomplete ( "setRegistry test not implemented" ); + + $this->GadgetContext->setRegistry(/* parameters */); + + } + + /** + * Tests GadgetContext->setRenderingContext() + */ + public function testSetRenderingContext() { + $redering_context = 'Dummie_rendering_context'; + $this->GadgetContext->setRenderingContext($redering_context); + $this->assertAttributeEquals($redering_context,'renderingContext',$this->GadgetContext); + + } + + /** + * Tests GadgetContext->setUrl() + */ + public function testSetUrl() { + $url = 'Dummie_url'; + $this->GadgetContext->setUrl($url); + $this->assertAttributeEquals($url,'url',$this->GadgetContext); + + } + + /** + * Tests GadgetContext->setUserPrefs() + */ + public function testSetUserPrefs() { + // TODO Auto-generated GadgetContextTest->testSetUserPrefs() + $this->markTestIncomplete ( "setUserPrefs test not implemented" ); + + $this->GadgetContext->setUserPrefs(/* parameters */); + + } + + /** + * Tests GadgetContext->setView() + */ + public function testSetView() { + $view = 'Dummie_view'; + $this->GadgetContext->setView($view); + $this->assertAttributeEquals($view,'view',$this->GadgetContext); + + } + + +} + Property changes on: test/gadgets/GadgetContextTest.php ___________________________________________________________________ Name: svn:executable + * Index: test/gadgets/index.php =================================================================== --- test/gadgets/index.php (revision 0) +++ test/gadgets/index.php (revision 0) @@ -0,0 +1,43 @@ + 0 ){ + while (($file = readdir($dir)) !== false) { + if($file != '..' && $file != '.' && $file != 'index.php'){ + if(is_dir($file)){ + readDirR($dirName.'/'.$file, $names); + }else{ + $clase = str_replace('.php','',$file); + $names[] = array('path' => $dirName.'/'.$file,'name' => $clase); + } + } + } + } + +} + +$clases = array(); +readDirR('.', $clases); +$suite = new PHPUnit_Framework_TestSuite(); + +foreach($clases as $clase){ + if(file_exists($clase['path'])){ + @require_once $clase['path']; + if(class_exists($clase['name'])){ + $suite->addTestSuite($clase['name']); + } + } +} +$result = new PHPUnit_TextUI_TestRunner(); +echo 'TestCases

Test Cases

'; 
+	$result->doRun($suite);
+echo'
' +?> \ No newline at end of file Property changes on: test/gadgets/index.php ___________________________________________________________________ Name: svn:executable + * Index: test/gadgets/GadgetIdTest.php =================================================================== --- test/gadgets/GadgetIdTest.php (revision 0) +++ test/gadgets/GadgetIdTest.php (revision 0) @@ -0,0 +1,80 @@ +GadgetId = new GadgetId($this->uri,$this->moduleId); + + } + + /** + * Cleans up the environment after running a test. + */ + protected function tearDown() { + // TODO Auto-generated GadgetIdTest::tearDown() + + + $this->GadgetId = null; + + parent::tearDown (); + } + + /** + * Constructs the test case. + */ + public function __construct() { + // TODO Auto-generated constructor + } + + + /** + * Tests GadgetId->getKey() + */ + public function testGetKey() { + // TODO Auto-generated GadgetIdTest->testGetKey() + + $this->assertEquals($this->uri,$this->GadgetId->getKey()); + } + + /** + * Tests GadgetId->getModuleId() + */ + public function testGetModuleId() { + // TODO Auto-generated GadgetIdTest->testGetModuleId() + + $this->GadgetId->getModuleId(); + + } + + /** + * Tests GadgetId->getURI() + */ + public function testGetURI() { + // TODO Auto-generated GadgetIdTest->testGetURI() + $this->assertEquals($this->uri,$this->GadgetId->getURI()); + + } + +} + Property changes on: test/gadgets/GadgetIdTest.php ___________________________________________________________________ Name: svn:executable + *