Skip to content

Commit a1f0134

Browse files
committed
Merge branch 'BUG#AC-3049' into spartans_cloud_native_245_25052022
2 parents 8194edd + 0a1cbcd commit a1f0134

File tree

3 files changed

+83
-9
lines changed

3 files changed

+83
-9
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: 33 additions & 5 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
/**
@@ -305,6 +305,10 @@ public function testInstallWithCodeBaseRollback()
305305
$this->cliCommand->install(
306306
['Magento_TestSetupDeclarationModule1']
307307
);
308+
309+
if ($this->isUsingAuroraDb()) {
310+
$this->markTestSkipped('Test skipped in AWS Aurora');
311+
}
308312
$beforeRollback = $this->describeTable->describeShard('default');
309313
self::assertEquals($this->getTrimmedData()['before'], $beforeRollback);
310314
//Move db_schema.xml file and tried to install
@@ -344,7 +348,9 @@ public function testTableRename()
344348
$this->resourceConnection->getTableName('some_table'),
345349
$dataToMigrate
346350
);
347-
self::assertEquals($this->getData()['before'], $before['some_table']);
351+
$this->isUsingAuroraDb() ?
352+
$this->assertStringContainsString($before['some_table'], $this->getTrimmedData()['before']) :
353+
$this->assertEquals($this->getData()['before'], $before['some_table']);
348354
//Move db_schema.xml file and tried to install
349355
$this->moduleManager->updateRevision(
350356
'Magento_TestSetupDeclarationModule1',
@@ -355,7 +361,9 @@ public function testTableRename()
355361

356362
$this->cliCommand->upgrade();
357363
$after = $this->describeTable->describeShard('default');
358-
self::assertEquals($this->getData()['after'], $after['some_table_renamed']);
364+
$this->isUsingAuroraDb() ?
365+
$this->assertStringContainsString($after['some_table_renamed'], $this->getTrimmedData()['after']) :
366+
$this->assertEquals($this->getData()['after'], $after['some_table_renamed']);
359367
$select = $adapter->select()
360368
->from($this->resourceConnection->getTableName('some_table_renamed'));
361369
self::assertEquals([$dataToMigrate], $adapter->fetchAll($select));
@@ -459,6 +467,26 @@ public function testInstallationWithDisablingTables()
459467
);
460468
self::assertNull($diff->getAll());
461469
$shardData = $this->describeTable->describeShard(Sharding::DEFAULT_CONNECTION);
462-
self::assertEquals($this->getData(), $shardData);
470+
$this->assertTableCreationStatements($this->getData(), $shardData);
471+
}
472+
473+
/**
474+
* Assert table creation statements
475+
*
476+
* @param array $expectedData
477+
* @param array $actualData
478+
*/
479+
private function assertTableCreationStatements(array $expectedData, array $actualData): void
480+
{
481+
if (!$this->isUsingAuroraDb()) {
482+
$this->assertEquals($expectedData, $actualData);
483+
} else {
484+
ksort($expectedData);
485+
ksort($actualData);
486+
$this->assertSameSize($expectedData, $actualData);
487+
foreach ($expectedData as $key => $value) {
488+
$this->assertStringContainsString($actualData[$key], $value);
489+
}
490+
}
463491
}
464492
}

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)