Skip to content

Commit b302292

Browse files
SDK-5621: Add integrator cleaner #164 from spryker-sdk/feature/SDK-5621
SDK-5621: Add integrator cleaner
2 parents b638757 + f20bc4d commit b302292

14 files changed

+183
-20
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
"require": {
77
"php": ">=7.4",
88
"ext-dom": "*",
9-
"ext-simplexml": "*",
109
"ext-json": "*",
10+
"ext-simplexml": "*",
1111
"composer-plugin-api": "^1.0.0 || ^2.0.0",
1212
"aws/aws-sdk-php": "^3.257",
1313
"composer/composer": "^2.1.0",

src/Console/IntegratorLockUpdaterConsole.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
4545
$commandArgumentsTransfer,
4646
);
4747

48+
$this->getFacade()
49+
->runCleanLock($io);
50+
4851
return 0;
4952
}
5053
}

src/Executor/Module/ModuleManifestExecutor.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use SprykerSdk\Integrator\Dependency\Console\InputOutputInterface;
1414
use SprykerSdk\Integrator\Executor\ManifestExecutorInterface;
1515
use SprykerSdk\Integrator\Filter\ManifestsFiltersExecutorInterface;
16+
use SprykerSdk\Integrator\IntegratorLock\IntegratorLockCleanerInterface;
1617
use SprykerSdk\Integrator\IntegratorLock\IntegratorLockReaderInterface;
1718
use SprykerSdk\Integrator\IntegratorLock\IntegratorLockWriterInterface;
1819
use SprykerSdk\Integrator\Manifest\RepositoryManifestReaderInterface;
@@ -50,9 +51,15 @@ class ModuleManifestExecutor implements ModuleManifestExecutorInterface
5051
*/
5152
private IntegratorLockReaderInterface $integratorLockReader;
5253

54+
/**
55+
* @var \SprykerSdk\Integrator\IntegratorLock\IntegratorLockCleanerInterface
56+
*/
57+
private IntegratorLockCleanerInterface $integratorLockCleaner;
58+
5359
/**
5460
* @param \SprykerSdk\Integrator\IntegratorLock\IntegratorLockReaderInterface $integratorLockReader
5561
* @param \SprykerSdk\Integrator\IntegratorLock\IntegratorLockWriterInterface $integratorLockWriter
62+
* @param \SprykerSdk\Integrator\IntegratorLock\IntegratorLockCleanerInterface $integratorLockCleaner
5663
* @param \SprykerSdk\Integrator\Manifest\RepositoryManifestReaderInterface $manifestReader
5764
* @param \SprykerSdk\Integrator\Executor\ManifestExecutorInterface $manifestExecutor
5865
* @param \SprykerSdk\Integrator\Composer\ComposerLockReaderInterface $composerLockReader
@@ -61,15 +68,17 @@ class ModuleManifestExecutor implements ModuleManifestExecutorInterface
6168
public function __construct(
6269
IntegratorLockReaderInterface $integratorLockReader,
6370
IntegratorLockWriterInterface $integratorLockWriter,
71+
IntegratorLockCleanerInterface $integratorLockCleaner,
6472
RepositoryManifestReaderInterface $manifestReader,
6573
ManifestExecutorInterface $manifestExecutor,
6674
ComposerLockReaderInterface $composerLockReader,
6775
ManifestsFiltersExecutorInterface $manifestsFiltersExecutor
6876
) {
6977
$this->integratorLockReader = $integratorLockReader;
70-
$this->manifestExecutor = $manifestExecutor;
7178
$this->integratorLockWriter = $integratorLockWriter;
79+
$this->integratorLockCleaner = $integratorLockCleaner;
7280
$this->manifestReader = $manifestReader;
81+
$this->manifestExecutor = $manifestExecutor;
7382
$this->composerLockReader = $composerLockReader;
7483
$this->manifestsFiltersExecutor = $manifestsFiltersExecutor;
7584
}
@@ -111,4 +120,15 @@ public function runUpdateLock(
111120
$this->integratorLockWriter->storeLock($moduleVersions);
112121
$input->write('<info>The integration lock file has been updated according to the project state.</info>', true);
113122
}
123+
124+
/**
125+
* @param \SprykerSdk\Integrator\Dependency\Console\InputOutputInterface $input
126+
*
127+
* @return void
128+
*/
129+
public function runCleanLock(InputOutputInterface $input): void
130+
{
131+
$this->integratorLockCleaner->deleteLock();
132+
$input->write('<info>The integration lock file has been removed.</info>', true);
133+
}
114134
}

