From e48fb107420e6428d29ff00b80b8f779980a955e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Pi=C5=A1t=C4=9Bk?= Date: Thu, 9 May 2024 14:45:06 +0200 Subject: [PATCH] Improve migrate secrets test --- tests/phpunit/MigrateTest.php | 61 ++++++++++++++++++++++++++++------- 1 file changed, 49 insertions(+), 12 deletions(-) diff --git a/tests/phpunit/MigrateTest.php b/tests/phpunit/MigrateTest.php index 46bdf16..6d23183 100644 --- a/tests/phpunit/MigrateTest.php +++ b/tests/phpunit/MigrateTest.php @@ -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 @@ -128,6 +129,8 @@ public function testMigrateSuccess( new ConfigDefinition() ); + $loggerMock = $this->createMock(LoggerInterface::class); + /** @var JobRunner $sourceJobRunnerMock */ /** @var JobRunner $destJobRunnerMock */ $migrate = new Migrate( @@ -136,7 +139,7 @@ public function testMigrateSuccess( $destJobRunnerMock, 'xxx-b', 'yyy-b', - new NullLogger(), + $loggerMock, ); $sourceClientMock = $this->createMock(StorageClient::class); @@ -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', + ], + ], ], ], ], @@ -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);