[Pkg-owncloud-commits] [owncloud] 62/165: Use data provider instead of hand-crafted for loops

David Prévot taffit at moszumanska.debian.org
Thu Apr 23 04:06:28 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch stable8
in repository owncloud.

commit 758b2332f0e5e0487b10fc3f2139e85b40c8152e
Author: Morris Jobke <hey at morrisjobke.de>
Date:   Sat Apr 18 15:19:33 2015 +0200

    Use data provider instead of hand-crafted for loops
    
    * reduces scrutinizer complains
    * uses PHPUnit functionality
---
 tests/lib/db.php | 46 ++++++++++++++++++++++++----------------------
 1 file changed, 24 insertions(+), 22 deletions(-)

diff --git a/tests/lib/db.php b/tests/lib/db.php
index 1fb384c..5c25bfb 100644
--- a/tests/lib/db.php
+++ b/tests/lib/db.php
@@ -261,31 +261,33 @@ class Test_DB extends \Test\TestCase {
 		$this->assertSame($expected, $actual);
 	}
 
-	public function testDecimal() {
+	/**
+	 * Insert, select and delete decimal(12,2) values
+	 * @dataProvider decimalData
+	 */
+	public function testDecimal($insert, $expect) {
 		$table = "*PREFIX*" . $this->table4;
 		$rowname = 'decimaltest';
 
-		// Insert, select and delete decimal(12,2) values
-		$inserts = array('1337133713.37', '1234567890');
-		$expects = array('1337133713.37', '1234567890.00');
-
-		for ($i = 0; $i < count($inserts); $i++) {
-			$insert = $inserts[$i];
-			$expect = $expects[$i];
-
-			$query = OC_DB::prepare('INSERT INTO `' . $table . '` (`' . $rowname . '`) VALUES (?)');
-			$result = $query->execute(array($insert));
-			$this->assertEquals(1, $result);
-			$query = OC_DB::prepare('SELECT `' . $rowname . '` FROM `' . $table . '`');
-			$result = $query->execute();
-			$this->assertTrue((bool)$result);
-			$row = $result->fetchRow();
-			$this->assertArrayHasKey($rowname, $row);
-			$this->assertEquals($expect, $row[$rowname]);
-			$query = OC_DB::prepare('DELETE FROM `' . $table . '`');
-			$result = $query->execute();
-			$this->assertTrue((bool)$result);
-		}
+		$query = OC_DB::prepare('INSERT INTO `' . $table . '` (`' . $rowname . '`) VALUES (?)');
+		$result = $query->execute(array($insert));
+		$this->assertEquals(1, $result);
+		$query = OC_DB::prepare('SELECT `' . $rowname . '` FROM `' . $table . '`');
+		$result = $query->execute();
+		$this->assertTrue((bool)$result);
+		$row = $result->fetchRow();
+		$this->assertArrayHasKey($rowname, $row);
+		$this->assertEquals($expect, $row[$rowname]);
+		$query = OC_DB::prepare('DELETE FROM `' . $table . '`');
+		$result = $query->execute();
+		$this->assertTrue((bool)$result);
+	}
+
+	public function decimalData() {
+		return [
+			['1337133713.37', '1337133713.37'],
+			['1234567890', '1234567890.00'],
+		];
 	}
 
 	public function testUpdateAffectedRowsNoMatch() {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git



More information about the Pkg-owncloud-commits mailing list