src/Executor/Module/ModuleManifestExecutorInterface.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,11 @@ public function runUpdateLock(
3535
InputOutputInterface $input,
3636
IntegratorCommandArgumentsTransfer $commandArgumentsTransfer
3737
): void;
38+
39+
/**
40+
* @param \SprykerSdk\Integrator\Dependency\Console\InputOutputInterface $input
41+
*
42+
* @return void
43+
*/
44+
public function runCleanLock(InputOutputInterface $input): void;
3845
}

src/IntegratorFacade.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,18 @@ public function runUpdateLock(
4646
->runUpdateLock($input, $commandArgumentsTransfer);
4747
}
4848

49+
/**
50+
* @param \SprykerSdk\Integrator\Dependency\Console\InputOutputInterface $input
51+
*
52+
* @return void
53+
*/
54+
public function runCleanLock(InputOutputInterface $input): void
55+
{
56+
$this->getFactory()
57+
->createModuleManifestExecutor()
58+
->runCleanLock($input);
59+
}
60+
4961
/**
5062
* @param \SprykerSdk\Integrator\Transfer\IntegratorCommandArgumentsTransfer $commandArgumentsTransfer
5163
* @param \SprykerSdk\Integrator\Dependency\Console\InputOutputInterface $input

src/IntegratorFacadeInterface.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ public function runUpdateLock(
3636
IntegratorCommandArgumentsTransfer $commandArgumentsTransfer
3737
): void;
3838

39+
/**
40+
* @param \SprykerSdk\Integrator\Dependency\Console\InputOutputInterface $input
41+
*
42+
* @return void
43+
*/
44+
public function runCleanLock(InputOutputInterface $input): void;
45+
3946
/**
4047
* @param \SprykerSdk\Integrator\Transfer\IntegratorCommandArgumentsTransfer $commandArgumentsTransfer
4148
* @param \SprykerSdk\Integrator\Dependency\Console\InputOutputInterface $input

src/IntegratorFactory.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@
136136
use SprykerSdk\Integrator\Filter\RatingBasedManifestFilter\RatingBasedManifestsFilter;
137137
use SprykerSdk\Integrator\Helper\ClassHelper;
138138
use SprykerSdk\Integrator\Helper\ClassHelperInterface;
139+
use SprykerSdk\Integrator\IntegratorLock\IntegratorLockCleaner;
140+
use SprykerSdk\Integrator\IntegratorLock\IntegratorLockCleanerInterface;
139141
use SprykerSdk\Integrator\IntegratorLock\IntegratorLockReader;
140142
use SprykerSdk\Integrator\IntegratorLock\IntegratorLockReaderInterface;
141143
use SprykerSdk\Integrator\IntegratorLock\IntegratorLockWriter;
@@ -184,6 +186,7 @@ public function createModuleManifestExecutor(): ModuleManifestExecutorInterface
184186
return new ModuleManifestExecutor(
185187
$this->createIntegratorLockReader(),
186188
$this->createIntegratorLockWriter(),
189+
$this->createIntegratorLockCleaner(),
187190
$this->createRepositoryManifestReader(),
188191
$this->createManifestExecutor(),
189192
$this->createComposerLockReader(),
@@ -241,6 +244,14 @@ public function createIntegratorLockWriter(): IntegratorLockWriterInterface
241244
return new IntegratorLockWriter($this->getConfig());
242245
}
243246

247+
/**
248+
* @return \SprykerSdk\Integrator\IntegratorLock\IntegratorLockCleanerInterface
249+
*/
250+
public function createIntegratorLockCleaner(): IntegratorLockCleanerInterface
251+
{
252+
return new IntegratorLockCleaner($this->getConfig());
253+
}
254+
244255
/**
245256
* @return \SprykerSdk\Integrator\Composer\ComposerLockReaderInterface
246257
*/
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
/**
4+
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
5+
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace SprykerSdk\Integrator\IntegratorLock;
11+
12+
use SprykerSdk\Integrator\IntegratorConfig;
13+
14+
class IntegratorLockCleaner implements IntegratorLockCleanerInterface
15+
{
16+
/**
17+
* @var \SprykerSdk\Integrator\IntegratorConfig
18+
*/
19+
protected IntegratorConfig $config;
20+
21+
/**
22+
* @param \SprykerSdk\Integrator\IntegratorConfig $config
23+
*/
24+
public function __construct(IntegratorConfig $config)
25+
{
26+
$this->config = $config;
27+
}
28+
29+
/**
30+
* @return void
31+
*/
32+
public function deleteLock(): void
33+
{
34+
$lockFilePath = $this->config->getIntegratorLockFilePath();
35+
36+
unlink($lockFilePath);
37+
}
38+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
/**
4+
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
5+
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace SprykerSdk\Integrator\IntegratorLock;
11+
12+
interface IntegratorLockCleanerInterface
13+
{
14+
/**
15+
* @return void
16+
*/
17+
public function deleteLock(): void;
18+
}

