diff options
author | mattab <matthieu.aubry@gmail.com> | 2014-09-29 06:49:34 +0400 |
---|---|---|
committer | mattab <matthieu.aubry@gmail.com> | 2014-09-29 06:49:34 +0400 |
commit | 2d6324134f4d490e505122e43605d95de207d1b7 (patch) | |
tree | 01f82ff4483e6bf6e49e103841c930bce8a26ba7 /tests | |
parent | 12c951b32f49817a46af4d743e130712ee1146aa (diff) |
Adding unit test to check that rowCount() really returns matched rows and not only affected/updated rows
Diffstat (limited to 'tests')
-rw-r--r-- | tests/PHPUnit/Integration/Core/Tracker/DbTest.php | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/PHPUnit/Integration/Core/Tracker/DbTest.php b/tests/PHPUnit/Integration/Core/Tracker/DbTest.php new file mode 100644 index 0000000000..6efd6d9665 --- /dev/null +++ b/tests/PHPUnit/Integration/Core/Tracker/DbTest.php @@ -0,0 +1,41 @@ +<?php +/** + * Piwik - free/libre analytics platform + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ +use Piwik\Common; +use Piwik\Db; + +/** + * Tracker DB test + * + * @group Core + */ +class Core_Tracker_DbTest extends DatabaseTestCase +{ + public function test_rowCount_whenUpdating_returnsAllMatchedRowsNotOnlyUpdatedRows() + { + $db = \Piwik\Tracker::getDatabase(); + // insert one record + $db->query("INSERT INTO `" . Common::prefixTable('option') . "` VALUES ('rowid', '1', false)"); + + // We will now UPDATE this table and check rowCount() value + $sqlUpdate = "UPDATE `" . Common::prefixTable('option') . "` SET option_value = 2"; + + // when no record was updated, return 0 + $result = $db->query($sqlUpdate . " WHERE option_name = 'NOT FOUND'"); + $this->assertSame(0, $db->rowCount($result)); + + // when one record was found and updated, returns 1 + $result = $db->query($sqlUpdate . " WHERE option_name = 'rowid'"); + $this->assertSame(1, $db->rowCount($result)); + + // when one record was found but NOT actually updated (as values have not changed), we make sure to return 1 + // testing for MYSQLI_CLIENT_FOUND_ROWS and MYSQL_ATTR_FOUND_ROWS + $result = $db->query($sqlUpdate . " WHERE option_name = 'rowid'"); + $this->assertSame(1, $db->rowCount($result)); + } + +}
\ No newline at end of file |