cvs: pear /MDB/tests MDB_api_testcase.php MDB_bugs_testcase.php MDB_usage_testcase.php

From: Date: Wed, 30 Oct 2002 15:18:26 +0000
Subject: cvs: pear /MDB/tests MDB_api_testcase.php MDB_bugs_testcase.php MDB_usage_testcase.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-7240@lists.php.net to get a copy of this message
pgc Wed Oct 30 10:18:26 2002 EDT Modified files: /pear/MDB/tests MDB_api_testcase.php MDB_usage_testcase.php MDB_bugs_testcase.php Log: put in a test to make sure were connected the database refactored the methodExists method Index: pear/MDB/tests/MDB_api_testcase.php diff -u pear/MDB/tests/MDB_api_testcase.php:1.6 pear/MDB/tests/MDB_api_testcase.php:1.7 --- pear/MDB/tests/MDB_api_testcase.php:1.6 Sun Oct 27 06:15:36 2002 +++ pear/MDB/tests/MDB_api_testcase.php Wed Oct 30 10:18:26 2002 @@ -41,7 +41,7 @@ // | Author: Paul Cooper <pgc@ucecom.com> | // +----------------------------------------------------------------------+ // -// $Id: MDB_api_testcase.php,v 1.6 2002/10/27 11:15:36 lsmith Exp $ +// $Id: MDB_api_testcase.php,v 1.7 2002/10/30 15:18:26 pgc Exp $ class MDB_Api_TestCase extends PHPUnit_TestCase { //contains the dsn of the database we are testing @@ -62,8 +62,12 @@ $this->dsn = $dsn; $this->database = $database; $this->db =& MDB::connect($dsn, $options); + if (MDB::isError($this->db)) { + print_r($this->db); + $this->assertTrue(FALSE, 'Could not connect to database in setUp'); + exit; + } $this->db->setDatabase($this->database); - $this->fields = array('user_name', 'user_password', 'subscribed', @@ -95,11 +99,11 @@ unset($this->db); } - function methodExists(&$class, $name) { - if (array_key_exists(strtolower($name), array_flip(get_class_methods($class)))) { + function methodExists($name) { + if (array_key_exists(strtolower($name), array_flip(get_class_methods($this->db)))) { return TRUE; } - $this->assertTrue(FALSE, 'method '. $name . ' not implemented in ' . get_class($class)); + $this->assertTrue(FALSE, 'method '. $name . ' not implemented in ' . get_class($this->db)); return FALSE; } @@ -113,27 +117,30 @@ } function testGetOption() { - if ($this->methodExists($this->db, 'getOption')) { - $atc = $this->db->getOption('persistent'); - $this->assertEquals($atc, $this->db->options['persistent']); + if (!$this->methodExists('getOption')) { + return; } + $atc = $this->db->getOption('persistent'); + $this->assertEquals($atc, $this->db->options['persistent']); } function testSetOption() { - if ($this->methodExists($this->db, 'setOption')) { - $option = $this->db->getOption('persistent'); - $this->db->setOption('persistent', !$option); - $this->assertEquals(!$option, $this->db->getOption('persistent')); - $this->db->setOption('persistent', $option); + if (!$this->methodExists($this->db, 'setOption')) { + return; } + $option = $this->db->getOption('persistent'); + $this->db->setOption('persistent', !$option); + $this->assertEquals(!$option, $this->db->getOption('persistent')); + $this->db->setOption('persistent', $option); } function testGetTextValue() { - if ($this->methodExists($this->db, 'getTextValue')) { - $text = "Mr O'Leary"; - $text = $this->db->getTextValue($text); - $this->assertEquals("'Mr O\'Leary'", $text); + if (!$this->methodExists($this->db, 'getTextValue')) { + return; } + $text = "Mr O'Leary"; + $text = $this->db->getTextValue($text); + $this->assertEquals("'Mr O\'Leary'", $text); } function testLoadExtension() { @@ -141,9 +148,10 @@ } function testLoadManager() { - if ($this->methodExists($this->db, 'loadManager')) { - $this->assertTrue(!MDB::isError($this->db->loadManager("Create database"))); + if (!$this->methodExists($this->db, 'loadManager')) { + return; } + $this->assertTrue(!MDB::isError($this->db->loadManager("Create database"))); } // test of the driver @@ -158,24 +166,27 @@ } function testQuery() { - if ($this->methodExists($this->db, 'query')) { - $result = $this->standardQuery(); - $this->assertTrue(is_resource($result), 'query: $result returned is not a resource'); + if (!$this->methodExists($this->db, 'query')) { + return; } + $result = $this->standardQuery(); + $this->assertTrue(is_resource($result), 'query: $result returned is not a resource'); } function testFetch() { - if ($this->methodExists($this->db, 'fetch')) { - $result = $this->standardQuery(); - $this->assertNotNull($this->db->fetch($result, 0, 0)); + if (!$this->methodExists($this->db, 'fetch')) { + return; } + $result = $this->standardQuery(); + $this->assertNotNull($this->db->fetch($result, 0, 0)); } function testNumCols() { - if ($this->methodExists($this->db, 'numCols')) { - $result = $this->standardQuery(); - $this->assertTrue((!MDB::isError($this->db->numCols($result))) && ($this->db->numCols($result) > 0)); + if (!$this->methodExists($this->db, 'numCols')) { + return; } + $result = $this->standardQuery(); + $this->assertTrue((!MDB::isError($this->db->numCols($result))) && ($this->db->numCols($result) > 0)); } } Index: pear/MDB/tests/MDB_usage_testcase.php diff -u pear/MDB/tests/MDB_usage_testcase.php:1.20 pear/MDB/tests/MDB_usage_testcase.php:1.21 --- pear/MDB/tests/MDB_usage_testcase.php:1.20 Sun Oct 27 06:14:15 2002 +++ pear/MDB/tests/MDB_usage_testcase.php Wed Oct 30 10:18:26 2002 @@ -41,7 +41,7 @@ // | Author: Paul Cooper <pgc@ucecom.com> | // +----------------------------------------------------------------------+ // -// $Id: MDB_usage_testcase.php,v 1.20 2002/10/27 11:14:15 lsmith Exp $ +// $Id: MDB_usage_testcase.php,v 1.21 2002/10/30 15:18:26 pgc Exp $ class MDB_Usage_TestCase extends PHPUnit_TestCase { //contains the dsn of the database we are testing @@ -62,6 +62,10 @@ $this->dsn = $dsn; $this->database = $database; $this->db =& MDB::connect($dsn, $options); + if (MDB::isError($this->db)) { + $this->assertTrue(FALSE, 'Could not connect to database in setUp'); + exit; + } $this->db->setDatabase($this->database); $this->fields = array('user_name', 'user_password', @@ -95,11 +99,11 @@ unset($this->db); } - function methodExists(&$class, $name) { - if (array_key_exists(strtolower($name), array_flip(get_class_methods($class)))) { + function methodExists($name) { + if (array_key_exists(strtolower($name), array_flip(get_class_methods($this->db)))) { return TRUE; } - $this->assertTrue(FALSE, 'method '. $name . ' not implemented in ' . get_class($class)); + $this->assertTrue(FALSE, 'method '. $name . ' not implemented in ' . get_class($this->db)); return FALSE; } Index: pear/MDB/tests/MDB_bugs_testcase.php diff -u pear/MDB/tests/MDB_bugs_testcase.php:1.1 pear/MDB/tests/MDB_bugs_testcase.php:1.2 --- pear/MDB/tests/MDB_bugs_testcase.php:1.1 Wed Oct 23 04:37:57 2002 +++ pear/MDB/tests/MDB_bugs_testcase.php Wed Oct 30 10:18:26 2002 @@ -62,6 +62,10 @@ $this->dsn = $dsn; $this->database = $database; $this->db =& MDB::connect($dsn, $options); + if (MDB::isError($this->db)) { + $this->assertTrue(FALSE, 'Could not connect to database in setUp'); + exit; + } $this->db->setDatabase($this->database); $this->fields = array('user_name', 'user_password',

« previous php.pear.cvs (#7240) next »