diff --git a/src/Command/Extension/SetExtensionVersionCommand.php b/src/Command/Extension/SetExtensionVersionCommand.php index 8f1ad45..3c7cd1e 100644 --- a/src/Command/Extension/SetExtensionVersionCommand.php +++ b/src/Command/Extension/SetExtensionVersionCommand.php @@ -28,6 +28,7 @@ */ class SetExtensionVersionCommand extends Command { + private const COMPOSER_PATTERN = '"version": "([0-9]+\.[0-9]+\.[0-9]+)"'; private const EMCONF_PATTERN = '["\']version["\']\s=>\s["\']((?:[0-9]+)\.[0-9]+\.[0-9]+\s*)["\']'; // Documentation/guides.xml @@ -64,6 +65,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int return 1; } + $composerFile = rtrim($path, '/') . '/composer.json'; + if (!file_exists($composerFile)) { + $io->error(sprintf('No \'composer.json\' found in the given path %s.', $path)); + return self::FAILURE; + } + $emConfFile = rtrim($path, '/') . '/ext_emconf.php'; if (!file_exists($emConfFile)) { $io->error(sprintf('No \'ext_emconf.php\' found in the given path %s.', $path)); @@ -72,6 +79,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int $versionReplacer = new VersionReplacer($version); + try { + $versionReplacer->setVersion($composerFile, self::COMPOSER_PATTERN); + } catch (\InvalidArgumentException) { + $io->error(sprintf('An error occurred while setting the composer.json version to %s.', $version)); + return self::FAILURE; + } + try { $versionReplacer->setVersion($emConfFile, self::EMCONF_PATTERN); } catch (\InvalidArgumentException $e) { diff --git a/tests/Unit/Filesystem/VersionReplacerTest.php b/tests/Unit/Filesystem/VersionReplacerTest.php index 5d6c1bc..c5d58ff 100644 --- a/tests/Unit/Filesystem/VersionReplacerTest.php +++ b/tests/Unit/Filesystem/VersionReplacerTest.php @@ -19,6 +19,19 @@ class VersionReplacerTest extends TestCase { + #[Test] + public function replaceVersionReplacesProperVersionOfComposerJson(): void + { + $composerContents = file_get_contents(__DIR__ . '/../Fixtures/Composer/composer_with_extension_key.json'); + $tempFile = tempnam('/tmp/', 'tailor_composer.json'); + file_put_contents($tempFile, $composerContents); + $subject = new VersionReplacer('6.9.0'); + $subject->setVersion($tempFile, '"version": "([0-9]+\.[0-9]+\.[0-9]+)"'); + $contents = file_get_contents($tempFile); + self::assertStringContainsString('"version": "6.9.0"', $contents); + unlink($tempFile); + } + #[Test] public function replaceVersionReplacesProperVersionOfEmConf(): void { diff --git a/tests/Unit/Fixtures/Composer/composer_with_extension_key.json b/tests/Unit/Fixtures/Composer/composer_with_extension_key.json index e570d26..5a2ffb6 100644 --- a/tests/Unit/Fixtures/Composer/composer_with_extension_key.json +++ b/tests/Unit/Fixtures/Composer/composer_with_extension_key.json @@ -19,7 +19,8 @@ }, "extra": { "typo3/cms": { - "extension-key": "my-extension" + "extension-key": "my-extension", + "version": "1.0.0" } } }