Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/Updater/CronUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ private function updateContent(Cron $cron, string $key): string
$content = $this->cronManipulator->getContent();

$count = 0;
$pattern = '/\r?\n' . $this->beginKey($key) . '.*?' . self::KEY_END . '/s';
$pattern = '/\r?\n' . $this->beginKey($key) . '\r?\n.*?' . self::KEY_END . '/s';
$replacedContent = \preg_replace($pattern, $this->wrapInKey($cron, $key), $content, -1, $count);

if ($count > 0) {
Expand Down
36 changes: 36 additions & 0 deletions tests/Updater/CronUpdaterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,42 @@ public function shouldReplaceKeyIfExist(): void
foo
# END

CRON;

$this->assertEquals($expectedCron, $this->manipulatorStub->contents);
}

/**
* @test
*/
public function shouldReplaceExactKeyOnly(): void
{
$this->manipulatorStub->contents = <<<CRON
headers
# KEY key1
value 1
# END
no key
# KEY key12
value 12
# END

CRON;

$cron = new Cron();
$cron->comment('replace');
$this->updater->updateWith($cron, 'key1');

$expectedCron = <<<CRON
headers
# KEY key1
#replace
# END
no key
# KEY key12
value 12
# END

CRON;

$this->assertEquals($expectedCron, $this->manipulatorStub->contents);
Expand Down