diff options
Diffstat (limited to 'tests/phpunit/includes/CdbTest.php')
-rw-r--r-- | tests/phpunit/includes/CdbTest.php | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/tests/phpunit/includes/CdbTest.php b/tests/phpunit/includes/CdbTest.php index b5418dd7..e3d9da7c 100644 --- a/tests/phpunit/includes/CdbTest.php +++ b/tests/phpunit/includes/CdbTest.php @@ -3,23 +3,29 @@ /** * Test the CDB reader/writer */ - class CdbTest extends MediaWikiTestCase { - public function setUp() { + protected function setUp() { + parent::setUp(); if ( !CdbReader::haveExtension() ) { $this->markTestSkipped( 'Native CDB support is not available' ); } } + /** + * @group medium + */ public function testCdb() { $dir = wfTempDir(); if ( !is_writable( $dir ) ) { $this->markTestSkipped( "Temp dir isn't writable" ); } - $w1 = new CdbWriter_PHP( "$dir/php.cdb" ); - $w2 = new CdbWriter_DBA( "$dir/dba.cdb" ); + $phpcdbfile = $this->getNewTempFile(); + $dbacdbfile = $this->getNewTempFile(); + + $w1 = new CdbWriter_PHP( $phpcdbfile ); + $w2 = new CdbWriter_DBA( $dbacdbfile ); $data = array(); for ( $i = 0; $i < 1000; $i++ ) { @@ -37,13 +43,13 @@ class CdbTest extends MediaWikiTestCase { $w2->close(); $this->assertEquals( - md5_file( "$dir/dba.cdb" ), - md5_file( "$dir/php.cdb" ), + md5_file( $phpcdbfile ), + md5_file( $dbacdbfile ), 'same hash' ); - $r1 = new CdbReader_PHP( "$dir/php.cdb" ); - $r2 = new CdbReader_DBA( "$dir/dba.cdb" ); + $r1 = new CdbReader_PHP( $phpcdbfile ); + $r2 = new CdbReader_DBA( $dbacdbfile ); foreach ( $data as $key => $value ) { if ( $key === '' ) { @@ -60,9 +66,6 @@ class CdbTest extends MediaWikiTestCase { $this->cdbAssert( "PHP error", $key, $v1, $value ); $this->cdbAssert( "DBA error", $key, $v2, $value ); } - - unlink( "$dir/dba.cdb" ); - unlink( "$dir/php.cdb" ); } private function randomString() { @@ -71,6 +74,7 @@ class CdbTest extends MediaWikiTestCase { for ( $j = 0; $j < $len; $j++ ) { $s .= chr( mt_rand( 0, 255 ) ); } + return $s; } |