-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Improve ext/pdo_mysql
tests cleanup
#11879
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve ext/pdo_mysql
tests cleanup
#11879
Conversation
This is a fantastic contribution. Thanks a lot Alex. I hope this gets merged so PHP can parallelize these tests in the CI server. |
This is a creative change, however I don't see the consistency in the naming.
Would be good to know what's the rule of naming tables. @kamil-tekiela, what do you think about this PR? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of my complaints are about the existings tests just being bad...
Some typos and other stuff but overall LGTM (sorry for taking this long I forgot)
ext/pdo_mysql/tests/bug66528.phpt
Outdated
MySQLPDOTest::dropTestTable(); | ||
$db = MySQLPDOTest::factory(); | ||
$db->exec('DROP TABLE IF EXISTS test_66528'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might make sense to keep this method and just pass a string to it with the table nape
ext/pdo_mysql/tests/bug75177.phpt
Outdated
$pdo->query("CREATE TABLE test_75177 (`bit` bit(8)) ENGINE=InnoDB"); | ||
$pdo->query("INSERT INTO test_75177 (`bit`) VALUES (1)"); | ||
$pdo->query("INSERT INTO test_75177 (`bit`) VALUES (0b011)"); | ||
$pdo->query("INSERT INTO test_75177 (`bit`) VALUES (0b01100)"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Insert queries could be combined into one
@@ -66,8 +66,8 @@ if (($row = $stmt->fetch(PDO::FETCH_ASSOC)) && ($row['value'] != '')) { | |||
|
|||
/* affected rows related */ | |||
|
|||
exec_and_count(2, $db, 'DROP TABLE IF EXISTS test', 0); | |||
exec_and_count(3, $db, sprintf('CREATE TABLE test(id INT NOT NULL PRIMARY KEY, col1 CHAR(10)) ENGINE=%s', PDO_MYSQL_TEST_ENGINE), 0); | |||
exec_and_count(2, $db, 'DROP TABLE IF EXISTS test_mysql_exec_load_data', 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't be needed
exec_and_count(2, $db, 'DROP TABLE IF EXISTS test', 0); | ||
exec_and_count(3, $db, sprintf('CREATE TABLE test(id INT NOT NULL PRIMARY KEY, col1 CHAR(10)) ENGINE=%s', PDO_MYSQL_TEST_ENGINE), 0); | ||
exec_and_count(4, $db, "INSERT INTO test(id, col1) VALUES (1, 'a')", 1); | ||
exec_and_count(2, $db, 'DROP TABLE IF EXISTS test_mysql_exec_select', 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not be needed anymore
$db->exec('DROP TABLE IF EXISTS test'); | ||
$db->exec('DROP TABLE IF EXISTS test_pdo_mysql_last_insert_id'); | ||
if ('0' !== ($tmp = $db->lastInsertId())) | ||
printf("[003] Expecting '0'/string got '%s'/%s", var_export($tmp, true), gettype($tmp)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be dropped
prepex(51, $db, 'DROP TABLE IF EXISTS test_prepare_native'); | ||
prepex(52, $db, 'CREATE TABLE test_prepare_native(id INT, label CHAR(255)) ENGINE=MyISAM'); | ||
if (is_object(prepex(53, $db, 'CREATE FULLTEXT INDEX idx1 ON test_prepare_native(label)', null, null, true))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...
@@ -53,11 +53,11 @@ unlink($file); | |||
return false; | |||
} | |||
|
|||
$db->exec('DROP TABLE IF EXISTS test'); | |||
$sql = sprintf('CREATE TABLE test(id INT, label BLOB) ENGINE=%s', PDO_MYSQL_TEST_ENGINE); | |||
$db->exec('DROP TABLE IF EXISTS test_stmt_blobfromstream'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be moved between the 2 calls to this function, or maybe even split into a new test IDK.
Also the set-up class seems to be common to some tests?
@@ -79,15 +79,14 @@ MySQLPDOTest::skip(); | |||
if (0 != $db->getAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY)) | |||
printf("[002] Unable to turn off emulated prepared statements\n"); | |||
|
|||
$db->exec('DROP TABLE IF EXISTS test'); | |||
$db->exec(sprintf('CREATE TABLE test(id INT, myobj BLOB) ENGINE=%s', | |||
$db->exec(sprintf('CREATE TABLE test_stmt_fetchserialize(id INT, myobj BLOB) ENGINE=%s', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is test is kinda pointless/outdated in its current form. What it probably should be is 3 different tests test sting the 3 different serialization mechanisms (or 4 if you cound the default one)
@@ -14,17 +14,17 @@ PDOTest::skip(); | |||
require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc'; | |||
$db = PDOTest::test_factory(__DIR__. '/common.phpt'); | |||
|
|||
$db->exec("CREATE TABLE test (bar INT NOT NULL, phase enum('please_select', 'I', 'II', 'IIa', 'IIb', 'III', 'IV'))"); | |||
$db->exec("CREATE TABLE test_pcl_bug_5200 (bar INT NOT NULL, phase enum('please_select', 'I', 'II', 'IIa', 'IIb', 'III', 'IV'))"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$db->exec("CREATE TABLE test_pcl_bug_5200 (bar INT NOT NULL, phase enum('please_select', 'I', 'II', 'IIa', 'IIb', 'III', 'IV'))"); | |
$db->exec("CREATE TABLE test_pecl_bug_5200 (bar INT NOT NULL, phase enum('please_select', 'I', 'II', 'IIa', 'IIb', 'III', 'IV'))"); |
Typo
$db->exec("CREATE TABLE test2 (login varchar(32) NOT NULL, password varchar(64) NOT NULL)"); | ||
$db->exec("INSERT INTO test2 (login, password) VALUES ('testing', 'testing')"); | ||
$db->exec("INSERT INTO test2 (login, password) VALUES ('test2', 'testpw2')"); | ||
$db->exec("CREATE TABLE test_pcl_bug_5780 (login varchar(32) NOT NULL, data varchar(64) NOT NULL)"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You typoed the spelling of PECL everywhere here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your work! :)
ext/pdo_mysql/tests/bug75177.phpt
Outdated
$pdo->query("INSERT INTO $tbl (`bit`) VALUES (1)"); | ||
$pdo->query("INSERT INTO $tbl (`bit`) VALUES (0b011)"); | ||
$pdo->query("INSERT INTO $tbl (`bit`) VALUES (0b01100)"); | ||
$pdo->query("DROP TABLE IF EXISTS test_75177"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
drop not needed
ext/pdo_mysql/tests/bug75177.phpt
Outdated
@@ -14,20 +14,20 @@ require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc'); | |||
$pdo = MySQLPDOTest::factory(); | |||
|
|||
$tbl = "test"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unused variable
@@ -46,7 +45,7 @@ if (MySQLPDOTest::isPDOMySQLnd()) | |||
printf("[%03d] id = %d, val = %s... (length: %d)\n", | |||
$offset, $id, substr($val, 0, 10), strlen($val)); | |||
} | |||
$db->exec('DROP TABLE IF EXISTS test'); | |||
$db->exec('DROP TABLE IF EXISTS test_attr_max_buffer_size'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this doesn't seem needed anymore
@@ -40,14 +40,13 @@ if (!defined('PDO::MYSQL_ATTR_LOCAL_INFILE_DIRECTORY')) { | |||
MySQLPDOTest::createTestTable($db, MySQLPDOTest::detect_transactional_mysql_engine($db)); | |||
|
|||
try { | |||
exec_and_count(1, $db, 'DROP TABLE IF EXISTS test', 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a few similar DROP TABLE
statements called via the exec_and_count()
function were not removed beforehand
Thank you all for your review, I'll have a look at it soon! 😃 |
@alexandre-daubois |
@alexandre-daubois Looks like there are some other pull requests waiting for this to be merged. I'll wait a few days and then re-create the pull request. |
641b27f
to
ea4d805
Compare
Thank you @Girgias @kocsismate, I did my best to address all your comments! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor nits and then LGTM :)
@@ -166,11 +166,11 @@ class MySQLPDOTest extends PDOTest { | |||
preg_match('/Client API version.*mysqlnd/', $tmp)); | |||
} | |||
|
|||
static function dropTestTable($db = NULL) { | |||
static function dropTestTable($db = NULL, $tableName = 'test') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it makes sense to flip the param other in a follow up PR.
(Also adding types)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, I'll have a look!
About adding types, in this PR or in a follow-up alos?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Follow up PR :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright I'll have a look at it!
@@ -178,7 +178,7 @@ MySQLPDOTest::skip(); | |||
require __DIR__ . '/mysql_pdo_test.inc'; | |||
$db = MySQLPDOTest::factory(); | |||
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT); |
@@ -178,7 +178,7 @@ MySQLPDOTest::skip(); | |||
require __DIR__ . '/mysql_pdo_test.inc'; | |||
$db = MySQLPDOTest::factory(); | |||
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT); | |||
@$db->exec('DROP TABLE IF EXISTS test'); | |||
@$db->exec('DROP TABLE IF EXISTS test_mysql_exec'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@$db->exec('DROP TABLE IF EXISTS test_mysql_exec'); | |
$db->exec('DROP TABLE IF EXISTS test_mysql_exec'); |
Shouldn't be needed
// Zerofill implies unsigned but the test plays with signed = negative values as well! | ||
// Zerofill implies unsigned but the test_mysql_types_zerofill plays with signed = negative values as well! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This "test" word does not need to be replaced
ea4d805
to
21f50f6
Compare
Thanks, comments addressed 🙂 |
Follow-up of #11855, same but for
ext/pdo_mysql