diff --git a/src/Updater/CronUpdater.php b/src/Updater/CronUpdater.php index 29cf4bd..4fd9810 100644 --- a/src/Updater/CronUpdater.php +++ b/src/Updater/CronUpdater.php @@ -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) { diff --git a/tests/Updater/CronUpdaterTest.php b/tests/Updater/CronUpdaterTest.php index 2ec3017..ad96751 100644 --- a/tests/Updater/CronUpdaterTest.php +++ b/tests/Updater/CronUpdaterTest.php @@ -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 = <<comment('replace'); + $this->updater->updateWith($cron, 'key1'); + + $expectedCron = <<assertEquals($expectedCron, $this->manipulatorStub->contents);