cvs: pear /MDB2/tests MDB2_api_testcase.php MDB2_bugs_testcase.php MDB2_manager_testcase.php MDB2_native_testcase.php MDB2_reverse_testcase.php
MDB2_testcase.php MDB2_usage_testcase.php

From: Date: Mon, 17 Oct 2005 08:07:32 +0000
Subject: cvs: pear /MDB2/tests MDB2_api_testcase.php MDB2_bugs_testcase.php MDB2_manager_testcase.php MDB2_native_testcase.php MDB2_reverse_testcase.php
MDB2_testcase.php MDB2_usage_testcase.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-35634@lists.php.net to get a copy of this message
lsmith Mon Oct 17 04:07:32 2005 EDT Added files: /pear/MDB2/tests MDB2_testcase.php Modified files: /pear/MDB2/tests MDB2_api_testcase.php MDB2_bugs_testcase.php MDB2_manager_testcase.php MDB2_native_testcase.php MDB2_reverse_testcase.php MDB2_usage_testcase.php Log: - refactored test cases to use an MDB2_testcase base class

http://cvs.php.net/diff.php/pear/MDB2/tests/MDB2_api_testcase.php?r1=1.12&r2=1.13&ty=u Index: pear/MDB2/tests/MDB2_api_testcase.php diff -u pear/MDB2/tests/MDB2_api_testcase.php:1.12 pear/MDB2/tests/MDB2_api_testcase.php:1.13 --- pear/MDB2/tests/MDB2_api_testcase.php:1.12 Thu Aug 25 04:48:45 2005 +++ pear/MDB2/tests/MDB2_api_testcase.php Mon Oct 17 04:07:32 2005 @@ -41,67 +41,11 @@ // | Author: Paul Cooper <pgc@ucecom.com> | // +----------------------------------------------------------------------+ // -// $Id: MDB2_api_testcase.php,v 1.12 2005/08/25 08:48:45 lsmith Exp $ +// $Id: MDB2_api_testcase.php,v 1.13 2005/10/17 08:07:32 lsmith Exp $ -class MDB2_Api_TestCase extends PHPUnit_TestCase { - //contains the dsn of the database we are testing - var $dsn; - //contains the options that should be used during testing - var $options; - //contains the name of the database we are testing - var $database; - //contains the MDB2 object of the db once we have connected - var $db; - // contains field names from the test table - var $fields; - // contains the types of the fields from the test table - var $types; - - function MDB2_Api_Test($name) { - $this->PHPUnit_TestCase($name); - } - - function setUp() { - $this->dsn = $GLOBALS['dsn']; - $this->options = $GLOBALS['options']; - $this->database = $GLOBALS['database']; - $this->db =& MDB2::factory($this->dsn, $this->options); - if (PEAR::isError($this->db)) { - $this->assertTrue(false, 'Could not connect to database in setUp - ' .$this->db->getMessage() . ' - ' .$this->db->getUserInfo()); - exit; - } - $this->db->setDatabase($this->database); - $this->fields = array( - 'user_name' => 'text', - 'user_password' => 'text', - 'subscribed' => 'boolean', - 'user_id' => 'integer', - 'quota' => 'decimal', - 'weight' => 'float', - 'access_date' => 'date', - 'access_time' => 'time', - 'approved' => 'timestamp', - ); - } - - function tearDown() { - unset($this->dsn); - if (!PEAR::isError($this->db)) { - $this->db->disconnect(); - } - unset($this->db); - } - - function methodExists(&$class, $name) { - if (is_object($class) - && array_key_exists(strtolower($name), array_change_key_case(array_flip(get_class_methods($class)), CASE_LOWER)) - ) { - return true; - } - $this->assertTrue(false, 'method '. $name.' not implemented in '.get_class($class)); - return false; - } +require_once 'MDB2_TestCase.php'; +class MDB2_Api_TestCase extends MDB2_TestCase { //test stuff in common.php function testConnect() { $db =& MDB2::factory($this->dsn, $this->options); http://cvs.php.net/diff.php/pear/MDB2/tests/MDB2_bugs_testcase.php?r1=1.21&r2=1.22&ty=u Index: pear/MDB2/tests/MDB2_bugs_testcase.php diff -u pear/MDB2/tests/MDB2_bugs_testcase.php:1.21 pear/MDB2/tests/MDB2_bugs_testcase.php:1.22 --- pear/MDB2/tests/MDB2_bugs_testcase.php:1.21 Thu Aug 25 04:48:45 2005 +++ pear/MDB2/tests/MDB2_bugs_testcase.php Mon Oct 17 04:07:32 2005 @@ -41,84 +41,11 @@ // | Author: Paul Cooper <pgc@ucecom.com> | // +----------------------------------------------------------------------+ // -// $Id: +// $Id: MDB2_bugs_testcase.php,v 1.22 2005/10/17 08:07:32 lsmith Exp $ -class MDB2_Bugs_TestCase extends PHPUnit_TestCase { - //contains the dsn of the database we are testing - var $dsn; - //contains the options that should be used during testing - var $options; - //contains the name of the database we are testing - var $database; - //contains the MDB2 object of the db once we have connected - var $db; - // contains field names from the test table - var $fields; - // contains the types of the fields from the test table - var $types; - - function MDB2_Bugs_TestCase($name) { - $this->PHPUnit_TestCase($name); - } - - function setUp() { - $this->dsn = $GLOBALS['dsn']; - $this->options = $GLOBALS['options']; - $this->database = $GLOBALS['database']; - $this->db =& MDB2::factory($this->dsn, $this->options); - if (PEAR::isError($this->db)) { - $this->assertTrue(false, 'Could not connect to database in setUp'); - exit; - } - $this->db->setDatabase($this->database); - $this->fields = array( - 'user_name' => 'text', - 'user_password' => 'text', - 'subscribed' => 'boolean', - 'user_id' => 'integer', - 'quota' => 'decimal', - 'weight' => 'float', - 'access_date' => 'date', - 'access_time' => 'time', - 'approved' => 'timestamp', - ); - $this->clearTables(); - } - - function tearDown() { - $this->clearTables(); - unset($this->dsn); - if (!PEAR::isError($this->db)) { - $this->db->disconnect(); - } - unset($this->db); - } - - function clearTables() { - if (PEAR::isError($this->db->query('DELETE FROM users'))) { - $this->assertTrue(false, 'Error deleting from table users'); - } - if (PEAR::isError($this->db->query('DELETE FROM files'))) { - $this->assertTrue(false, 'Error deleting from table users'); - } - } - - function verifyFetchedValues(&$result, $rownum, &$data) { - $row = $result->fetchRow(MDB2_FETCHMODE_DEFAULT, $rownum); - reset($row); - foreach ($this->fields as $field => $type) { - $value = current($row); - if ($type == 'float') { - $delta = 0.0000000001; - } else { - $delta = 0; - } - - $this->assertEquals($data[$field], $value, "the value retrieved for field \"$field\" doesn't match what was stored into the row $rownum", $delta); - next($row); - } - } +require_once 'MDB2_TestCase.php'; +class MDB2_Bugs_TestCase extends MDB2_TestCase { /** * */ http://cvs.php.net/diff.php/pear/MDB2/tests/MDB2_manager_testcase.php?r1=1.29&r2=1.30&ty=u Index: pear/MDB2/tests/MDB2_manager_testcase.php diff -u pear/MDB2/tests/MDB2_manager_testcase.php:1.29 pear/MDB2/tests/MDB2_manager_testcase.php:1.30 --- pear/MDB2/tests/MDB2_manager_testcase.php:1.29 Sun Oct 16 12:31:54 2005 +++ pear/MDB2/tests/MDB2_manager_testcase.php Mon Oct 17 04:07:32 2005 @@ -42,41 +42,17 @@ // | Lorenzo Alberton <l dot alberton at quipo dot it> | // +----------------------------------------------------------------------+ // -// $Id: MDB2_manager_testcase.php,v 1.29 2005/10/16 16:31:54 lsmith Exp $ +// $Id: MDB2_manager_testcase.php,v 1.30 2005/10/17 08:07:32 lsmith Exp $ -require_once 'MDB2/Schema.php'; +require_once 'MDB2_TestCase.php'; -class MDB2_Manager_TestCase extends PHPUnit_TestCase { - //contains the dsn of the database we are testing - var $dsn; - //contains the options that should be used during testing - var $options; - //contains the name of the database we are testing - var $database; - //contains the MDB2 object of the db once we have connected - var $db; +class MDB2_Manager_TestCase extends MDB2_TestCase { //test table name (it is dynamically created/dropped) var $table = 'newtable'; - //test table fields - var $fields; - - function MDB2_Manager_Test($name) { - $this->PHPUnit_TestCase($name); - } function setUp() { - $this->dsn = $GLOBALS['dsn']; - $this->options = $GLOBALS['options']; - $this->database = $GLOBALS['database']; - - $this->db =& MDB2::connect($this->dsn, $this->options); - $this->db->setDatabase($this->database); + parent::setUp(); $this->db->loadModule('Manager'); - $this->db->expectError(MDB2_ERROR_UNSUPPORTED); - if (PEAR::isError($this->db) || PEAR::isError($this->db->manager) ) { - $this->assertTrue(false, 'Could not connect to manager in setUp'); - exit; - } $this->fields = array( 'id' => array( 'type' => 'integer', @@ -98,13 +74,13 @@ 'default' => 'M', ), ); - if (!$this->tableExists()) { + if (!$this->tableExists($this->table)) { $this->db->manager->createTable($this->table, $this->fields); } } function tearDown() { - if ($this->tableExists()) { + if ($this->tableExists($this->table)) { $this->db->manager->dropTable($this->table); } $this->db->popExpect(); @@ -115,21 +91,6 @@ unset($this->db); } - function methodExists(&$class, $name) { - if (is_object($class) - && array_key_exists(strtolower($name), array_change_key_case(array_flip(get_class_methods($class)), CASE_LOWER)) - ) { - return true; - } - $this->assertTrue(false, 'method '. $name.' not implemented in '.get_class($class)); - return false; - } - - function tableExists() { - $tables = $this->db->manager->listTables(); - return in_array($this->table, $tables); - } - /** * Create a sample table, test the new fields, and drop it. */ @@ -137,7 +98,7 @@ if (!$this->methodExists($this->db->manager, 'createTable')) { return; } - if ($this->tableExists()) { + if ($this->tableExists($this->table)) { $this->db->manager->dropTable($this->table); } @@ -343,7 +304,7 @@ if (!$this->methodExists($this->db->manager, 'listTables')) { return; } - $this->assertTrue($this->tableExists(), 'Error listing tables'); + $this->assertTrue($this->tableExists($this->table), 'Error listing tables'); } /** @@ -428,7 +389,7 @@ return; } $result = $this->db->manager->dropTable($this->table); - $this->assertFalse($this->tableExists(), 'Error listing tables'); + $this->assertFalse($this->tableExists($this->table), 'Error listing tables'); } /** http://cvs.php.net/diff.php/pear/MDB2/tests/MDB2_native_testcase.php?r1=1.8&r2=1.9&ty=u Index: pear/MDB2/tests/MDB2_native_testcase.php diff -u pear/MDB2/tests/MDB2_native_testcase.php:1.8 pear/MDB2/tests/MDB2_native_testcase.php:1.9 --- pear/MDB2/tests/MDB2_native_testcase.php:1.8 Thu Aug 25 04:48:45 2005 +++ pear/MDB2/tests/MDB2_native_testcase.php Mon Oct 17 04:07:32 2005 @@ -41,69 +41,12 @@ // | Author: Lorenzo Alberton <l dot alberton at quipo dot it> | // +----------------------------------------------------------------------+ // -// $Id: MDB2_native_testcase.php,v 1.8 2005/08/25 08:48:45 lsmith Exp $ +// $Id: MDB2_native_testcase.php,v 1.9 2005/10/17 08:07:32 lsmith Exp $ -class MDB2_Native_TestCase extends PHPUnit_TestCase -{ - //contains the dsn of the database we are testing - var $dsn; - //contains the options that should be used during testing - var $options; - //contains the name of the database we are testing - var $database; - //contains the MDB2 object of the db once we have connected - var $db; - // contains field names from the test table - var $fields; - // contains the types of the fields from the test table - var $types; - - function MDB2_Native_Test($name) { - $this->PHPUnit_TestCase($name); - } - - function setUp() { - $this->dsn = $GLOBALS['dsn']; - $this->options = $GLOBALS['options']; - $this->database = $GLOBALS['database']; - $this->db =& MDB2::factory($this->dsn, $this->options); - if (PEAR::isError($this->db)) { - $this->assertTrue(false, 'Could not connect to database in setUp - ' .$this->db->getMessage() . ' - ' .$this->db->getUserInfo()); - exit; - } - $this->db->setDatabase($this->database); - $this->db->loadModule('Native'); - $this->fields = array( - 'user_name' => 'text', - 'user_password' => 'text', - 'subscribed' => 'boolean', - 'user_id' => 'integer', - 'quota' => 'decimal', - 'weight' => 'float', - 'access_date' => 'date', - 'access_time' => 'time', - 'approved' => 'timestamp', - ); - } - - function tearDown() { - unset($this->dsn); - if (!PEAR::isError($this->db)) { - $this->db->disconnect(); - } - unset($this->db); - } - - function methodExists(&$class, $name) { - if (is_object($class) - && array_key_exists(strtolower($name), array_change_key_case(array_flip(get_class_methods($class)), CASE_LOWER)) - ) { - return true; - } - $this->assertTrue(false, 'method '. $name.' not implemented in '.get_class($class)); - return false; - } +require_once 'MDB2_TestCase.php'; +class MDB2_Native_TestCase extends MDB2_TestCase +{ /** * Test deleteOID() */ http://cvs.php.net/diff.php/pear/MDB2/tests/MDB2_reverse_testcase.php?r1=1.16&r2=1.17&ty=u Index: pear/MDB2/tests/MDB2_reverse_testcase.php diff -u pear/MDB2/tests/MDB2_reverse_testcase.php:1.16 pear/MDB2/tests/MDB2_reverse_testcase.php:1.17 --- pear/MDB2/tests/MDB2_reverse_testcase.php:1.16 Fri Oct 14 12:30:37 2005 +++ pear/MDB2/tests/MDB2_reverse_testcase.php Mon Oct 17 04:07:32 2005 @@ -41,74 +41,15 @@ // | Author: Lorenzo Alberton <l dot alberton at quipo dot it> | // +----------------------------------------------------------------------+ // -// $Id: MDB2_reverse_testcase.php,v 1.16 2005/10/14 16:30:37 lsmith Exp $ +// $Id: MDB2_reverse_testcase.php,v 1.17 2005/10/17 08:07:32 lsmith Exp $ -class MDB2_Reverse_TestCase extends PHPUnit_TestCase -{ - //contains the dsn of the database we are testing - var $dsn; - //contains the options that should be used during testing - var $options; - //contains the name of the database we are testing - var $database; - //contains the MDB2 object of the db once we have connected - var $db; - // contains field names from the test table - var $fields; - // contains the types of the fields from the test table - var $types; - - function MDB2_Reverse_Test($name) { - $this->PHPUnit_TestCase($name); - } +require_once 'MDB2_TestCase.php'; +class MDB2_Reverse_TestCase extends MDB2_TestCase +{ function setUp() { - $this->dsn = $GLOBALS['dsn']; - $this->options = $GLOBALS['options']; - $this->database = $GLOBALS['database']; - $this->db =& MDB2::factory($this->dsn, $this->options); - if (PEAR::isError($this->db)) { - $this->assertTrue(false, 'Could not connect to database in setUp - ' .$this->db->getMessage() . ' - ' .$this->db->getUserInfo()); - exit; - } - $this->db->setDatabase($this->database); - $this->db->expectError(MDB2_ERROR_UNSUPPORTED); + parent::setUp(); $this->db->loadModule('Reverse'); - $this->fields = array( - 'user_name' => 'text', - 'user_password' => 'text', - 'subscribed' => 'boolean', - 'user_id' => 'integer', - 'quota' => 'decimal', - 'weight' => 'float', - 'access_date' => 'date', - 'access_time' => 'time', - 'approved' => 'timestamp', - ); - } - - function tearDown() { - $this->db->popExpect(); - unset($this->dsn); - if (!PEAR::isError($this->db)) { - $this->db->disconnect(); - } - unset($this->db); - } - - function methodExists(&$class, $name) { - if (is_object($class) - && array_key_exists(strtolower($name), array_change_key_case(array_flip(get_class_methods($class)), CASE_LOWER)) - ) { - return true; - } - $this->assertTrue(false, 'method '. $name.' not implemented in '.get_class($class)); - return false; - } - - function tableExists($table) { - $tables = $this->db->manager->listTables(); - return in_array($table, $tables); } /** @@ -268,8 +209,11 @@ //setup $this->db->loadModule('Manager'); $sequence = 'test_sequence'; - $result = $this->db->manager->createSequence($sequence); - $this->assertFalse(PEAR::isError($result), 'Error creating a sequence'); + $sequences = $this->db->manager->listSequences(); + if (!in_array($sequence, $sequences)) { + $result = $this->db->manager->createSequence($sequence); + $this->assertFalse(PEAR::isError($result), 'Error creating a sequence'); + } //test $start = $this->db->nextId($sequence); http://cvs.php.net/diff.php/pear/MDB2/tests/MDB2_usage_testcase.php?r1=1.43&r2=1.44&ty=u Index: pear/MDB2/tests/MDB2_usage_testcase.php diff -u pear/MDB2/tests/MDB2_usage_testcase.php:1.43 pear/MDB2/tests/MDB2_usage_testcase.php:1.44 --- pear/MDB2/tests/MDB2_usage_testcase.php:1.43 Wed Oct 5 08:40:29 2005 +++ pear/MDB2/tests/MDB2_usage_testcase.php Mon Oct 17 04:07:32 2005 @@ -41,107 +41,11 @@ // | Author: Paul Cooper <pgc@ucecom.com> | // +----------------------------------------------------------------------+ // -// $Id: MDB2_usage_testcase.php,v 1.43 2005/10/05 12:40:29 lsmith Exp $ +// $Id: MDB2_usage_testcase.php,v 1.44 2005/10/17 08:07:32 lsmith Exp $ -class MDB2_Usage_TestCase extends PHPUnit_TestCase { - //contains the dsn of the database we are testing - var $dsn; - //contains the options that should be used during testing - var $options; - //contains the name of the database we are testing - var $database; - //contains the MDB2 object of the db once we have connected - var $db; - // contains field names from the test table - var $fields; - // contains the types of the fields from the test table - var $types; - - function MDB2_Usage_TestCase($name) { - $this->PHPUnit_TestCase($name); - } - - function setUp() { - $this->dsn = $GLOBALS['dsn']; - $this->options = $GLOBALS['options']; - $this->database = $GLOBALS['database']; - $this->db =& MDB2::factory($this->dsn, $this->options); - - if (PEAR::isError($this->db)) { - $this->assertTrue(false, 'Could not connect to database in setUp'); - exit; - } - $this->db->setDatabase($this->database); - $this->fields = array( - 'user_name' => 'text', - 'user_password' => 'text', - 'subscribed' => 'boolean', - 'user_id' => 'integer', - 'quota' => 'decimal', - 'weight' => 'float', - 'access_date' => 'date', - 'access_time' => 'time', - 'approved' => 'timestamp', - ); - $this->clearTables(); - } - - function tearDown() { - $this->clearTables(); - unset($this->dsn); - if (!PEAR::isError($this->db)) { - $this->db->disconnect(); - } - unset($this->db); - } - - function clearTables() { - if (PEAR::isError($this->db->query('DELETE FROM users'))) { - $this->assertTrue(false, 'Error deleting from table users'); - } - if (PEAR::isError($this->db->query('DELETE FROM files'))) { - $this->assertTrue(false, 'Error deleting from table users'); - } - } - - function supported($feature) { - if (!$this->db->supports($feature)) { - $this->assertTrue(false, 'This database does not support '.$feature); - return false; - } - return true; - } - - function verifyFetchedValues(&$result, $rownum, &$data) { - $row = $result->fetchRow(MDB2_FETCHMODE_DEFAULT, $rownum); - reset($row); - foreach ($this->fields as $field => $type) { - $value = current($row); - if ($type == 'float') { - $delta = 0.0000000001; - } else { - $delta = 0; - } - - $this->assertEquals($data[$field], $value, "the value retrieved for field \"$field\" doesn't match what was stored into the row $rownum", $delta); - next($row); - } - } - - function getSampleData($row) { - $data = array(); - $data['user_name'] = 'user_' . $row; - $data['user_password'] = 'somepassword'; - $data['subscribed'] = $row % 2 ? true : false; - $data['user_id'] = $row; - $data['quota'] = strval($row/100); - $data['weight'] = sqrt($row); - $data['access_date'] = MDB2_Date::mdbToday(); - $data['access_time'] = MDB2_Date::mdbTime(); - $data['approved'] = MDB2_Date::mdbNow(); - return $data; - } +require_once 'MDB2_TestCase.php'; +class MDB2_Usage_TestCase extends MDB2_TestCase { /** * Test typed data storage and retrieval * http://cvs.php.net/co.php/pear/MDB2/tests/MDB2_testcase.php?r=1.1&p=1 Index: pear/MDB2/tests/MDB2_testcase.php +++ pear/MDB2/tests/MDB2_testcase.php <?php // +----------------------------------------------------------------------+ // | PHP versions 4 and 5 | // +----------------------------------------------------------------------+ // | Copyright (c) 1998-2004 Manuel Lemos, Paul Cooper | // | All rights reserved. | // +----------------------------------------------------------------------+ // | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB | // | API as well as database abstraction for PHP applications. | // | This LICENSE is in the BSD license style. | // | | // | Redistribution and use in source and binary forms, with or without | // | modification, are permitted provided that the following conditions | // | are met: | // | | // | Redistributions of source code must retain the above copyright | // | notice, this list of conditions and the following disclaimer. | // | | // | Redistributions in binary form must reproduce the above copyright | // | notice, this list of conditions and the following disclaimer in the | // | documentation and/or other materials provided with the distribution. | // | | // | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, | // | Lukas Smith nor the names of his contributors may be used to endorse | // | or promote products derived from this software without specific prior| // | written permission. | // | | // | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | // | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | // | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | // | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | // | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | // | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | // | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS| // | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | // | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | // | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY| // | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | // | POSSIBILITY OF SUCH DAMAGE. | // +----------------------------------------------------------------------+ // | Author: Paul Cooper <pgc@ucecom.com> | // +----------------------------------------------------------------------+ // // $Id: MDB2_testcase.php,v 1.1 2005/10/17 08:07:32 lsmith Exp $ class MDB2_TestCase extends PHPUnit_TestCase { //contains the dsn of the database we are testing var $dsn; //contains the options that should be used during testing var $options; //contains the name of the database we are testing var $database; //contains the MDB2 object of the db once we have connected var $db; // contains field names from the test table var $fields; // contains the types of the fields from the test table var $types; function MDB2_TestCase($name) { $this->PHPUnit_TestCase($name); } function setUp() { $this->dsn = $GLOBALS['dsn']; $this->options = $GLOBALS['options']; $this->database = $GLOBALS['database']; $this->db =& MDB2::factory($this->dsn, $this->options); $this->db->setDatabase($this->database); $this->db->expectError(MDB2_ERROR_UNSUPPORTED); $this->fields = array( 'user_name' => 'text', 'user_password' => 'text', 'subscribed' => 'boolean', 'user_id' => 'integer', 'quota' => 'decimal', 'weight' => 'float', 'access_date' => 'date', 'access_time' => 'time', 'approved' => 'timestamp', ); $this->clearTables(); } function tearDown() { $this->clearTables(); $this->db->popExpect(); unset($this->dsn); if (!PEAR::isError($this->db)) { $this->db->disconnect(); } unset($this->db); } function clearTables() { if (PEAR::isError($this->db->query('DELETE FROM users'))) { $this->assertTrue(false, 'Error deleting from table users'); } if (PEAR::isError($this->db->query('DELETE FROM files'))) { $this->assertTrue(false, 'Error deleting from table users'); } } function supported($feature) { if (!$this->db->supports($feature)) { $this->assertTrue(false, 'This database does not support '.$feature); return false; } return true; } function verifyFetchedValues(&$result, $rownum, &$data) { $row = $result->fetchRow(MDB2_FETCHMODE_DEFAULT, $rownum); reset($row); foreach ($this->fields as $field => $type) { $value = current($row); if ($type == 'float') { $delta = 0.0000000001; } else { $delta = 0; } $this->assertEquals($data[$field], $value, "the value retrieved for field \"$field\" doesn't match what was stored into the row $rownum", $delta); next($row); } } function getSampleData($row) { $data = array(); $data['user_name'] = 'user_' . $row; $data['user_password'] = 'somepassword'; $data['subscribed'] = $row % 2 ? true : false; $data['user_id'] = $row; $data['quota'] = strval($row/100); $data['weight'] = sqrt($row); $data['access_date'] = MDB2_Date::mdbToday(); $data['access_time'] = MDB2_Date::mdbTime(); $data['approved'] = MDB2_Date::mdbNow(); return $data; } function methodExists(&$class, $name) { if (is_object($class) && array_key_exists(strtolower($name), array_change_key_case(array_flip(get_class_methods($class)), CASE_LOWER)) ) { return true; } $this->assertTrue(false, 'method '. $name.' not implemented in '.get_class($class)); return false; } function tableExists($table) { $tables = $this->db->manager->listTables(); return in_array($table, $tables); } } ?>
« previous php.pear.cvs (#35634) next »