src/IntegratorLock/IntegratorLockWriter.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,7 @@ public function storeLock(array $lockData): int
4646
}
4747

4848
$json = preg_replace(static::REPLACE_4_WITH_2_SPACES, '$1', $json) . PHP_EOL;
49-
if (file_put_contents($lockFilePath, $json) === false) {
50-
return 1;
51-
}
5249

53-
return 0;
50+
return file_put_contents($lockFilePath, $json) === false ? 1 : 0;
5451
}
5552
}

tests/SprykerSdkTest/Integrator/Composer/ComposerLockReaderTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class ComposerLockReaderTest extends BaseTestCase
2525
*/
2626
public function testGetModuleVersions(): void
2727
{
28-
$composerLockReader = $this->createComposerLockReadr();
28+
$composerLockReader = $this->createComposerLockReader();
2929

3030
$this->assertCount(4, $composerLockReader->getModuleVersions());
3131
$this->assertArrayHasKey(static::DEFAULT_PACKAGE_NAME, $composerLockReader->getModuleVersions());
@@ -34,7 +34,7 @@ public function testGetModuleVersions(): void
3434
/**
3535
* @return \SprykerSdk\Integrator\Composer\ComposerLockReader
3636
*/
37-
private function createComposerLockReadr(): ComposerLockReader
37+
private function createComposerLockReader(): ComposerLockReader
3838
{
3939
$integratorConfigMock = $this->createMock(IntegratorConfig::class);
4040
$integratorConfigMock->method('getComposerLockFilePath')->willReturn('./tests/_data/composer/composer.lock');

tests/SprykerSdkTest/Integrator/ConfigReader/ConfigReaderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class ConfigReaderTest extends BaseTestCase
2121
public function testReadShouldReturnParsedValues(): void
2222
{
2323
// Arrange
24-
$configFilePath = './tests/_data/project_config/config_default.php';
24+
$configFilePath = ROOT_TESTS . '/_data/project_config/config_default.php';
2525
$configReader = new ConfigReader(new ParserFactory());
2626
$configKeys = ['KernelConstants::PROJECT_NAMESPACES', 'KernelConstants::CORE_NAMESPACES'];
2727

tests/SprykerSdkTest/Integrator/IntegratorFacadeTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,4 +561,22 @@ public function testRunUpdateLock(): void
561561

562562
$this->assertNotEmpty(trim(file_get_contents($integratorLock)));
563563
}
564+
565+
/**
566+
* @return void
567+
*/
568+
public function testRunCleanLock(): void
569+
{
570+
// Arrange
571+
$ioAdapter = $this->buildSymfonyConsoleInputOutputAdapter();
572+
573+
file_put_contents($this->getTestTmpDirPath() . '/integrator.lock', 'test');
574+
575+
// Act
576+
$this->createIntegratorFacade()->runCleanLock($ioAdapter);
577+
578+
// Assert
579+
$integratorLock = $this->getTestTmpDirPath() . '/integrator.lock';
580+
$this->assertFileDoesNotExist($integratorLock);
581+
}
564582
}

tests/SprykerSdkTest/Integrator/IntegratorLock/IntegratorLockTest.php

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
namespace SprykerSdkTest\Integrator\IntegratorLock;
1111

1212
use SprykerSdk\Integrator\IntegratorConfig;
13+
use SprykerSdk\Integrator\IntegratorLock\IntegratorLockCleaner;
1314
use SprykerSdk\Integrator\IntegratorLock\IntegratorLockReader;
1415
use SprykerSdk\Integrator\IntegratorLock\IntegratorLockWriter;
1516
use SprykerSdkTest\Integrator\BaseTestCase;
@@ -21,7 +22,7 @@ class IntegratorLockTest extends BaseTestCase
2122
*/
2223
public function testWriteFileLock(): void
2324
{
24-
$compareFilePath = './tests/_data/composer/spryker_lock_test_write_lock.json';
25+
$compareFilePath = ROOT_TESTS . '/_data/composer/spryker_lock_test_write_lock.json';
2526
$lockData = [
2627
'Spryker.Test' => [
2728
'wire-plugin' => [
@@ -51,7 +52,7 @@ public function testWriteFileLock(): void
5152
public function testReadFileLock(): void
5253
{
5354
$tmpIntegratorLockFilePath = tempnam(sys_get_temp_dir(), 'integrator.lock.');
54-
$compareFilePath = './tests/_data/composer/spryker_lock_test_write_lock.json';
55+
$compareFilePath = ROOT_TESTS . '/_data/composer/spryker_lock_test_write_lock.json';
5556

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

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

68+
/**
69+
* @return void
70+
*/
71+
public function testDeleteFileLock(): void
72+
{
73+
$tmpIntegratorLockFilePath = tempnam(sys_get_temp_dir(), 'integrator.lock.');
74+
$compareFilePath = ROOT_TESTS . '/_data/composer/spryker_lock_test_write_lock.json';
75+
76+
file_put_contents($tmpIntegratorLockFilePath, file_get_contents($compareFilePath));
77+
78+
$integratorLockCleaner = $this->createIntegratorLockCleaner($tmpIntegratorLockFilePath);
79+
$integratorLockCleaner->deleteLock();
80+
81+
$this->assertFileDoesNotExist($tmpIntegratorLockFilePath);
82+
}
83+
6784
/**
6885
* @param string $tmpIntegratorLockFilePath
6986
*
7087
* @return \SprykerSdk\Integrator\IntegratorLock\IntegratorLockWriter
7188
*/
7289
private function createIntegratorLockWriter(string $tmpIntegratorLockFilePath): IntegratorLockWriter
7390
{
74-
$integrotorConfigMock = $this->createMock(IntegratorConfig::class);
75-
76-
$integrotorConfigMock->method('getIntegratorLockFilePath')
77-
->willReturn($tmpIntegratorLockFilePath);
78-
79-
return new IntegratorLockWriter($integrotorConfigMock);
91+
return new IntegratorLockWriter($this->mockIntegratorConfig($tmpIntegratorLockFilePath));
8092
}
8193

8294
/**
@@ -86,12 +98,32 @@ private function createIntegratorLockWriter(string $tmpIntegratorLockFilePath):
8698
*/
8799
private function createIntegratorLockReader(string $tmpIntegratorLockFilePath): IntegratorLockReader
88100
{
89-
$integrotorConfigMock = $this->createMock(IntegratorConfig::class);
101+
return new IntegratorLockReader($this->mockIntegratorConfig($tmpIntegratorLockFilePath));
102+
}
103+
104+
/**
105+
* @param string $tmpIntegratorLockFilePath
106+
*
107+
* @return \SprykerSdk\Integrator\IntegratorLock\IntegratorLockCleaner
108+
*/
109+
private function createIntegratorLockCleaner(string $tmpIntegratorLockFilePath): IntegratorLockCleaner
110+
{
111+
return new IntegratorLockCleaner($this->mockIntegratorConfig($tmpIntegratorLockFilePath));
112+
}
113+
114+
/**
115+
* @param string $tmpIntegratorLockFilePath
116+
*
117+
* @return \SprykerSdk\Integrator\IntegratorConfig
118+
*/
119+
private function mockIntegratorConfig(string $tmpIntegratorLockFilePath): IntegratorConfig
120+
{
121+
$integratorConfigMock = $this->createMock(IntegratorConfig::class);
90122

91-
$integrotorConfigMock->method('getIntegratorLockFilePath')
123+
$integratorConfigMock->method('getIntegratorLockFilePath')
92124
->willReturn($tmpIntegratorLockFilePath);
93125

94-
return new IntegratorLockReader($integrotorConfigMock);
126+
return $integratorConfigMock;
95127
}
96128

97129
/**

0 commit comments

Comments
 (0)