Skip to content
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

Add tests for #98 #141

Draft
wants to merge 1 commit into
base: fix-mysql-php8-migration-transaction-issue
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ jobs:
- "8.1"
- "8.2"
- "8.3"
services:
mysql:
image: mysql:5.7.42-debian
env:
MYSQL_DATABASE: 'doctrine1_test'
MYSQL_USER: 'doctrine1'
MYSQL_PASSWORD: 'd0ctr1n3'
MYSQL_ALLOW_EMPTY_PASSWORD: true
ports:
- 3306:3306

steps:
- name: Checkout
Expand Down Expand Up @@ -62,4 +72,6 @@ jobs:
run: composer install --prefer-dist

- name: Run Tests
env:
MYSQL_TEST_DSN: 'mysql:host=127.0.0.1;dbname=doctrine1_test;user=doctrine1;password=d0ctr1n3'
run: cd tests && php run.php
8 changes: 5 additions & 3 deletions lib/Doctrine/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -1556,7 +1556,9 @@ public function getTmpConnection($info)
$pdoDsn .= 'unix_socket=' . $info['unix_socket'] . ';';
}

$pdoDsn .= 'host=' . $info['host'];
if ($info['host']) {
$pdoDsn .= 'host=' . $info['host'];
}

if ($info['port']) {
$pdoDsn .= ';port=' . $info['port'];
Expand All @@ -1566,8 +1568,8 @@ public function getTmpConnection($info)
$pdoDsn .= ';dbname=' . $this->export->tmpConnectionDatabase;
}

$username = $this->getOption('username');
$password = $this->getOption('password');
$username = $info['user'] ?: $this->getOption('username');
$password = $info['password'] ?: $this->getOption('password');

$conn = $this->getManager()->openConnection(array($pdoDsn, $username, $password), 'doctrine_tmp_connection', false);
$conn->setOption('username', $username);
Expand Down
11 changes: 11 additions & 0 deletions tests/DoctrineTest/Doctrine_UnitTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,17 @@ public function getDeclaration($type)
return $this->dataDict->getPortableDeclaration(array('type' => $type, 'name' => 'colname', 'length' => 1, 'fixed' => true));
}

/**
* @param string $pdoDsn
* @return Doctrine_Connection
*/
protected function openAdditionalPdoConnection(string $pdoDsn)
{
$pdoFromDsn = new PDO($pdoDsn);

return $this->openAdditionalConnection($pdoFromDsn);
}

protected function openAdditionalConnection($adapter = null, $name = null)
{
$connection = $this->manager->openConnection($adapter, $name);
Expand Down
38 changes: 38 additions & 0 deletions tests/MigrationMysqlTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

class Doctrine_MigrationMysql_TestCase extends Doctrine_UnitTestCase
{
public function setUp()
{
parent::setUp();
$dsn = getenv('MYSQL_TEST_DSN') ?? '';

$this->connection = $this->openAdditionalPdoConnection($dsn);
$this->connection->setOption('dsn', $dsn);
$this->connection->dropDatabase();
$this->connection->createDatabase();
}

public function disabled_testAfterSuccessfullMigrationItWillSetMigratedVersionAsCurrentVersionInMysqlDB()
{
$migration = new Doctrine_Migration(__DIR__.'/migration_classes', $this->connection);
$this->assertFalse($migration->hasMigrated());
$migration->setCurrentVersion(0);
$this->assertFalse($this->connection->import->tableExists('migration_phonenumber'));
$this->assertFalse($this->connection->import->tableExists('migration_user'));
$this->assertFalse($this->connection->import->tableExists('migration_profile'));

$migration->migrate(3);
$this->assertTrue($migration->hasMigrated());
$this->assertEqual($migration->getCurrentVersion(), 3);
$this->assertTrue($this->connection->import->tableExists('migration_phonenumber'));
$this->assertTrue($this->connection->import->tableExists('migration_user'));
$this->assertTrue($this->connection->import->tableExists('migration_profile'));

$migration->migrate(4);
$this->assertEqual($migration->getCurrentVersion(), 4);
$this->assertTrue($this->connection->import->tableExists('migration_phonenumber'));
$this->assertTrue($this->connection->import->tableExists('migration_user'));
$this->assertFalse($this->connection->import->tableExists('migration_profile'));
}
}
1 change: 1 addition & 0 deletions tests/run.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@
// Migration Tests
$migration = new GroupTest('Migration Tests', 'migration');
$migration->addTestCase(new Doctrine_Migration_TestCase());
$migration->addTestCase(new Doctrine_MigrationMysql_TestCase());
$migration->addTestCase(new Doctrine_Migration_Base_TestCase());
$migration->addTestCase(new Doctrine_Migration_Diff_TestCase());
$test->addTestCase($migration);
Expand Down