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 '
TestCasesTest 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