Skip to content

Commit

Permalink
Improve migrate secrets test
Browse files Browse the repository at this point in the history
  • Loading branch information
romantmb committed May 9, 2024
1 parent de44022 commit e48fb10
Showing 1 changed file with 49 additions and 12 deletions.
61 changes: 49 additions & 12 deletions tests/phpunit/MigrateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Keboola\Syrup\ClientException;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;

class MigrateTest extends TestCase
Expand Down Expand Up @@ -128,6 +129,8 @@ public function testMigrateSuccess(
new ConfigDefinition()
);

$loggerMock = $this->createMock(LoggerInterface::class);

/** @var JobRunner $sourceJobRunnerMock */
/** @var JobRunner $destJobRunnerMock */
$migrate = new Migrate(
Expand All @@ -136,7 +139,7 @@ public function testMigrateSuccess(
$destJobRunnerMock,
'xxx-b',
'yyy-b',
new NullLogger(),
$loggerMock,
);

$sourceClientMock = $this->createMock(StorageClient::class);
Expand All @@ -154,10 +157,29 @@ public function testMigrateSuccess(
],
],
[
'components//configs?', null, [],
'components?include=', null, [],
[
[
'id' => '123',
'id' => 'gooddata-writer', // should be skipped
],
[
'id' => 'some-component',
'configurations' => [
[
'id' => '101',
],
[
'id' => '102',
],
],
],
[
'id' => 'another-component',
'configurations' => [
[
'id' => '201',
],
],
],
],
],
Expand All @@ -170,15 +192,30 @@ public function testMigrateSuccess(
;

$migrationsClientMock = $this->createMock(Migrations::class);
$migrationsClientMock->method('migrateConfiguration')
->willReturnCallback(function (...$args) {
[, $destinationStack, , $configId] = $args;
return [
'message' => "Configuration with ID '$configId' successfully " .
"migrated to stack '$destinationStack'.",
'data' => [],
];
});

if ($migrateSecrets) {
$migrationsClientMock
->expects(self::exactly(3))
->method('migrateConfiguration')
->willReturnCallback(function (...$args) {
[, $destinationStack, , , $configId] = $args;
return [
'message' => "Configuration with ID '$configId' successfully " .
"migrated to stack '$destinationStack'.",
'data' => [],
];
});

$loggerMock->expects(self::exactly(3))
->method('debug')
->withConsecutive(
[self::equalTo('Configuration with ID \'101\' successfully migrated to stack \'xxx-b\'.')],
[self::equalTo('Configuration with ID \'102\' successfully migrated to stack \'xxx-b\'.')],
[self::equalTo('Configuration with ID \'201\' successfully migrated to stack \'xxx-b\'.')]
);
} else {
$migrationsClientMock->expects(self::never())->method('migrateConfiguration');
}

$migrate->setSourceClientFactory(fn() => $sourceClientMock);
$migrate->setMigrationsClientFactory(fn() => $migrationsClientMock);
Expand Down

0 comments on commit e48fb10

Please sign in to comment.