diff options
-rw-r--r-- | lib/mysql.php | 121 | ||||
-rw-r--r-- | tests/MySqlShimTest.php | 418 |
2 files changed, 267 insertions, 272 deletions
diff --git a/lib/mysql.php b/lib/mysql.php index f2908a0..0207d1a 100644 --- a/lib/mysql.php +++ b/lib/mysql.php @@ -45,7 +45,7 @@ namespace { $hash = sha1($hostname . $username . $flags); /* persistent connections start with p: */ - if ($hostname{1} != ':' && isset(\Dshafik\MySQL::$connections[$hash])) { + if ($hostname{1} !== ':' && isset(\Dshafik\MySQL::$connections[$hash])) { \Dshafik\MySQL::$last_connection = \Dshafik\MySQL::$connections[$hash]['conn']; \Dshafik\MySQL::$connections[$hash]['refcount'] += 1; return \Dshafik\MySQL::$connections[$hash]['conn']; @@ -126,7 +126,7 @@ namespace { } $return = true; - if (\Dshafik\MySQL::$connections[$link->hash]['refcount'] == 0) { + if (\Dshafik\MySQL::$connections[$link->hash]['refcount'] === 0) { $return = mysqli_close($link); unset(\Dshafik\MySQL::$connections[$link->hash]); } @@ -144,7 +144,7 @@ namespace { return mysqli_query( $link, - "USE `" . mysqli_real_escape_string($link, $databaseName) . "`" + 'USE `' . mysqli_real_escape_string($link, $databaseName) . '`' ) !== false; } @@ -173,14 +173,14 @@ namespace { function mysql_list_dbs(\mysqli $link = null) { - return mysql_query("SHOW DATABASES", $link); + return mysql_query('SHOW DATABASES', $link); } function mysql_list_tables($databaseName, \mysqli $link = null) { $link = \Dshafik\MySQL::getConnection($link); $query = sprintf( - "SHOW TABLES FROM `%s`", + 'SHOW TABLES FROM `%s`', mysql_real_escape_string($databaseName, $link) ); return mysql_query($query, $link); @@ -191,7 +191,7 @@ namespace { $link = \Dshafik\MySQL::getConnection($link); $query = sprintf( - "SHOW COLUMNS FROM `%s`.`%s`", + 'SHOW COLUMNS FROM `%s`.`%s`', mysqli_real_escape_string($link, $databaseName), mysqli_real_escape_string($link, $tableName) ); @@ -203,7 +203,7 @@ namespace { return $result; } - trigger_error("mysql_list_fields(): Unable to save MySQL query result", E_USER_WARNING); + trigger_error('mysql_list_fields(): Unable to save MySQL query result', E_USER_WARNING); // @codeCoverageIgnoreStart return false; // @codeCoverageIgnoreEnd @@ -211,7 +211,7 @@ namespace { function mysql_list_processes(\mysqli $link = null) { - return mysql_query("SHOW PROCESSLIST", $link); + return mysql_query('SHOW PROCESSLIST', $link); } function mysql_error(\mysqli $link = null) @@ -236,7 +236,7 @@ namespace { function mysql_result($result, $row, $field = 0) { - if (\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { + if (!\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { // @codeCoverageIgnoreStart return false; // @codeCoverageIgnoreEnd @@ -245,7 +245,7 @@ namespace { if (!mysqli_data_seek($result, $row)) { trigger_error( sprintf( - "mysql_result(): Unable to jump to row %d on MySQL result index %s", + 'mysql_result(): Unable to jump to row %d on MySQL result index %s', $row, spl_object_hash($result) ), @@ -257,13 +257,13 @@ namespace { } $found = true; - if (strpos($field, ".") !== false) { - list($table, $name) = explode(".", $field); + if (strpos($field, '.') !== false) { + list($table, $name) = explode('.', $field); $i = 0; $found = false; mysqli_field_seek($result, 0); while ($column = mysqli_fetch_field($result)) { - if ($column->table == $table && $column->name == $name) { + if ($column->table === $table && $column->name === $name) { $field = $i; $found = true; break; @@ -279,7 +279,7 @@ namespace { trigger_error( sprintf( - "%s(): %s not found in MySQL result index %s", + '%s(): %s not found in MySQL result index %s', __FUNCTION__, $field, spl_object_hash($result) @@ -293,7 +293,7 @@ namespace { function mysql_num_rows($result) { - if (\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { + if (!\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { // @codeCoverageIgnoreStart return false; // @codeCoverageIgnoreEnd @@ -308,7 +308,7 @@ namespace { function mysql_num_fields($result) { - if (\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { + if (!\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { // @codeCoverageIgnoreStart return false; // @codeCoverageIgnoreEnd @@ -318,7 +318,7 @@ namespace { function mysql_fetch_row($result) { - if (\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { + if (!\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { // @codeCoverageIgnoreStart return false; // @codeCoverageIgnoreEnd @@ -328,7 +328,7 @@ namespace { function mysql_fetch_array($result, $resultType = MYSQL_BOTH) { - if (\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { + if (!\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { // @codeCoverageIgnoreStart return false; // @codeCoverageIgnoreEnd @@ -338,7 +338,7 @@ namespace { function mysql_fetch_assoc($result) /* : array|null */ { - if (\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { + if (!\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { // @codeCoverageIgnoreStart return false; // @codeCoverageIgnoreEnd @@ -349,7 +349,7 @@ namespace { function mysql_fetch_object($result, $class = null, array $params = array()) /* : object|null */ { - if (\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { + if (!\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { // @codeCoverageIgnoreStart return false; // @codeCoverageIgnoreEnd @@ -366,7 +366,7 @@ namespace { function mysql_data_seek($result, $offset) { - if (\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { + if (!\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { // @codeCoverageIgnoreStart return false; // @codeCoverageIgnoreEnd @@ -376,7 +376,7 @@ namespace { function mysql_fetch_lengths($result) /* : array|*/ { - if (\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { + if (!\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { // @codeCoverageIgnoreStart return false; // @codeCoverageIgnoreEnd @@ -386,7 +386,7 @@ namespace { function mysql_fetch_field($result) /* : object|*/ { - if (\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { + if (!\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { // @codeCoverageIgnoreStart return false; // @codeCoverageIgnoreEnd @@ -396,7 +396,7 @@ namespace { function mysql_field_seek($result, $field) { - if (\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { + if (!\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { // @codeCoverageIgnoreStart return false; // @codeCoverageIgnoreEnd @@ -406,7 +406,7 @@ namespace { function mysql_free_result($result) { - if (\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { + if (!\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { // @codeCoverageIgnoreStart return false; // @codeCoverageIgnoreEnd @@ -416,7 +416,7 @@ namespace { function mysql_field_name($result, $field) { - if (\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { + if (!\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { // @codeCoverageIgnoreStart return false; // @codeCoverageIgnoreEnd @@ -426,7 +426,7 @@ namespace { function mysql_field_table($result, $field) { - if (\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { + if (!\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { // @codeCoverageIgnoreStart return false; // @codeCoverageIgnoreEnd @@ -436,7 +436,7 @@ namespace { function mysql_field_len($result, $field) { - if (\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { + if (!\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { // @codeCoverageIgnoreStart return false; // @codeCoverageIgnoreEnd @@ -446,7 +446,7 @@ namespace { function mysql_field_type($result, $field) { - if (\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { + if (!\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { // @codeCoverageIgnoreStart return false; // @codeCoverageIgnoreEnd @@ -456,7 +456,7 @@ namespace { function mysql_field_flags($result, $field) { - if (\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { + if (!\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { // @codeCoverageIgnoreStart return false; // @codeCoverageIgnoreEnd @@ -469,7 +469,7 @@ namespace { if (\Dshafik\MySQL::$last_connection === null) { trigger_error( sprintf( - "%s() is insecure; use mysql_real_escape_string() instead!", + '%s() is insecure; use mysql_real_escape_string() instead!', __FUNCTION__ ), E_USER_NOTICE @@ -537,7 +537,7 @@ namespace { function mysql_db_name($result, $row, $field = 0) { - if (\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { + if (!\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { // @codeCoverageIgnoreStart return false; // @codeCoverageIgnoreEnd @@ -549,7 +549,7 @@ namespace { function mysql_tablename($result, $row) { - if (\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { + if (!\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { // @codeCoverageIgnoreStart return false; // @codeCoverageIgnoreEnd @@ -647,9 +647,9 @@ namespace Dshafik { } if (static::$last_connection === null) { - $err = "A link to the server could not be established"; + $err = 'A link to the server could not be established'; if ($func !== null) { - $err = $func . "(): no MySQL-Link resource supplied"; + $err = $func . '(): no MySQL-Link resource supplied'; } trigger_error($err, E_USER_WARNING); return false; @@ -665,7 +665,7 @@ namespace Dshafik { } catch (\Exception $e) { trigger_error( sprintf( - "mysql_field_%s(): Field %d is invalid for MySQL result index %s", + 'mysql_field_%s(): Field %d is invalid for MySQL result index %s', $what, $field, spl_object_hash($result) @@ -678,19 +678,19 @@ namespace Dshafik { // @codeCoverageIgnoreEnd } - if ($what == 'name' || $what == 'table') { + if ($what === 'name' || $what === 'table') { return $field->{$what}; } - if ($what == 'len') { + if ($what === 'len') { return $field->length; } - if ($what == 'type') { + if ($what === 'type') { return static::getFieldType($field->type); } - if ($what == 'flags') { + if ($what === 'flags') { return static::getFieldFlags($field->flags); } @@ -700,28 +700,29 @@ namespace Dshafik { public static function checkValidResult($result, $function) { if (!($result instanceof \mysqli_result)) { - if ($function != "mysql_fetch_object") { + if ($function !== 'mysql_fetch_object') { trigger_error( - $function . "() expects parameter 1 to be resource, " . strtolower(gettype($result)) . " given", + $function . '() expects parameter 1 to be resource, ' . strtolower(gettype($result)) . ' given', E_USER_WARNING ); } - if ($function == "mysql_fetch_object") { + if ($function === 'mysql_fetch_object') { trigger_error( - $function . "(): supplied argument is not a valid MySQL result resource", + $function . '(): supplied argument is not a valid MySQL result resource', E_USER_WARNING ); } return false; } + return true; } public static function escapeString($unescapedString) { - $escapedString = ""; - for ($i = 0; $i < strlen($unescapedString); $i++) { + $escapedString = ''; + for ($i = 0, $max = strlen($unescapedString); $i < $max; $i++) { $escapedString .= self::escapeChar($unescapedString{$i}); } @@ -732,18 +733,18 @@ namespace Dshafik { { // Order of flags taken from http://lxr.php.net/xref/PHP_5_6/ext/mysql/php_mysql.c#2507 $flags = array( - MYSQLI_NOT_NULL_FLAG => "not_null", - MYSQLI_PRI_KEY_FLAG => "primary_key", - MYSQLI_UNIQUE_KEY_FLAG => "unique_key", - MYSQLI_MULTIPLE_KEY_FLAG => "multiple_key", - MYSQLI_BLOB_FLAG => "blob", - MYSQLI_UNSIGNED_FLAG => "unsigned", - MYSQLI_ZEROFILL_FLAG => "zerofill", - MYSQLI_BINARY_FLAG => "binary", - MYSQLI_ENUM_FLAG => "enum", - MYSQLI_SET_FLAG => "set", - MYSQLI_AUTO_INCREMENT_FLAG => "auto_increment", - MYSQLI_TIMESTAMP_FLAG => "timestamp", + MYSQLI_NOT_NULL_FLAG => 'not_null', + MYSQLI_PRI_KEY_FLAG => 'primary_key', + MYSQLI_UNIQUE_KEY_FLAG => 'unique_key', + MYSQLI_MULTIPLE_KEY_FLAG => 'multiple_key', + MYSQLI_BLOB_FLAG => 'blob', + MYSQLI_UNSIGNED_FLAG => 'unsigned', + MYSQLI_ZEROFILL_FLAG => 'zerofill', + MYSQLI_BINARY_FLAG => 'binary', + MYSQLI_ENUM_FLAG => 'enum', + MYSQLI_SET_FLAG => 'set', + MYSQLI_AUTO_INCREMENT_FLAG => 'auto_increment', + MYSQLI_TIMESTAMP_FLAG => 'timestamp', ); $fieldFlags = array(); @@ -753,7 +754,7 @@ namespace Dshafik { } } - return implode(" ", $fieldFlags); + return implode(' ', $fieldFlags); } protected static function getFieldType($what) @@ -793,7 +794,7 @@ namespace Dshafik { MYSQLI_TYPE_GEOMETRY => 'geometry', ); - return isset($types[$what]) ? $types[$what] : "unknown"; + return isset($types[$what]) ? $types[$what] : 'unknown'; } protected static function escapeChar($char) diff --git a/tests/MySqlShimTest.php b/tests/MySqlShimTest.php index 7ffb704..3bb34cf 100644 --- a/tests/MySqlShimTest.php +++ b/tests/MySqlShimTest.php @@ -62,12 +62,12 @@ class MySqlShimTest extends \PHPUnit_Framework_TestCase */ public function test_mysql_connect_fail_warning() { - $mysql = mysql_connect(static::$host, "baduser", "badpass"); + mysql_connect(static::$host, 'baduser', 'badpass'); } public function test_mysql_connect_fail_false() { - $mysql = @mysql_connect(static::$host, "baduser", "badpass"); + $mysql = @mysql_connect(static::$host, 'baduser', 'badpass'); $this->assertFalse($mysql); } @@ -78,7 +78,7 @@ class MySqlShimTest extends \PHPUnit_Framework_TestCase */ public function test_mysql_connect_new() { - $mysql = mysql_connect(static::$host, 'root', null, true); + mysql_connect(static::$host, 'root', null, true); } public function test_mysql_connect_options() @@ -93,7 +93,7 @@ class MySqlShimTest extends \PHPUnit_Framework_TestCase */ public function test_mysql_connect_options_fail() { - mysql_connect(static::$host, "baduser", "badpass", false, MYSQL_CLIENT_COMPRESS); + mysql_connect(static::$host, 'baduser', 'badpass', false, MYSQL_CLIENT_COMPRESS); } public function test_mysql_connect_multi() @@ -105,11 +105,11 @@ class MySqlShimTest extends \PHPUnit_Framework_TestCase $this->assertEquals($conn, $conn2); - $result = mysql_query("SELECT CONNECTION_ID()", $conn); + $result = mysql_query('SELECT CONNECTION_ID()', $conn); $row = mysql_fetch_row($result); $id = $row[0]; - $result = mysql_query("SELECT CONNECTION_ID()", $conn2); + $result = mysql_query('SELECT CONNECTION_ID()', $conn2); $row = mysql_fetch_row($result); $id2 = $row[0]; @@ -145,14 +145,14 @@ class MySqlShimTest extends \PHPUnit_Framework_TestCase public function test_mysql_query_ddl() { - $conn = mysql_connect(static::$host, 'root'); - $result = mysql_query("CREATE DATABASE IF NOT EXISTS shim_test"); + mysql_connect(static::$host, 'root'); + $result = mysql_query('CREATE DATABASE IF NOT EXISTS shim_test'); $this->assertTrue($result, mysql_error()); } public function test_mysql_query_insert() { - $this->getConnection("shim_test"); + $this->getConnection('shim_test'); $result = mysql_query( "INSERT INTO testing (one, two, three, four, five, six, seven, eight, nine, ten, eleven) @@ -180,15 +180,15 @@ class MySqlShimTest extends \PHPUnit_Framework_TestCase public function test_mysql_query() { - $this->getConnection("shim_test"); - $result = mysql_query("SELECT VERSION()"); + $this->getConnection('shim_test'); + $result = mysql_query('SELECT VERSION()'); $this->assertResult($result); } public function test_mysql_query_nodata() { - $this->getConnection("shim_test"); + $this->getConnection('shim_test'); $result = mysql_query("SET @test = 'foo'"); $this->assertTrue($result); @@ -196,17 +196,17 @@ class MySqlShimTest extends \PHPUnit_Framework_TestCase public function test_mysql_query_fail() { - $this->getConnection("shim_test"); - $result = mysql_query("SELECT VERSION("); + $this->getConnection('shim_test'); + $result = mysql_query('SELECT VERSION('); $this->assertFalse($result); } public function test_mysql_unbuffered_query() { - $this->getConnection("shim_test"); + $this->getConnection('shim_test'); - $result = mysql_unbuffered_query("SELECT one, two FROM testing LIMIT 4"); + $result = mysql_unbuffered_query('SELECT one, two FROM testing LIMIT 4'); $this->assertResult($result); $i = 0; while ($row = mysql_fetch_assoc($result)) { @@ -214,7 +214,7 @@ class MySqlShimTest extends \PHPUnit_Framework_TestCase } $this->assertEquals(4, $i); - $result = mysql_query("SELECT one, two FROM testing LIMIT 4"); + $result = mysql_query('SELECT one, two FROM testing LIMIT 4'); $this->assertResult($result); } @@ -222,15 +222,15 @@ class MySqlShimTest extends \PHPUnit_Framework_TestCase { $this->getConnection(); - $result = mysql_unbuffered_query("SELECT VERSION("); + $result = mysql_unbuffered_query('SELECT VERSION('); $this->assertFalse($result); } public function test_mysql_unbuffered_query_num_rows() { - $this->getConnection("shim_test"); + $this->getConnection('shim_test'); - $result = mysql_unbuffered_query("SELECT one, two FROM testing"); + $result = mysql_unbuffered_query('SELECT one, two FROM testing'); $this->assertResult($result); $this->assertEquals(0, mysql_num_rows($result)); mysql_free_result($result); @@ -242,18 +242,18 @@ class MySqlShimTest extends \PHPUnit_Framework_TestCase public function test_mysql_unbuffered_query_close_legacy() { if (!version_compare(PHP_VERSION, '7.0.0', '<')) { - $this->markTestIncomplete("PHP < 7.0.0 is required"); + $this->markTestIncomplete('PHP < 7.0.0 is required'); } - $conn = $this->getConnection("shim_test"); + $conn = $this->getConnection('shim_test'); - $result = mysql_unbuffered_query("SELECT one, two FROM testing"); + $result = mysql_unbuffered_query('SELECT one, two FROM testing'); $this->assertResult($result); try { mysql_close($conn); } catch (\PHPUnit_Framework_Error_Notice $e) { $this->assertEquals( - "mysql_close(): Function called without first fetching all rows from a previous unbuffered query", + 'mysql_close(): Function called without first fetching all rows from a previous unbuffered query', $e->getMessage() ); } @@ -264,8 +264,8 @@ class MySqlShimTest extends \PHPUnit_Framework_TestCase */ public function test_mysql_unbuffered_query_close() { - $conn = $this->getConnection("shim_test"); - $result = mysql_unbuffered_query("SELECT one, two FROM testing"); + $conn = $this->getConnection('shim_test'); + $result = mysql_unbuffered_query('SELECT one, two FROM testing'); $this->assertResult($result); mysql_close($conn); } @@ -275,14 +275,14 @@ class MySqlShimTest extends \PHPUnit_Framework_TestCase $this->skipForHHVM(); $this->getConnection(); - $result = mysql_db_query("shim_test", "SELECT DATABASE()"); + $result = mysql_db_query('shim_test', 'SELECT DATABASE()'); $this->assertResult($result); $rows = mysql_fetch_row($result); - $this->assertEquals("shim_test", $rows[0]); - $result = mysql_db_query("mysql", "SELECT DATABASE()"); + $this->assertEquals('shim_test', $rows[0]); + $result = mysql_db_query('mysql', 'SELECT DATABASE()'); $this->assertResult($result); $rows = mysql_fetch_row($result); - $this->assertEquals("mysql", $rows[0]); + $this->assertEquals('mysql', $rows[0]); } public function test_mysql_db_query_fail() @@ -290,13 +290,13 @@ class MySqlShimTest extends \PHPUnit_Framework_TestCase $this->skipForHHVM(); $this->getConnection(); - $result = mysql_db_query("nonexistent", "SELECT DATABASE()"); + $result = mysql_db_query('nonexistent', 'SELECT DATABASE()'); $this->assertFalse($result); } public function test_mysql_insert_id() { - $this->getConnection("shim_test"); + $this->getConnection('shim_test'); $result = mysql_query( "INSERT INTO testing (id, one, two, three, four, five, six, seven, eight, nine, ten, eleven) @@ -312,18 +312,18 @@ class MySqlShimTest extends \PHPUnit_Framework_TestCase $result = mysql_list_dbs(); $this->assertResult($result); while ($row = mysql_fetch_assoc($result)) { - $this->assertArrayHasKey("Database", $row); + $this->assertArrayHasKey('Database', $row); } } public function test_mysql_list_tables() { $this->getConnection(); - $result = mysql_list_tables("mysql"); + $result = mysql_list_tables('mysql'); $this->assertResult($result); while ($row = mysql_fetch_assoc($result)) { - $this->assertArrayHasKey("Tables_in_mysql", $row); + $this->assertArrayHasKey('Tables_in_mysql', $row); } } @@ -335,7 +335,7 @@ class MySqlShimTest extends \PHPUnit_Framework_TestCase $this->skipForHHVM(); $this->getConnection(); - $result = mysql_list_tables("nonexistent"); + $result = mysql_list_tables('nonexistent'); $this->assertFalse($result); } @@ -348,7 +348,7 @@ class MySqlShimTest extends \PHPUnit_Framework_TestCase $i = 0; while ($row = mysql_fetch_assoc($result)) { $i++; - $this->assertArrayHasKey("Tables_in_shim-test", $row); + $this->assertArrayHasKey('Tables_in_shim-test', $row); } $this->assertEquals(2, $i); } @@ -362,9 +362,7 @@ class MySqlShimTest extends \PHPUnit_Framework_TestCase $mysql = $this->getConnection(); - $sql = "SHOW CREATE TABLE testing"; - - $result = mysql_list_fields("shim_test", "testing", $mysql); + $result = mysql_list_fields('shim_test', 'testing', $mysql); $this->assertResult($result); $i = 0; @@ -385,8 +383,6 @@ class MySqlShimTest extends \PHPUnit_Framework_TestCase } $this->assertEquals(12, $i); - - return; } /** @@ -398,7 +394,7 @@ class MySqlShimTest extends \PHPUnit_Framework_TestCase $this->getConnection('shim-test'); - $result = mysql_query( + mysql_query( "CREATE TABLE IF NOT EXISTS `testing-3` ( id int AUTO_INCREMENT, one varchar(255), @@ -422,7 +418,7 @@ class MySqlShimTest extends \PHPUnit_Framework_TestCase ) CHARACTER SET latin1;" ); - $result = mysql_list_fields("shim-test", "testing-3"); + $result = mysql_list_fields('shim-test', 'testing-3'); $this->assertResult($result); $i = 0; @@ -442,8 +438,6 @@ class MySqlShimTest extends \PHPUnit_Framework_TestCase } $this->assertEquals(12, $i); - - return; } public function test_mysql_list_fields_fail() @@ -452,7 +446,7 @@ class MySqlShimTest extends \PHPUnit_Framework_TestCase try { $this->getConnection(); - mysql_list_fields("shim_test", "nonexistent"); + mysql_list_fields('shim_test', 'nonexistent'); } catch (\Exception $e) { $this->assertInstanceOf('\PHPUnit_Framework_Error_Warning', $e); $this->assertEquals('mysql_list_fields(): Unable to save MySQL query result', $e->getMessage()); @@ -461,80 +455,80 @@ class MySqlShimTest extends \PHPUnit_Framework_TestCase public function test_mysql_field() { - $this->getConnection("shim_test"); - $result = mysql_query("SELECT * FROM testing LIMIT 1"); + $this->getConnection('shim_test'); + $result = mysql_query('SELECT * FROM testing LIMIT 1'); - $this->assertEquals("testing", mysql_field_table($result, 0)); - $this->assertEquals("id", mysql_field_name($result, 0)); - $this->assertEquals("int", mysql_field_type($result, 0)); + $this->assertEquals('testing', mysql_field_table($result, 0)); + $this->assertEquals('id', mysql_field_name($result, 0)); + $this->assertEquals('int', mysql_field_type($result, 0)); $this->assertEquals(11, mysql_field_len($result, 0)); - $this->assertEquals("not_null primary_key auto_increment", mysql_field_flags($result, 0)); + $this->assertEquals('not_null primary_key auto_increment', mysql_field_flags($result, 0)); - $this->assertEquals("testing", mysql_field_table($result, 1)); - $this->assertEquals("one", mysql_field_name($result, 1)); - $this->assertEquals("string", mysql_field_type($result, 1)); + $this->assertEquals('testing', mysql_field_table($result, 1)); + $this->assertEquals('one', mysql_field_name($result, 1)); + $this->assertEquals('string', mysql_field_type($result, 1)); $this->assertEquals(255, mysql_field_len($result, 1)); - $this->assertEquals("multiple_key", mysql_field_flags($result, 1)); + $this->assertEquals('multiple_key', mysql_field_flags($result, 1)); - $this->assertEquals("testing", mysql_field_table($result, 2)); - $this->assertEquals("two", mysql_field_name($result, 2)); - $this->assertEquals("string", mysql_field_type($result, 2)); + $this->assertEquals('testing', mysql_field_table($result, 2)); + $this->assertEquals('two', mysql_field_name($result, 2)); + $this->assertEquals('string', mysql_field_type($result, 2)); $this->assertEquals(255, mysql_field_len($result, 2)); - $this->assertEquals("unique_key", mysql_field_flags($result, 2)); + $this->assertEquals('unique_key', mysql_field_flags($result, 2)); - $this->assertEquals("testing", mysql_field_table($result, 3)); - $this->assertEquals("three", mysql_field_name($result, 3)); - $this->assertEquals("string", mysql_field_type($result, 3)); + $this->assertEquals('testing', mysql_field_table($result, 3)); + $this->assertEquals('three', mysql_field_name($result, 3)); + $this->assertEquals('string', mysql_field_type($result, 3)); $this->assertEquals(255, mysql_field_len($result, 3)); - $this->assertEquals("multiple_key", mysql_field_flags($result, 3)); + $this->assertEquals('multiple_key', mysql_field_flags($result, 3)); - $this->assertEquals("testing", mysql_field_table($result, 4)); - $this->assertEquals("four", mysql_field_name($result, 4)); - $this->assertEquals("string", mysql_field_type($result, 4)); + $this->assertEquals('testing', mysql_field_table($result, 4)); + $this->assertEquals('four', mysql_field_name($result, 4)); + $this->assertEquals('string', mysql_field_type($result, 4)); $this->assertEquals(255, mysql_field_len($result, 4)); - $this->assertEquals("multiple_key", mysql_field_flags($result, 4)); + $this->assertEquals('multiple_key', mysql_field_flags($result, 4)); - $this->assertEquals("testing", mysql_field_table($result, 5)); - $this->assertEquals("five", mysql_field_name($result, 5)); - $this->assertEquals("string", mysql_field_type($result, 5)); + $this->assertEquals('testing', mysql_field_table($result, 5)); + $this->assertEquals('five', mysql_field_name($result, 5)); + $this->assertEquals('string', mysql_field_type($result, 5)); $this->assertEquals(255, mysql_field_len($result, 5)); $this->assertEmpty(mysql_field_flags($result, 5)); - $this->assertEquals("testing", mysql_field_table($result, 6)); - $this->assertEquals("six", mysql_field_name($result, 6)); - $this->assertEquals("string", mysql_field_type($result, 6)); + $this->assertEquals('testing', mysql_field_table($result, 6)); + $this->assertEquals('six', mysql_field_name($result, 6)); + $this->assertEquals('string', mysql_field_type($result, 6)); $this->assertEquals(255, mysql_field_len($result, 6)); $this->assertEmpty(mysql_field_flags($result, 6)); - $this->assertEquals("testing", mysql_field_table($result, 7)); - $this->assertEquals("seven", mysql_field_name($result, 7)); - $this->assertEquals("string", mysql_field_type($result, 7)); + $this->assertEquals('testing', mysql_field_table($result, 7)); + $this->assertEquals('seven', mysql_field_name($result, 7)); + $this->assertEquals('string', mysql_field_type($result, 7)); $this->assertEquals(255, mysql_field_len($result, 7)); - $this->assertEquals("multiple_key", mysql_field_flags($result, 7)); + $this->assertEquals('multiple_key', mysql_field_flags($result, 7)); - $this->assertEquals("testing", mysql_field_table($result, 8)); - $this->assertEquals("eight", mysql_field_name($result, 8)); - $this->assertEquals("string", mysql_field_type($result, 8)); + $this->assertEquals('testing', mysql_field_table($result, 8)); + $this->assertEquals('eight', mysql_field_name($result, 8)); + $this->assertEquals('string', mysql_field_type($result, 8)); $this->assertEquals(255, mysql_field_len($result, 8)); $this->assertEmpty(mysql_field_flags($result, 8)); - $this->assertEquals("testing", mysql_field_table($result, 9)); - $this->assertEquals("nine", mysql_field_name($result, 9)); - $this->assertEquals("string", mysql_field_type($result, 9)); + $this->assertEquals('testing', mysql_field_table($result, 9)); + $this->assertEquals('nine', mysql_field_name($result, 9)); + $this->assertEquals('string', mysql_field_type($result, 9)); $this->assertEquals(6, mysql_field_len($result, 9)); - $this->assertEquals("enum", mysql_field_flags($result, 9)); + $this->assertEquals('enum', mysql_field_flags($result, 9)); - $this->assertEquals("testing", mysql_field_table($result, 10)); - $this->assertEquals("ten", mysql_field_name($result, 10)); - $this->assertEquals("string", mysql_field_type($result, 10)); + $this->assertEquals('testing', mysql_field_table($result, 10)); + $this->assertEquals('ten', mysql_field_name($result, 10)); + $this->assertEquals('string', mysql_field_type($result, 10)); $this->assertEquals(15, mysql_field_len($result, 10)); - $this->assertEquals("set", mysql_field_flags($result, 10)); + $this->assertEquals('set', mysql_field_flags($result, 10)); - $this->assertEquals("testing", mysql_field_table($result, 11)); - $this->assertEquals("eleven", mysql_field_name($result, 11)); - $this->assertEquals("blob", mysql_field_type($result, 11)); + $this->assertEquals('testing', mysql_field_table($result, 11)); + $this->assertEquals('eleven', mysql_field_name($result, 11)); + $this->assertEquals('blob', mysql_field_type($result, 11)); $this->assertEquals(16777215, mysql_field_len($result, 11)); - $this->assertEquals("blob", mysql_field_flags($result, 11)); + $this->assertEquals('blob', mysql_field_flags($result, 11)); } /** @@ -543,10 +537,10 @@ class MySqlShimTest extends \PHPUnit_Framework_TestCase */ public function test_mysql_field_name_fail() { - $this->getConnection("shim_test"); - $result = mysql_query("SELECT * FROM testing LIMIT 1"); + $this->getConnection('shim_test'); + $result = mysql_query('SELECT * FROM testing LIMIT 1'); - $this->assertEquals("testing", mysql_field_name($result, 999)); + $this->assertEquals('testing', mysql_field_name($result, 999)); } /** @@ -555,10 +549,10 @@ class MySqlShimTest extends \PHPUnit_Framework_TestCase */ public function test_mysql_field_table_fail() { - $this->getConnection("shim_test"); - $result = mysql_query("SELECT * FROM testing LIMIT 1"); + $this->getConnection('shim_test'); + $result = mysql_query('SELECT * FROM testing LIMIT 1'); - $this->assertEquals("testing", mysql_field_table($result, 999)); + $this->assertEquals('testing', mysql_field_table($result, 999)); } /** @@ -567,10 +561,10 @@ class MySqlShimTest extends \PHPUnit_Framework_TestCase */ public function test_mysql_field_type_fail() { - $this->getConnection("shim_test"); - $result = mysql_query("SELECT * FROM testing LIMIT 1"); + $this->getConnection('shim_test'); + $result = mysql_query('SELECT * FROM testing LIMIT 1'); - $this->assertEquals("testing", mysql_field_type($result, 999)); + $this->assertEquals('testing', mysql_field_type($result, 999)); } /** @@ -579,10 +573,10 @@ class MySqlShimTest extends \PHPUnit_Framework_TestCase */ public function test_mysql_field_len_fail() { - $this->getConnection("shim_test"); - $result = mysql_query("SELECT * FROM testing LIMIT 1"); + $this->getConnection('shim_test'); + $result = mysql_query('SELECT * FROM testing LIMIT 1'); - $this->assertEquals("testing", mysql_field_len($result, 999)); + $this->assertEquals('testing', mysql_field_len($result, 999)); } /** @@ -591,16 +585,16 @@ class MySqlShimTest extends \PHPUnit_Framework_TestCase */ public function test_mysql_field_flags_fail() { - $this->getConnection("shim_test"); - $result = mysql_query("SELECT * FROM testing LIMIT 1"); + $this->getConnection('shim_test'); + $result = mysql_query('SELECT * FROM testing LIMIT 1'); - $this->assertEquals("testing", mysql_field_flags($result, 999)); + $this->assertEquals('testing', mysql_field_flags($result, 999)); } public function test_mysql_num_fields() { $this->getConnection('shim_test'); - $result = mysql_query("SELECT one, two FROM testing LIMIT 1"); + $result = mysql_query('SELECT one, two FROM testing LIMIT 1'); $this->assertResult($result); $this->assertEquals(2, mysql_num_fields($result)); @@ -613,7 +607,7 @@ class MySqlShimTest extends \PHPUnit_Framework_TestCase public function test_mysql_num_fields_fail() { $this->getConnection('shim_test'); - $result = mysql_query("SELECT one, two FROM nonexistent"); + $result = mysql_query('SELECT one, two FROM nonexistent'); mysql_num_fields($result); } @@ -642,12 +636,12 @@ class MySqlShimTest extends \PHPUnit_Framework_TestCase */ public function test_mysql_fetch($function, $results, $resultType = null) { - $this->getConnection("shim_test"); + $this->getConnection('shim_test'); - $result = mysql_query("SELECT one, two FROM testing LIMIT 4"); + $result = mysql_query('SELECT one, two FROM testing LIMIT 4'); $this->assertResult($result); - $this->assertEquals(sizeof($results), mysql_num_rows($result)); + $this->assertEquals(count($results), mysql_num_rows($result)); $function = function ($result) use ($function, $resultType) { if ($resultType) { @@ -662,7 +656,7 @@ class MySqlShimTest extends \PHPUnit_Framework_TestCase $i++; } - $this->assertEquals(sizeof($results), $i); + $this->assertEquals(count($results), $i); } /** @@ -670,7 +664,7 @@ class MySqlShimTest extends \PHPUnit_Framework_TestCase */ public function test_mysql_fetch_no_rows($function) { - $this->getConnection("shim_test"); + $this->getConnection('shim_test'); $result = mysql_query("SELECT * FROM testing WHERE one = 'fail'"); $this->assertResult($result); @@ -680,21 +674,21 @@ class MySqlShimTest extends \PHPUnit_Framework_TestCase public function test_mysql_num_rows() { - $this->getConnection("shim_test"); + $this->getConnection('shim_test'); - $result = mysql_query("SELECT * FROM testing LIMIT 4"); + $result = mysql_query('SELECT * FROM testing LIMIT 4'); $this->assertResult($result); $this->assertEquals(4, mysql_num_rows($result)); } public function test_mysql_affected_rows() { - $this->getConnection("shim_test"); + $this->getConnection('shim_test'); - $result = mysql_query("UPDATE testing SET one = one + 1000, two = two + 1000 ORDER BY one DESC LIMIT 4"); + $result = mysql_query('UPDATE testing SET one = one + 1000, two = two + 1000 ORDER BY one DESC LIMIT 4'); $this->assertTrue($result); $this->assertEquals(4, mysql_affected_rows()); - $result = mysql_query("UPDATE testing SET one = one - 1000, two = two - 1000 ORDER BY one DESC LIMIT 4"); + $result = mysql_query('UPDATE testing SET one = one - 1000, two = two - 1000 ORDER BY one DESC LIMIT 4'); $this->assertTrue($result, mysql_error()); $this->assertEquals(4, mysql_affected_rows()); } @@ -703,10 +697,10 @@ class MySqlShimTest extends \PHPUnit_Framework_TestCase { $this->getConnection(); - $result = mysql_query("SELECT one, two AS aliased FROM testing"); + $result = mysql_query('SELECT one, two AS aliased FROM testing'); $this->assertResult($result); - for($i = 0; $i < mysql_num_rows($result); $i++) { + for($i = 0, $max = mysql_num_rows($result); $i < $max; $i++) { $this->assertEquals($i+1, mysql_result($result, $i, 0)); $this->assertEquals($i+1, mysql_result($result, $i, 'one')); $this->assertEquals($i+1, mysql_result($result, $i, 1)); @@ -722,21 +716,21 @@ class MySqlShimTest extends \PHPUnit_Framework_TestCase { $this->getConnection(); - $result = mysql_query("SELECT one, two FROM testing LIMIT 1"); + $result = mysql_query('SELECT one, two FROM testing LIMIT 1'); $this->assertResult($result); - mysql_result($result, 0, "three"); + mysql_result($result, 0, 'three'); } public function test_mysql_result_prefixed() { $this->getConnection(); - $result = mysql_query("SELECT one, two FROM testing LIMIT 1"); + $result = mysql_query('SELECT one, two FROM testing LIMIT 1'); $this->assertResult($result); - $this->assertEquals(1, mysql_result($result, 0, "testing.one")); - $this->assertEquals(1, mysql_result($result, 0, "testing.two")); + $this->assertEquals(1, mysql_result($result, 0, 'testing.one')); + $this->assertEquals(1, mysql_result($result, 0, 'testing.two')); } /** @@ -747,10 +741,10 @@ class MySqlShimTest extends \PHPUnit_Framework_TestCase { $this->getConnection(); - $result = mysql_query("SELECT one, two FROM testing LIMIT 1"); + $result = mysql_query('SELECT one, two FROM testing LIMIT 1'); $this->assertResult($result); - mysql_result($result, 0, "testing.three"); + mysql_result($result, 0, 'testing.three'); } /** @@ -761,7 +755,7 @@ class MySqlShimTest extends \PHPUnit_Framework_TestCase { $this->getConnection(); - $result = mysql_query("SELECT one FROM testing LIMIT 1"); + $result = mysql_query('SELECT one FROM testing LIMIT 1'); $this->assertResult($result); mysql_result($result, 1, 0); @@ -774,7 +768,7 @@ class MySqlShimTest extends \PHPUnit_Framework_TestCase { $this->getConnection(); - $result = mysql_query("SELECT * FROM testing LIMIT 1"); + $result = mysql_query('SELECT * FROM testing LIMIT 1'); $this->assertResult($result); $this->assertEquals(1, mysql_result($result, 0, 'testing.one')); @@ -795,7 +789,7 @@ class MySqlShimTest extends \PHPUnit_Framework_TestCase mysql_close(); } catch (\Exception $e) { $this->assertInstanceOf('\PHPUnit_Framework_Error_Warning', $e); - $this->assertEquals("mysql_close(): no MySQL-Link resource supplied", $e->getMessage()); + $this->assertEquals('mysql_close(): no MySQL-Link resource supplied', $e->getMessage()); } } @@ -805,7 +799,7 @@ class MySqlShimTest extends \PHPUnit_Framework_TestCase $this->assertEmpty(mysql_error()); - $result = mysql_query("SELECT VERSION("); + $result = mysql_query('SELECT VERSION('); $this->assertFalse($result); $this->assertRegExp( @@ -819,7 +813,7 @@ class MySqlShimTest extends \PHPUnit_Framework_TestCase $this->assertEmpty(mysql_errno()); - $result = mysql_query("SELECT VERSION("); + $result = mysql_query('SELECT VERSION('); $this->assertFalse($result); $this->assertEquals(1064, mysql_errno()); @@ -863,7 +857,7 @@ class MySqlShimTest extends \PHPUnit_Framework_TestCase public function test_mysql_db_name() { - $conn = $this->getConnection(); + $this->getConnection(); $dbs = mysql_list_dbs(); $this->assertEquals('information_schema', mysql_db_name($dbs, 0)); } @@ -883,22 +877,22 @@ class MySqlShimTest extends \PHPUnit_Framework_TestCase static::markTestSkipped('Docker is required to run these tests'); } - fwrite(STDERR, "=> Running Docker Container: "); + fwrite(STDERR, '=> Running Docker Container: '); static::$container = exec($docker . ' run -e MYSQL_ALLOW_EMPTY_PASSWORD=1 -P -d mysql/mysql-server:5.7'); if (empty(static::$container)) { - static::markTestSkipped("Unable to start docker container"); + static::markTestSkipped('Unable to start docker container'); } fwrite(STDERR, static::$container . "\n"); - fwrite(STDERR, "=> Finding MySQL Host: "); + fwrite(STDERR, '=> Finding MySQL Host: '); static::$host = exec($docker . ' port ' . self::$container . ' 3306'); fwrite(STDERR, static::$host . "\n"); - fwrite(STDERR, "=> Waiting on mysqld to start:"); + fwrite(STDERR, '=> Waiting on mysqld to start:'); $out = ''; - while (trim($out) != 'mysqld') { + while (trim($out) !== 'mysqld') { $out = exec(static::$bin['docker'] . ' exec ' . static::$container . ' ps ax | awk \'/mysqld/ {print $NF}\''); } fwrite(STDERR, " started\n"); @@ -933,9 +927,9 @@ class MySqlShimTest extends \PHPUnit_Framework_TestCase return; } - mysql_connect(static::$host, "root"); - mysql_query("DROP DATABASE IF EXISTS shim_test"); - mysql_query("DROP DATABASE IF EXISTS `shim-test`"); + mysql_connect(static::$host, 'root'); + mysql_query('DROP DATABASE IF EXISTS shim_test'); + mysql_query('DROP DATABASE IF EXISTS `shim-test`'); } public function mysql_fetch_DataProvider() @@ -1021,103 +1015,103 @@ class MySqlShimTest extends \PHPUnit_Framework_TestCase { return array( array( - "function" => "mysql_result", - "message" => "mysql_result\(\) expects parameter 1 to be resource, (null|NULL) given", - "args" => array(0) + 'function' => 'mysql_result', + 'message' => "mysql_result\(\) expects parameter 1 to be resource, (null|NULL) given", + 'args' => array(0) ), array( - "function" => "mysql_num_rows", - "message" => "mysql_num_rows\(\) expects parameter 1 to be resource, (null|NULL) given", - "args" => array(), + 'function' => 'mysql_num_rows', + 'message' => "mysql_num_rows\(\) expects parameter 1 to be resource, (null|NULL) given", + 'args' => array(), ), array( - "function" => "mysql_num_fields", - "message" => "mysql_num_fields\(\) expects parameter 1 to be resource, (null|NULL) given", - "args" => array(), + 'function' => 'mysql_num_fields', + 'message' => "mysql_num_fields\(\) expects parameter 1 to be resource, (null|NULL) given", + 'args' => array(), ), array( - "function" => "mysql_fetch_row", - "message" => "mysql_fetch_row\(\) expects parameter 1 to be resource, (null|NULL) given", - "args" => array(), - "skipHHVM" => true + 'function' => 'mysql_fetch_row', + 'message' => "mysql_fetch_row\(\) expects parameter 1 to be resource, (null|NULL) given", + 'args' => array(), + 'skipHHVM' => true ), array( - "function" => "mysql_fetch_array", - "message" => "mysql_fetch_array\(\) expects parameter 1 to be resource, (null|NULL) given", - "args" => array(), + 'function' => 'mysql_fetch_array', + 'message' => "mysql_fetch_array\(\) expects parameter 1 to be resource, (null|NULL) given", + 'args' => array(), ), array( - "function" => "mysql_fetch_assoc", - "message" => "mysql_fetch_assoc\(\) expects parameter 1 to be resource, (null|NULL) given", - "args" => array(), - "skipHHVM" => true + 'function' => 'mysql_fetch_assoc', + 'message' => "mysql_fetch_assoc\(\) expects parameter 1 to be resource, (null|NULL) given", + 'args' => array(), + 'skipHHVM' => true ), array( - "function" => "mysql_fetch_object", - "message" => "(mysql_fetch_object\(\): )?supplied argument is not a valid MySQL result resource", - "args" => array("StdClass") + 'function' => 'mysql_fetch_object', + 'message' => "(mysql_fetch_object\(\): )?supplied argument is not a valid MySQL result resource", + 'args' => array('StdClass') ), array( - "function" => "mysql_data_seek", - "message" => "mysql_data_seek\(\) expects parameter 1 to be resource, (null|NULL) given", - "args" => array(0) + 'function' => 'mysql_data_seek', + 'message' => "mysql_data_seek\(\) expects parameter 1 to be resource, (null|NULL) given", + 'args' => array(0) ), array( - "function" => "mysql_fetch_lengths", - "message" => "mysql_fetch_lengths\(\) expects parameter 1 to be resource, (null|NULL) given", - "args" => array() + 'function' => 'mysql_fetch_lengths', + 'message' => "mysql_fetch_lengths\(\) expects parameter 1 to be resource, (null|NULL) given", + 'args' => array() ), array( - "function" => "mysql_fetch_field", - "message" => "mysql_fetch_field\(\) expects parameter 1 to be resource, (null|NULL) given", - "args" => array() + 'function' => 'mysql_fetch_field', + 'message' => "mysql_fetch_field\(\) expects parameter 1 to be resource, (null|NULL) given", + 'args' => array() ), array( - "function" => "mysql_field_seek", - "message" => "mysql_field_seek\(\) expects parameter 1 to be resource, (null|NULL) given", - "args" => array(0) + 'function' => 'mysql_field_seek', + 'message' => "mysql_field_seek\(\) expects parameter 1 to be resource, (null|NULL) given", + 'args' => array(0) ), array( - "function" => "mysql_free_result", - "message" => "mysql_free_result\(\) expects parameter 1 to be resource, (null|NULL) given", - "args" => array() + 'function' => 'mysql_free_result', + 'message' => "mysql_free_result\(\) expects parameter 1 to be resource, (null|NULL) given", + 'args' => array() ), array( - "function" => "mysql_field_name", - "message" => "mysql_field_name\(\) expects parameter 1 to be resource, (null|NULL) given", - "args" => array(0) + 'function' => 'mysql_field_name', + 'message' => "mysql_field_name\(\) expects parameter 1 to be resource, (null|NULL) given", + 'args' => array(0) ), array( - "function" => "mysql_field_table", - "message" => "mysql_field_table\(\) expects parameter 1 to be resource, (null|NULL) given", - "args" => array(0) + 'function' => 'mysql_field_table', + 'message' => "mysql_field_table\(\) expects parameter 1 to be resource, (null|NULL) given", + 'args' => array(0) ), array( - "function" => "mysql_field_len", - "message" => "mysql_field_len\(\) expects parameter 1 to be resource, (null|NULL) given", - "args" => array(0) + 'function' => 'mysql_field_len', + 'message' => "mysql_field_len\(\) expects parameter 1 to be resource, (null|NULL) given", + 'args' => array(0) ), array( - "function" => "mysql_field_type", - "message" => "mysql_field_type\(\) expects parameter 1 to be resource, (null|NULL) given", - "args" => array(0) + 'function' => 'mysql_field_type', + 'message' => "mysql_field_type\(\) expects parameter 1 to be resource, (null|NULL) given", + 'args' => array(0) ), array( - "function" => "mysql_field_flags", - "message" => "mysql_field_flags\(\) expects parameter 1 to be resource, (null|NULL) given", - "args" => array(0) + 'function' => 'mysql_field_flags', + 'message' => "mysql_field_flags\(\) expects parameter 1 to be resource, (null|NULL) given", + 'args' => array(0) ), array( - "function" => "mysql_db_name", - "message" => "mysql_db_name\(\) expects parameter 1 to be resource, (null|NULL) given", - "args" => array(0), - "skipHHVM" => true + 'function' => 'mysql_db_name', + 'message' => "mysql_db_name\(\) expects parameter 1 to be resource, (null|NULL) given", + 'args' => array(0), + 'skipHHVM' => true ), array( - "function" => "mysql_tablename", - "message" => "mysql_tablename\(\) expects parameter 1 to be resource, (null|NULL) given", - "args" => array(0), - "skipHHVM" => true + 'function' => 'mysql_tablename', + 'message' => "mysql_tablename\(\) expects parameter 1 to be resource, (null|NULL) given", + 'args' => array(0), + 'skipHHVM' => true ), ); } @@ -1128,7 +1122,7 @@ class MySqlShimTest extends \PHPUnit_Framework_TestCase protected function assertResult($result) { $this->assertTrue( - is_resource($result) && get_resource_type($result) == 'mysql result' + is_resource($result) && get_resource_type($result) === 'mysql result' || $result instanceof \mysqli_result, mysql_error() ); @@ -1139,13 +1133,13 @@ class MySqlShimTest extends \PHPUnit_Framework_TestCase $mysql = mysql_connect(static::$host, 'root'); $this->assertConnection($mysql); - mysql_query("SET NAMES latin1"); + mysql_query('SET NAMES latin1'); $result = mysql_query("CREATE DATABASE IF NOT EXISTS `$db` CHARACTER SET latin1;"); $this->assertTrue($result); $result = mysql_select_db($db); $this->assertTrue($result); - $result = mysql_query( + mysql_query( "CREATE TABLE IF NOT EXISTS testing ( id int AUTO_INCREMENT, one varchar(255), @@ -1169,7 +1163,7 @@ class MySqlShimTest extends \PHPUnit_Framework_TestCase ) CHARACTER SET latin1;" ); - $result = mysql_query( + mysql_query( "CREATE TABLE IF NOT EXISTS testing2 ( id int AUTO_INCREMENT, one varchar(255), @@ -1206,17 +1200,17 @@ class MySqlShimTest extends \PHPUnit_Framework_TestCase protected function assertConnection($mysql) { $this->assertTrue( - is_resource($mysql) && get_resource_type($mysql) == 'mysql link' + is_resource($mysql) && get_resource_type($mysql) === 'mysql link' || $mysql instanceof \mysqli, - "Not a valid MySQL connection" + 'Not a valid MySQL connection' ); } protected function skipForHHVM($condition = true) { if ($this->runtime->isHHVM() && $condition) { - $this->markTestSkipped("HHVM Behavior differs from PHP"); + $this->markTestSkipped('HHVM Behavior differs from PHP'); } } } |