Skip to content

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

Merged
merged 2 commits into from
Nov 16, 2023

Conversation

alexandre-daubois
Copy link
Contributor

Follow-up of #11855, same but for ext/pdo_mysql

@javiereguiluz
Copy link
Contributor

This is a fantastic contribution. Thanks a lot Alex. I hope this gets merged so PHP can parallelize these tests in the CI server.

@jorgsowa
Copy link
Contributor

jorgsowa commented Oct 9, 2023

This is a creative change, however I don't see the consistency in the naming.

  1. File last_insert_id.phpt gets test_last_insert_id table name.
  2. File pdo_mysql_exec gets test_mysql_exec table name, trimming pdo prefix.

Would be good to know what's the rule of naming tables.

@kamil-tekiela, what do you think about this PR?

Copy link
Member

@Girgias Girgias left a 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)

MySQLPDOTest::dropTestTable();
$db = MySQLPDOTest::factory();
$db->exec('DROP TABLE IF EXISTS test_66528');
Copy link
Member

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

Comment on lines 18 to 21
$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)");
Copy link
Member

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);
Copy link
Member

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);
Copy link
Member

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

Comment on lines 25 to 26
$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));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be dropped

Comment on lines 272 to 274
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))) {
Copy link
Member

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');
Copy link
Member

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',
Copy link
Member

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'))");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$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)");
Copy link
Member

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

Copy link
Member

@kocsismate kocsismate left a 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! :)

$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");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drop not needed

@@ -14,20 +14,20 @@ require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
$pdo = MySQLPDOTest::factory();

$tbl = "test";
Copy link
Member

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');
Copy link
Member

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);
Copy link
Member

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

@alexandre-daubois
Copy link
Contributor Author

Thank you all for your review, I'll have a look at it soon! 😃

KentarouTakeda added a commit to KentarouTakeda/php-src that referenced this pull request Nov 11, 2023
KentarouTakeda added a commit to KentarouTakeda/php-src that referenced this pull request Nov 11, 2023
KentarouTakeda added a commit to KentarouTakeda/php-src that referenced this pull request Nov 11, 2023
KentarouTakeda added a commit to KentarouTakeda/php-src that referenced this pull request Nov 11, 2023
KentarouTakeda added a commit to KentarouTakeda/php-src that referenced this pull request Nov 11, 2023
KentarouTakeda added a commit to KentarouTakeda/php-src that referenced this pull request Nov 11, 2023
KentarouTakeda added a commit to KentarouTakeda/php-src that referenced this pull request Nov 11, 2023
KentarouTakeda added a commit to KentarouTakeda/php-src that referenced this pull request Nov 11, 2023
KentarouTakeda added a commit to KentarouTakeda/php-src that referenced this pull request Nov 11, 2023
KentarouTakeda added a commit to KentarouTakeda/php-src that referenced this pull request Nov 11, 2023
KentarouTakeda added a commit to KentarouTakeda/php-src that referenced this pull request Nov 11, 2023
KentarouTakeda added a commit to KentarouTakeda/php-src that referenced this pull request Nov 11, 2023
KentarouTakeda added a commit to KentarouTakeda/php-src that referenced this pull request Nov 11, 2023
KentarouTakeda added a commit to KentarouTakeda/php-src that referenced this pull request Nov 11, 2023
KentarouTakeda added a commit to KentarouTakeda/php-src that referenced this pull request Nov 11, 2023
KentarouTakeda added a commit to KentarouTakeda/php-src that referenced this pull request Nov 11, 2023
KentarouTakeda added a commit to KentarouTakeda/php-src that referenced this pull request Nov 11, 2023
KentarouTakeda added a commit to KentarouTakeda/php-src that referenced this pull request Nov 11, 2023
KentarouTakeda added a commit to KentarouTakeda/php-src that referenced this pull request Nov 11, 2023
KentarouTakeda added a commit to KentarouTakeda/php-src that referenced this pull request Nov 11, 2023
KentarouTakeda added a commit to KentarouTakeda/php-src that referenced this pull request Nov 11, 2023
KentarouTakeda added a commit to KentarouTakeda/php-src that referenced this pull request Nov 11, 2023
KentarouTakeda added a commit to KentarouTakeda/php-src that referenced this pull request Nov 11, 2023
KentarouTakeda added a commit to KentarouTakeda/php-src that referenced this pull request Nov 11, 2023
KentarouTakeda added a commit to KentarouTakeda/php-src that referenced this pull request Nov 11, 2023
KentarouTakeda added a commit to KentarouTakeda/php-src that referenced this pull request Nov 11, 2023
@KentarouTakeda
Copy link
Contributor

@alexandre-daubois
Hi, Could you please merge alexandre-daubois#2

@KentarouTakeda
Copy link
Contributor

@alexandre-daubois
You seem to be very busy, I'm sorry.

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.

@alexandre-daubois alexandre-daubois force-pushed the improve-pdo_mysql-cleanup branch 2 times, most recently from 641b27f to ea4d805 Compare November 15, 2023 13:36
@alexandre-daubois
Copy link
Contributor Author

Thank you @Girgias @kocsismate, I did my best to address all your comments!

Copy link
Member

@Girgias Girgias left a 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') {
Copy link
Member

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)

Copy link
Contributor Author

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow up PR :)

Copy link
Contributor Author

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$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');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@$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!
Copy link
Member

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

@alexandre-daubois alexandre-daubois force-pushed the improve-pdo_mysql-cleanup branch from ea4d805 to 21f50f6 Compare November 16, 2023 12:03
@alexandre-daubois
Copy link
Contributor Author

Thanks, comments addressed 🙂

@Girgias Girgias merged commit 6f95273 into php:master Nov 16, 2023
@alexandre-daubois alexandre-daubois deleted the improve-pdo_mysql-cleanup branch January 28, 2024 08:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants