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

SDK-5621: Add integrator cleaner #164

Merged
merged 9 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from 8 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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"require": {
"php": ">=7.4",
"ext-dom": "*",
"ext-simplexml": "*",
"ext-json": "*",
"ext-simplexml": "*",
"composer-plugin-api": "^1.0.0 || ^2.0.0",
"aws/aws-sdk-php": "^3.257",
"composer/composer": "^2.1.0",
Expand Down
22 changes: 21 additions & 1 deletion src/Executor/Module/ModuleManifestExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use SprykerSdk\Integrator\Dependency\Console\InputOutputInterface;
use SprykerSdk\Integrator\Executor\ManifestExecutorInterface;
use SprykerSdk\Integrator\Filter\ManifestsFiltersExecutorInterface;
use SprykerSdk\Integrator\IntegratorLock\IntegratorLockCleanerInterface;
use SprykerSdk\Integrator\IntegratorLock\IntegratorLockReaderInterface;
use SprykerSdk\Integrator\IntegratorLock\IntegratorLockWriterInterface;
use SprykerSdk\Integrator\Manifest\RepositoryManifestReaderInterface;
Expand Down Expand Up @@ -50,9 +51,15 @@ class ModuleManifestExecutor implements ModuleManifestExecutorInterface
*/
private IntegratorLockReaderInterface $integratorLockReader;

/**
* @var \SprykerSdk\Integrator\IntegratorLock\IntegratorLockCleanerInterface
*/
private IntegratorLockCleanerInterface $integratorLockCleaner;

/**
* @param \SprykerSdk\Integrator\IntegratorLock\IntegratorLockReaderInterface $integratorLockReader
* @param \SprykerSdk\Integrator\IntegratorLock\IntegratorLockWriterInterface $integratorLockWriter
* @param \SprykerSdk\Integrator\IntegratorLock\IntegratorLockCleanerInterface $integratorLockCleaner
* @param \SprykerSdk\Integrator\Manifest\RepositoryManifestReaderInterface $manifestReader
* @param \SprykerSdk\Integrator\Executor\ManifestExecutorInterface $manifestExecutor
* @param \SprykerSdk\Integrator\Composer\ComposerLockReaderInterface $composerLockReader
Expand All @@ -61,15 +68,17 @@ class ModuleManifestExecutor implements ModuleManifestExecutorInterface
public function __construct(
IntegratorLockReaderInterface $integratorLockReader,
IntegratorLockWriterInterface $integratorLockWriter,
IntegratorLockCleanerInterface $integratorLockCleaner,
RepositoryManifestReaderInterface $manifestReader,
ManifestExecutorInterface $manifestExecutor,
ComposerLockReaderInterface $composerLockReader,
ManifestsFiltersExecutorInterface $manifestsFiltersExecutor
) {
$this->integratorLockReader = $integratorLockReader;
$this->manifestExecutor = $manifestExecutor;
$this->integratorLockWriter = $integratorLockWriter;
$this->integratorLockCleaner = $integratorLockCleaner;
$this->manifestReader = $manifestReader;
$this->manifestExecutor = $manifestExecutor;
$this->composerLockReader = $composerLockReader;
$this->manifestsFiltersExecutor = $manifestsFiltersExecutor;
}
Expand Down Expand Up @@ -111,4 +120,15 @@ public function runUpdateLock(
$this->integratorLockWriter->storeLock($moduleVersions);
$input->write('<info>The integration lock file has been updated according to the project state.</info>', true);
}

/**
* @param \SprykerSdk\Integrator\Dependency\Console\InputOutputInterface $input
*
* @return void
*/
public function runCleanLock(InputOutputInterface $input): void
{
$this->integratorLockCleaner->deleteLock();
$input->write('<info>The integration lock file has been removed.</info>', true);
}
}
7 changes: 7 additions & 0 deletions src/Executor/Module/ModuleManifestExecutorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,11 @@ public function runUpdateLock(
InputOutputInterface $input,
IntegratorCommandArgumentsTransfer $commandArgumentsTransfer
): void;

/**
* @param \SprykerSdk\Integrator\Dependency\Console\InputOutputInterface $input
*
* @return void
*/
public function runCleanLock(InputOutputInterface $input): void;
}
12 changes: 12 additions & 0 deletions src/IntegratorFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ public function runUpdateLock(
->runUpdateLock($input, $commandArgumentsTransfer);
}

/**
* @param \SprykerSdk\Integrator\Dependency\Console\InputOutputInterface $input
*
* @return void
*/
public function runCleanLock(InputOutputInterface $input): void
{
$this->getFactory()
->createModuleManifestExecutor()
->runCleanLock($input);
}

/**
* @param \SprykerSdk\Integrator\Transfer\IntegratorCommandArgumentsTransfer $commandArgumentsTransfer
* @param \SprykerSdk\Integrator\Dependency\Console\InputOutputInterface $input
Expand Down
7 changes: 7 additions & 0 deletions src/IntegratorFacadeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ public function runUpdateLock(
IntegratorCommandArgumentsTransfer $commandArgumentsTransfer
): void;

/**
* @param \SprykerSdk\Integrator\Dependency\Console\InputOutputInterface $input
*
* @return void
*/
public function runCleanLock(InputOutputInterface $input): void;

