diff options
Diffstat (limited to 'tests/MySqlShimTest.php')
-rw-r--r-- | tests/MySqlShimTest.php | 418 |
1 files changed, 206 insertions, 212 deletions
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'); } } } |