Replace deprecated doctrine methods in tests directory

[MAILPOET-3889]
This commit is contained in:
Rostislav Wolny
2021-10-27 10:43:39 +02:00
committed by Veljko V
parent 73a9bed483
commit b8d72522a2
10 changed files with 45 additions and 41 deletions

View File

@ -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() {

View File

@ -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");
}
}

View File

@ -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);

View File

@ -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");
}
/**

View File

@ -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);

View File

@ -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() {

View File

@ -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) {

View File

@ -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();
}
}

View File

@ -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");
}
}

View File

@ -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() {