Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
14 changes: 14 additions & 0 deletions src/Command/Extension/SetExtensionVersionCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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));
Expand All @@ -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) {
Expand Down
13 changes: 13 additions & 0 deletions tests/Unit/Filesystem/VersionReplacerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
},
"extra": {
"typo3/cms": {
"extension-key": "my-extension"
"extension-key": "my-extension",
"version": "1.0.0"
}
}
}
Loading