/**
* @param \SprykerSdk\Integrator\Transfer\IntegratorCommandArgumentsTransfer $commandArgumentsTransfer
* @param \SprykerSdk\Integrator\Dependency\Console\InputOutputInterface $input
Expand Down
11 changes: 11 additions & 0 deletions src/IntegratorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@
use SprykerSdk\Integrator\Filter\RatingBasedManifestFilter\RatingBasedManifestsFilter;
use SprykerSdk\Integrator\Helper\ClassHelper;
use SprykerSdk\Integrator\Helper\ClassHelperInterface;
use SprykerSdk\Integrator\IntegratorLock\IntegratorLockCleaner;
use SprykerSdk\Integrator\IntegratorLock\IntegratorLockCleanerInterface;
use SprykerSdk\Integrator\IntegratorLock\IntegratorLockReader;
use SprykerSdk\Integrator\IntegratorLock\IntegratorLockReaderInterface;
use SprykerSdk\Integrator\IntegratorLock\IntegratorLockWriter;
Expand Down Expand Up @@ -184,6 +186,7 @@ public function createModuleManifestExecutor(): ModuleManifestExecutorInterface
return new ModuleManifestExecutor(
$this->createIntegratorLockReader(),
$this->createIntegratorLockWriter(),
$this->createIntegratorLockCleaner(),
$this->createRepositoryManifestReader(),
$this->createManifestExecutor(),
$this->createComposerLockReader(),
Expand Down Expand Up @@ -241,6 +244,14 @@ public function createIntegratorLockWriter(): IntegratorLockWriterInterface
return new IntegratorLockWriter($this->getConfig());
}

/**
* @return \SprykerSdk\Integrator\IntegratorLock\IntegratorLockCleanerInterface
*/
public function createIntegratorLockCleaner(): IntegratorLockCleanerInterface
{
return new IntegratorLockCleaner($this->getConfig());
}

/**
* @return \SprykerSdk\Integrator\Composer\ComposerLockReaderInterface
*/
Expand Down
38 changes: 38 additions & 0 deletions src/IntegratorLock/IntegratorLockCleaner.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

/**
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
*/

declare(strict_types=1);

namespace SprykerSdk\Integrator\IntegratorLock;

use SprykerSdk\Integrator\IntegratorConfig;

class IntegratorLockCleaner implements IntegratorLockCleanerInterface
{
/**
* @var \SprykerSdk\Integrator\IntegratorConfig
*/
protected IntegratorConfig $config;

/**
* @param \SprykerSdk\Integrator\IntegratorConfig $config
*/
public function __construct(IntegratorConfig $config)
{
$this->config = $config;
}

/**
* @return void
*/
public function deleteLock(): void
{
$lockFilePath = $this->config->getIntegratorLockFilePath();

unlink($lockFilePath);
}
}
18 changes: 18 additions & 0 deletions src/IntegratorLock/IntegratorLockCleanerInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

/**
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
*/

declare(strict_types=1);

namespace SprykerSdk\Integrator\IntegratorLock;

interface IntegratorLockCleanerInterface
{
/**
* @return void
*/
public function deleteLock(): void;
}
5 changes: 1 addition & 4 deletions src/IntegratorLock/IntegratorLockWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,7 @@ public function storeLock(array $lockData): int
}

$json = preg_replace(static::REPLACE_4_WITH_2_SPACES, '$1', $json) . PHP_EOL;
if (file_put_contents($lockFilePath, $json) === false) {
return 1;
}

