Skip to content

Commit 8d80f90

Browse files
committed
BUG#AC-3049: Cloud - native 2.4.5 Integration test Failures (Aurora)
1 parent 4021e52 commit 8d80f90

File tree

3 files changed

+81
-11
lines changed

3 files changed

+81
-11
lines changed

dev/tests/setup-integration/framework/Magento/TestFramework/TestCase/SetupTestCase.php

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77

88
namespace Magento\TestFramework\TestCase;
99

10+
use Magento\Framework\App\ResourceConnection;
1011
use Magento\Framework\DB\Adapter\ConnectionException;
1112
use Magento\Framework\DB\Adapter\SqlVersionProvider;
1213
use Magento\TestFramework\Annotation\DataProviderFromFile;
1314
use Magento\TestFramework\Helper\Bootstrap;
15+
use Zend_Db_Statement_Exception;
1416

1517
/**
1618
* Instance of Setup test case. Used in order to tweak dataProviders functionality.
@@ -32,17 +34,25 @@ class SetupTestCase extends \PHPUnit\Framework\TestCase implements MutableDataIn
3234
*/
3335
private $sqlVersionProvider;
3436

37+
/**
38+
* @var ResourceConnection
39+
*/
40+
private ResourceConnection $resourceConnection;
41+
3542
/**
3643
* @inheritDoc
3744
*/
3845
public function __construct(
3946
$name = null,
4047
array $data = [],
41-
$dataName = ''
48+
$dataName = '',
49+
ResourceConnection $resourceConnection = null
4250
) {
4351
parent::__construct($name, $data, $dataName);
4452

45-
$this->sqlVersionProvider = Bootstrap::getObjectManager()->get(SqlVersionProvider::class);
53+
$objectManager = Bootstrap::getObjectManager();
54+
$this->sqlVersionProvider = $objectManager->get(SqlVersionProvider::class);
55+
$this->resourceConnection = $resourceConnection ?? $objectManager->get(ResourceConnection::class);
4656
}
4757

4858
/**
@@ -105,4 +115,20 @@ private function getDbKey(): string
105115

106116
return $this->dbKey;
107117
}
118+
119+
/**
120+
* Checks if the DB connection Aurora RDS
121+
*
122+
* @param string $resource
123+
* @return bool
124+
*/
125+
public function isUsingAuroraDb(string $resource = ResourceConnection::DEFAULT_CONNECTION): bool
126+
{
127+
try {
128+
$this->resourceConnection->getConnection($resource)->query('SELECT AURORA_VERSION();');
129+
return true;
130+
} catch (Zend_Db_Statement_Exception $e) {
131+
return false;
132+
}
133+
}
108134
}

dev/tests/setup-integration/testsuite/Magento/Setup/DeclarativeInstallerTest.php

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ public function testInstallationWithConstraintsModification()
216216
);
217217
self::assertNull($diff->getAll());
218218
$shardData = $this->describeTable->describeShard(Sharding::DEFAULT_CONNECTION);
219-
self::assertEquals($this->getTrimmedData(), $shardData);
219+
$this->assertTableCreationStatements($this->getTrimmedData(), $shardData);
220220
}
221221

