diff --git a/tests/integration/API/JSON/v1/FeatureFlagsTest.php b/tests/integration/API/JSON/v1/FeatureFlagsTest.php index 60b6a0aebc..ef06a393af 100644 --- a/tests/integration/API/JSON/v1/FeatureFlagsTest.php +++ b/tests/integration/API/JSON/v1/FeatureFlagsTest.php @@ -20,7 +20,7 @@ class FeatureFlagsTest extends \MailPoetTest { parent::_before(); $this->repository = $this->diContainer->get(FeatureFlagsRepository::class); $tableName = $this->entityManager->getClassMetadata(FeatureFlagEntity::class)->getTableName(); - $this->entityManager->getConnection()->executeUpdate("TRUNCATE $tableName"); + $this->entityManager->getConnection()->executeStatement("TRUNCATE $tableName"); } public function testItReturnsDefaults() { diff --git a/tests/integration/API/JSON/v1/UserFlagsTest.php b/tests/integration/API/JSON/v1/UserFlagsTest.php index 309ea14e78..56cefae50a 100644 --- a/tests/integration/API/JSON/v1/UserFlagsTest.php +++ b/tests/integration/API/JSON/v1/UserFlagsTest.php @@ -62,6 +62,6 @@ class UserFlagsTest extends \MailPoetTest { private function cleanup() { $tableName = $this->entityManager->getClassMetadata(UserFlagEntity::class)->getTableName(); - $this->entityManager->getConnection()->executeUpdate("TRUNCATE $tableName"); + $this->entityManager->getConnection()->executeStatement("TRUNCATE $tableName"); } } diff --git a/tests/integration/Doctrine/ConnectionFactoryTest.php b/tests/integration/Doctrine/ConnectionFactoryTest.php index 307abb8e6a..deba822a67 100644 --- a/tests/integration/Doctrine/ConnectionFactoryTest.php +++ b/tests/integration/Doctrine/ConnectionFactoryTest.php @@ -32,11 +32,12 @@ class ConnectionFactoryTest extends \MailPoetTest { expect($connection->getWrappedConnection())->isInstanceOf(PDO::class); expect($connection->getDriver())->isInstanceOf(PDOMySql\Driver::class); expect($connection->getDatabasePlatform())->isInstanceOf(MySqlPlatform::class); - expect($connection->getHost())->equals(Env::$dbHost); - expect($connection->getParams())->notContains('unix_socket'); - expect($connection->getUsername())->equals(Env::$dbUsername); - expect($connection->getPassword())->equals(Env::$dbPassword); - expect($connection->getParams()['charset'])->equals(Env::$dbCharset); + $params = $connection->getParams(); + expect($params['host'])->equals(Env::$dbHost); + expect($params)->notContains('unix_socket'); + expect($params['user'])->equals(Env::$dbUsername); + expect($params['password'])->equals(Env::$dbPassword); + expect($params['charset'])->equals(Env::$dbCharset); expect($connection->getDatabase())->equals(Env::$dbName); expect(Type::getType(JsonType::NAME))->isInstanceOf(JsonType::class); @@ -49,7 +50,7 @@ class ConnectionFactoryTest extends \MailPoetTest { Env::$dbPort = 3456; $connectionFactory = new ConnectionFactory(); $connection = $connectionFactory->createConnection(); - expect($connection->getPort())->equals(3456); + expect($connection->getParams()['port'])->equals(3456); } finally { Env::$dbPort = $backup; } @@ -68,10 +69,10 @@ class ConnectionFactoryTest extends \MailPoetTest { Env::$dbSocket = 'socket'; $connectionFactory = new ConnectionFactory(); $connection = $connectionFactory->createConnection(); - - expect($connection->getHost())->null(); - expect($connection->getPort())->null(); - expect($connection->getParams()['unix_socket'])->equals('socket'); + $params = $connection->getParams(); + expect(isset($params['host']))->false(); + expect(isset($params['port']))->false(); + expect($params['unix_socket'])->equals('socket'); } public function testItSetsUpIpV6() { @@ -80,19 +81,19 @@ class ConnectionFactoryTest extends \MailPoetTest { Env::$dbHost = '::1'; $connectionFactory = new ConnectionFactory(); $connection = $connectionFactory->createConnection(); - expect($connection->getHost())->equals('[::1]'); + expect($connection->getParams()['host'])->equals('[::1]'); Env::$dbHost = 'b57e:9b70:ab96:6a0b:5ba2:49e3:ebba:a036'; $connectionFactory = new ConnectionFactory(); $connection = $connectionFactory->createConnection(); - expect($connection->getHost())->equals('[b57e:9b70:ab96:6a0b:5ba2:49e3:ebba:a036]'); + expect($connection->getParams()['host'])->equals('[b57e:9b70:ab96:6a0b:5ba2:49e3:ebba:a036]'); // try to actually connect to the DB over IPv6 Env::$dbHost = '::ffff:' . gethostbyname($this->envBackup['db_host']); $connectionFactory = new ConnectionFactory(); $connection = $connectionFactory->createConnection(); expect($connection->getWrappedConnection())->isInstanceOf(PDO::class); - expect($connection->executeQuery('SELECT 1')->fetchColumn())->same('1'); + expect($connection->executeQuery('SELECT 1')->fetchOne())->same('1'); } public function testItSetsDriverOptions() { @@ -108,7 +109,7 @@ class ConnectionFactoryTest extends \MailPoetTest { @@session.character_set_connection, @@session.character_set_results, @@session.collation_connection - ')->fetch(); + ')->fetchAssociative(); // check timezone, SQL mode, wait timeout expect($result['@@session.time_zone'])->equals(Env::$dbTimezoneOffset); diff --git a/tests/integration/Doctrine/EventListeners/TimestampListenerTest.php b/tests/integration/Doctrine/EventListeners/TimestampListenerTest.php index 414a7dee5d..ce5713ea75 100644 --- a/tests/integration/Doctrine/EventListeners/TimestampListenerTest.php +++ b/tests/integration/Doctrine/EventListeners/TimestampListenerTest.php @@ -40,8 +40,8 @@ class TimestampListenerTest extends \MailPoetTest { $this->replaceListeners($originalListener, $newTimestampListener); $this->tableName = $this->entityManager->getClassMetadata(TimestampEntity::class)->getTableName(); - $this->connection->executeUpdate("DROP TABLE IF EXISTS $this->tableName"); - $this->connection->executeUpdate(" + $this->connection->executeStatement("DROP TABLE IF EXISTS $this->tableName"); + $this->connection->executeStatement(" CREATE TABLE $this->tableName ( id int(11) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY, created_at timestamp NULL, @@ -63,7 +63,7 @@ class TimestampListenerTest extends \MailPoetTest { } public function testItSetsTimestampOnUpdate() { - $this->connection->executeUpdate(" + $this->connection->executeStatement(" INSERT INTO $this->tableName (id, created_at, updated_at, name) VALUES ( 123, '2000-01-01 12:00:00', @@ -83,7 +83,7 @@ class TimestampListenerTest extends \MailPoetTest { public function _after() { parent::_after(); - $this->connection->executeUpdate("DROP TABLE IF EXISTS $this->tableName"); + $this->connection->executeStatement("DROP TABLE IF EXISTS $this->tableName"); } /** diff --git a/tests/integration/Doctrine/EventListeners/ValidationTest.php b/tests/integration/Doctrine/EventListeners/ValidationTest.php index 15e04942d8..806069341d 100644 --- a/tests/integration/Doctrine/EventListeners/ValidationTest.php +++ b/tests/integration/Doctrine/EventListeners/ValidationTest.php @@ -28,8 +28,8 @@ class ValidationTest extends \MailPoetTest { $this->wp = new WPFunctions(); $this->entityManager = $this->createEntityManager(); $this->tableName = $this->entityManager->getClassMetadata(ValidatedEntity::class)->getTableName(); - $this->connection->executeUpdate("DROP TABLE IF EXISTS $this->tableName"); - $this->connection->executeUpdate(" + $this->connection->executeStatement("DROP TABLE IF EXISTS $this->tableName"); + $this->connection->executeStatement(" CREATE TABLE $this->tableName ( id int(11) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY, name varchar(255) NOT NULL @@ -52,7 +52,7 @@ class ValidationTest extends \MailPoetTest { public function testItValidatesUpdatedEntity() { $id = 1; $name = 'Test name'; - $this->connection->executeUpdate("INSERT INTO $this->tableName (id, name) VALUES (?, ?)", [$id, $name]); + $this->connection->executeStatement("INSERT INTO $this->tableName (id, name) VALUES (?, ?)", [$id, $name]); /** @var ValidatedEntity $entity */ $entity = $this->entityManager->find(ValidatedEntity::class, $id); diff --git a/tests/integration/Doctrine/Types/JsonTypesTest.php b/tests/integration/Doctrine/Types/JsonTypesTest.php index dc42aaf365..84f2bf982d 100644 --- a/tests/integration/Doctrine/Types/JsonTypesTest.php +++ b/tests/integration/Doctrine/Types/JsonTypesTest.php @@ -40,8 +40,8 @@ class JsonTypesTest extends \MailPoetTest { $this->wp = new WPFunctions(); $this->entityManager = $this->createEntityManager(); $this->tableName = $this->entityManager->getClassMetadata(JsonEntity::class)->getTableName(); - $this->connection->executeUpdate("DROP TABLE IF EXISTS $this->tableName"); - $this->connection->executeUpdate(" + $this->connection->executeStatement("DROP TABLE IF EXISTS $this->tableName"); + $this->connection->executeStatement(" CREATE TABLE $this->tableName ( id int(11) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY, json_data longtext NULL, @@ -57,13 +57,13 @@ class JsonTypesTest extends \MailPoetTest { $this->entityManager->persist($entity); $this->entityManager->flush(); - $savedData = $this->connection->executeQuery("SELECT * FROM $this->tableName")->fetch(); + $savedData = $this->connection->executeQuery("SELECT * FROM $this->tableName")->fetchAssociative() ?: []; expect($savedData['json_data'])->same(json_encode($this->testData)); expect($savedData['json_or_serialized_data'])->same(json_encode($this->testData)); } public function testItLoadsJsonData() { - $this->connection->executeUpdate( + $this->connection->executeStatement( "INSERT INTO $this->tableName (id, json_data, json_or_serialized_data) VALUES (?, ?, ?)", [ 1, @@ -79,7 +79,7 @@ class JsonTypesTest extends \MailPoetTest { } public function testItLoadsSerializedData() { - $this->connection->executeUpdate( + $this->connection->executeStatement( "INSERT INTO $this->tableName (id, json_or_serialized_data) VALUES (?, ?)", [ 1, @@ -100,13 +100,14 @@ class JsonTypesTest extends \MailPoetTest { $this->entityManager->persist($entity); $this->entityManager->flush(); - $savedData = $this->connection->executeQuery("SELECT * FROM $this->tableName")->fetch(); + $savedData = $this->connection->executeQuery("SELECT * FROM $this->tableName")->fetchAssociative() ?: []; + expect($savedData)->array(); expect($savedData['json_data'])->null(); expect($savedData['json_or_serialized_data'])->null(); } public function testItLoadsNullData() { - $this->connection->executeUpdate( + $this->connection->executeStatement( "INSERT INTO $this->tableName (id, json_data, json_or_serialized_data) VALUES (?, ?, ?)", [ 1, @@ -122,7 +123,7 @@ class JsonTypesTest extends \MailPoetTest { } public function testItLoadsEmptyStringAsNull() { - $this->connection->executeUpdate( + $this->connection->executeStatement( "INSERT INTO $this->tableName (id, json_data, json_or_serialized_data) VALUES (?, ?, ?)", [ 1, @@ -152,7 +153,7 @@ class JsonTypesTest extends \MailPoetTest { } public function testItDoesNotLoadInvalidData() { - $this->connection->executeUpdate( + $this->connection->executeStatement( "INSERT INTO $this->tableName (id, json_data) VALUES (?, ?)", [ 1, @@ -171,7 +172,7 @@ class JsonTypesTest extends \MailPoetTest { public function _after() { parent::_after(); - $this->connection->executeUpdate("DROP TABLE IF EXISTS $this->tableName"); + $this->connection->executeStatement("DROP TABLE IF EXISTS $this->tableName"); } private function createEntityManager() { diff --git a/tests/integration/Segments/WPTest.php b/tests/integration/Segments/WPTest.php index 4da143abaf..ac92116958 100644 --- a/tests/integration/Segments/WPTest.php +++ b/tests/integration/Segments/WPTest.php @@ -600,11 +600,13 @@ class WPTest extends \MailPoetTest { private function getUser(int $id): array { global $wpdb; - return $this->entityManager->getConnection()->executeQuery(' + $user = $this->entityManager->getConnection()->executeQuery(' SELECT user_login, user_email, user_registered FROM ' . $wpdb->users . ' WHERE id = :id - ', ['id' => $id])->fetch(); + ', ['id' => $id])->fetchAssociative(); + $this->assertIsArray($user); + return $user; } private function updateWPUserEmail($id, $email) { diff --git a/tests/integration/Settings/SettingsControllerTest.php b/tests/integration/Settings/SettingsControllerTest.php index 81ed0b3048..734ead0987 100644 --- a/tests/integration/Settings/SettingsControllerTest.php +++ b/tests/integration/Settings/SettingsControllerTest.php @@ -125,7 +125,7 @@ class SettingsControllerTest extends \MailPoetTest { private function createOrUpdateSetting($name, $value) { $tableName = $this->entityManager->getClassMetadata(SettingEntity::class)->getTableName(); - $this->connection->executeUpdate(" + $this->connection->executeStatement(" INSERT INTO $tableName (name, value) VALUES (?, ?) ON DUPLICATE KEY UPDATE value = ? ", [$name, $value, $value]); @@ -133,6 +133,6 @@ class SettingsControllerTest extends \MailPoetTest { private function getSettingValue($name) { $tableName = $this->entityManager->getClassMetadata(SettingEntity::class)->getTableName(); - return $this->connection->executeQuery("SELECT value FROM $tableName WHERE name = ?", [$name])->fetchColumn(); + return $this->connection->executeQuery("SELECT value FROM $tableName WHERE name = ?", [$name])->fetchOne(); } } diff --git a/tests/integration/Settings/UserFlagsControllerTest.php b/tests/integration/Settings/UserFlagsControllerTest.php index 93f5bcdda3..68871d7a07 100644 --- a/tests/integration/Settings/UserFlagsControllerTest.php +++ b/tests/integration/Settings/UserFlagsControllerTest.php @@ -117,6 +117,6 @@ class UserFlagsControllerTest extends \MailPoetTest { private function cleanup() { $tableName = $this->entityManager->getClassMetadata(UserFlagEntity::class)->getTableName(); - $this->connection->executeUpdate("TRUNCATE $tableName"); + $this->connection->executeStatement("TRUNCATE $tableName"); } } diff --git a/tests/integration/_bootstrap.php b/tests/integration/_bootstrap.php index 7dc84d78c1..5dfe9aff4d 100644 --- a/tests/integration/_bootstrap.php +++ b/tests/integration/_bootstrap.php @@ -223,9 +223,9 @@ abstract class MailPoetTest extends \Codeception\TestCase\Test { // phpcs:ignore $classMetadata = $this->entityManager->getClassMetadata($entityName); $tableName = $classMetadata->getTableName(); $connection = $this->entityManager->getConnection(); - $connection->query('SET FOREIGN_KEY_CHECKS=0'); - $connection->executeUpdate("TRUNCATE $tableName"); - $connection->query('SET FOREIGN_KEY_CHECKS=1'); + $connection->executeQuery('SET FOREIGN_KEY_CHECKS=0'); + $connection->executeStatement("TRUNCATE $tableName"); + $connection->executeQuery('SET FOREIGN_KEY_CHECKS=1'); } public function clearSubscribersCountCache() {