return 0;
return file_put_contents($lockFilePath, $json) === false ? 1 : 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ComposerLockReaderTest extends BaseTestCase
*/
public function testGetModuleVersions(): void
{
$composerLockReader = $this->createComposerLockReadr();
$composerLockReader = $this->createComposerLockReader();

$this->assertCount(4, $composerLockReader->getModuleVersions());
$this->assertArrayHasKey(static::DEFAULT_PACKAGE_NAME, $composerLockReader->getModuleVersions());
Expand All @@ -34,7 +34,7 @@ public function testGetModuleVersions(): void
/**
* @return \SprykerSdk\Integrator\Composer\ComposerLockReader
*/
private function createComposerLockReadr(): ComposerLockReader
private function createComposerLockReader(): ComposerLockReader
{
$integratorConfigMock = $this->createMock(IntegratorConfig::class);
$integratorConfigMock->method('getComposerLockFilePath')->willReturn('./tests/_data/composer/composer.lock');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ConfigReaderTest extends BaseTestCase
public function testReadShouldReturnParsedValues(): void
{
// Arrange
$configFilePath = './tests/_data/project_config/config_default.php';
$configFilePath = ROOT_TESTS . '/_data/project_config/config_default.php';
$configReader = new ConfigReader(new ParserFactory());
$configKeys = ['KernelConstants::PROJECT_NAMESPACES', 'KernelConstants::CORE_NAMESPACES'];

Expand Down
18 changes: 18 additions & 0 deletions tests/SprykerSdkTest/Integrator/IntegratorFacadeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -561,4 +561,22 @@ public function testRunUpdateLock(): void

$this->assertNotEmpty(trim(file_get_contents($integratorLock)));
}

/**
* @return void
*/
public function testRunCleanLock(): void
{
// Arrange
$ioAdapter = $this->buildSymfonyConsoleInputOutputAdapter();

file_put_contents($this->getTestTmpDirPath() . '/integrator.lock', 'test');

// Act
$this->createIntegratorFacade()->runCleanLock($ioAdapter);

// Assert
$integratorLock = $this->getTestTmpDirPath() . '/integrator.lock';
$this->assertFileDoesNotExist($integratorLock);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace SprykerSdkTest\Integrator\IntegratorLock;

use SprykerSdk\Integrator\IntegratorConfig;
use SprykerSdk\Integrator\IntegratorLock\IntegratorLockCleaner;
use SprykerSdk\Integrator\IntegratorLock\IntegratorLockReader;
use SprykerSdk\Integrator\IntegratorLock\IntegratorLockWriter;
use SprykerSdkTest\Integrator\BaseTestCase;
Expand All @@ -21,7 +22,7 @@ class IntegratorLockTest extends BaseTestCase
*/
public function testWriteFileLock(): void
{
$compareFilePath = './tests/_data/composer/spryker_lock_test_write_lock.json';
$compareFilePath = ROOT_TESTS . '/_data/composer/spryker_lock_test_write_lock.json';
$lockData = [
'Spryker.Test' => [
'wire-plugin' => [
Expand Down Expand Up @@ -51,7 +52,7 @@ public function testWriteFileLock(): void
public function testReadFileLock(): void
{
$tmpIntegratorLockFilePath = tempnam(sys_get_temp_dir(), 'integrator.lock.');
$compareFilePath = './tests/_data/composer/spryker_lock_test_write_lock.json';
$compareFilePath = ROOT_TESTS . '/_data/composer/spryker_lock_test_write_lock.json';

file_put_contents($tmpIntegratorLockFilePath, file_get_contents($compareFilePath));

Expand All @@ -64,19 +65,30 @@ public function testReadFileLock(): void
$this->removeFile($tmpIntegratorLockFilePath);
}

/**
* @return void
*/
public function testDeleteFileLock(): void
{
$tmpIntegratorLockFilePath = tempnam(sys_get_temp_dir(), 'integrator.lock.');
$compareFilePath = ROOT_TESTS . '/_data/composer/spryker_lock_test_write_lock.json';

file_put_contents($tmpIntegratorLockFilePath, file_get_contents($compareFilePath));

$integratorLockCleaner = $this->createIntegratorLockCleaner($tmpIntegratorLockFilePath);
$integratorLockCleaner->deleteLock();

$this->assertFileDoesNotExist($tmpIntegratorLockFilePath);
}

/**
* @param string $tmpIntegratorLockFilePath
*
* @return \SprykerSdk\Integrator\IntegratorLock\IntegratorLockWriter
*/
private function createIntegratorLockWriter(string $tmpIntegratorLockFilePath): IntegratorLockWriter
{
$integrotorConfigMock = $this->createMock(IntegratorConfig::class);

$integrotorConfigMock->method('getIntegratorLockFilePath')
->willReturn($tmpIntegratorLockFilePath);

return new IntegratorLockWriter($integrotorConfigMock);
return new IntegratorLockWriter($this->mockIntegratorConfig($tmpIntegratorLockFilePath));
}

/**
Expand All @@ -86,12 +98,32 @@ private function createIntegratorLockWriter(string $tmpIntegratorLockFilePath):
*/
private function createIntegratorLockReader(string $tmpIntegratorLockFilePath): IntegratorLockReader
{
$integrotorConfigMock = $this->createMock(IntegratorConfig::class);
return new IntegratorLockReader($this->mockIntegratorConfig($tmpIntegratorLockFilePath));
}

/**
* @param string $tmpIntegratorLockFilePath
*
* @return \SprykerSdk\Integrator\IntegratorLock\IntegratorLockCleaner
*/
private function createIntegratorLockCleaner(string $tmpIntegratorLockFilePath): IntegratorLockCleaner
{
return new IntegratorLockCleaner($this->mockIntegratorConfig($tmpIntegratorLockFilePath));
}

/**
* @param string $tmpIntegratorLockFilePath
*
* @return \SprykerSdk\Integrator\IntegratorConfig
*/
private function mockIntegratorConfig(string $tmpIntegratorLockFilePath): IntegratorConfig
{
$integratorConfigMock = $this->createMock(IntegratorConfig::class);

$integrotorConfigMock->method('getIntegratorLockFilePath')
$integratorConfigMock->method('getIntegratorLockFilePath')
->willReturn($tmpIntegratorLockFilePath);

return new IntegratorLockReader($integrotorConfigMock);
return $integratorConfigMock;
}

/**
Expand Down
Loading