222222
/**
@@ -246,7 +246,7 @@ public function testInstallationWithDroppingTables()
246246
);
247247
self::assertNull($diff->getAll());
248248
$shardData = $this->describeTable->describeShard(Sharding::DEFAULT_CONNECTION);
249-
self::assertEquals($this->getData(), $shardData);
249+
$this->assertTableCreationStatements($this->getData(), $shardData);
250250
}
251251

252252
/**
@@ -306,7 +306,7 @@ public function testInstallWithCodeBaseRollback()
306306
['Magento_TestSetupDeclarationModule1']
307307
);
308308
$beforeRollback = $this->describeTable->describeShard('default');
309-
self::assertEquals($this->getTrimmedData()['before'], $beforeRollback);
309+
$this->assertTableCreationStatements($this->getTrimmedData()['before'], $beforeRollback);
310310
//Move db_schema.xml file and tried to install
311311
$this->moduleManager->updateRevision(
312312
'Magento_TestSetupDeclarationModule1',
@@ -317,7 +317,7 @@ public function testInstallWithCodeBaseRollback()
317317

318318
$this->cliCommand->upgrade();
319319
$afterRollback = $this->describeTable->describeShard('default');
320-
self::assertEquals($this->getData()['after'], $afterRollback);
320+
$this->assertTableCreationStatements($this->getData()['after'], $afterRollback);
321321
}
322322

323323
/**
@@ -344,7 +344,9 @@ public function testTableRename()
344344
$this->resourceConnection->getTableName('some_table'),
345345
$dataToMigrate
346346
);
347-
self::assertEquals($this->getData()['before'], $before['some_table']);
347+
$this->isUsingAuroraDb() ?
348+
$this->assertStringContainsString($this->getData()['before'], $before['some_table']) :
349+
$this->assertEquals($this->getData()['before'], $before['some_table']);
348350
//Move db_schema.xml file and tried to install
349351
$this->moduleManager->updateRevision(
350352
'Magento_TestSetupDeclarationModule1',
@@ -355,7 +357,9 @@ public function testTableRename()
355357

356358
$this->cliCommand->upgrade();
357359
$after = $this->describeTable->describeShard('default');
358-
self::assertEquals($this->getData()['after'], $after['some_table_renamed']);
360+
$this->isUsingAuroraDb() ?
361+
$this->assertStringContainsString($this->getData()['after'], $after['some_table_renamed']) :
362+
$this->assertEquals($this->getData()['after'], $after['some_table_renamed']);
359363
$select = $adapter->select()
360364
->from($this->resourceConnection->getTableName('some_table_renamed'));
361365
self::assertEquals([$dataToMigrate], $adapter->fetchAll($select));
@@ -459,6 +463,26 @@ public function testInstallationWithDisablingTables()
459463
);
460464
self::assertNull($diff->getAll());
461465
$shardData = $this->describeTable->describeShard(Sharding::DEFAULT_CONNECTION);
462-
self::assertEquals($this->getData(), $shardData);
466+
$this->assertTableCreationStatements($this->getData(), $shardData);
467+
}
468+
469+
/**
470+
* Assert table creation statements
471+
*
472+
* @param array $expectedData
473+
* @param array $actualData
474+
*/
475+
private function assertTableCreationStatements(array $expectedData, array $actualData): void
476+
{
477+
if (!$this->isUsingAuroraDb()) {
478+
$this->assertEquals($expectedData, $actualData);
479+
} else {
480+
ksort($expectedData);
481+
ksort($actualData);
482+
$this->assertSameSize($expectedData, $actualData);
483+
foreach ($expectedData as $key => $value) {
484+
$this->assertStringContainsString($actualData[$key], $value);
485+
}
486+
}
463487
}
464488
}

dev/tests/setup-integration/testsuite/Magento/Setup/ShardingTest.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function testInstall()
7878
self::assertCount(2, $default);
7979
self::assertCount(1, $shard1);
8080
self::assertCount(1, $shard2);
81-
self::assertEquals($this->getData(), array_replace($default, $shard1, $shard2));
81+
$this->assertTableCreationStatements($this->getData(), array_replace($default, $shard1, $shard2));
8282
}
8383

8484
/**
@@ -99,6 +99,26 @@ public function testUpgrade()
9999
self::assertCount(2, $default);
100100
self::assertCount(1, $shard1);
101101
self::assertCount(1, $shard2);
102-
self::assertEquals($this->getData(), array_replace($default, $shard1, $shard2));
102+
$this->assertTableCreationStatements($this->getData(), array_replace($default, $shard1, $shard2));
103+
}
104+
105+
/**
106+
* Assert table creation statements
107+
*
108+
* @param array $expectedData
109+
* @param array $actualData
110+
*/
111+
private function assertTableCreationStatements(array $expectedData, array $actualData): void
112+
{
113+
if (!$this->isUsingAuroraDb()) {
114+
$this->assertEquals($expectedData, $actualData);
115+
} else {
116+
ksort($expectedData);
117+
ksort($actualData);
118+
$this->assertSameSize($expectedData, $actualData);
119+
foreach ($expectedData as $key => $value) {
120+
$this->assertStringContainsString($actualData[$key], $value);
121+
}
122+
}
103123
}
104124
}

0 commit comments

Comments
 (0)