Skip to content

Commit

Permalink
Fix premature EOF issue #8
Browse files Browse the repository at this point in the history
  • Loading branch information
keyvanakbary committed Aug 4, 2014
1 parent ca45594 commit 9a4ce59
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Formatter/Cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function format()
$lines .= $line->format() . PHP_EOL;
}

return (($this->hasHeader()) ? $this->header->format() . PHP_EOL : '') . trim($lines);
return (($this->hasHeader()) ? $this->header->format() . PHP_EOL : '') . trim($lines) . PHP_EOL;
}

public function hasHeader()
Expand Down
4 changes: 2 additions & 2 deletions src/Updater/CronUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private function updateContent(Cron $cron, $key)

private function wrapInKey(Cron $cron, $key)
{
return PHP_EOL . $this->beginKey($key) . PHP_EOL . $cron->format() . PHP_EOL . self::KEY_END;
return PHP_EOL . $this->beginKey($key) . PHP_EOL . trim($cron->format()) . PHP_EOL . self::KEY_END;
}

private function beginKey($key)
Expand All @@ -69,6 +69,6 @@ private function beginKey($key)

private function appendContent(Cron $cron, $key, $content)
{
return $content . $this->wrapInKey($cron, $key);
return $content . $this->wrapInKey($cron, $key) . PHP_EOL;
}
}
1 change: 1 addition & 0 deletions tests/Formatter/CronTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public function shouldBuildConfiguration()
#This is another command!
*/5 * * * sun /bin/php command2 --env=prod > /dev/null 2> /dev/null
EXP;

$this->assertEquals($expected, $this->cron->format());
Expand Down
5 changes: 4 additions & 1 deletion tests/Updater/CronUpdaterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function shouldReplaceContent()
{
$this->updater->replaceWith(new Cron);

$this->assertEquals('', $this->manipulatorStub->contents);
$this->assertEquals("\n", $this->manipulatorStub->contents);
}

/**
Expand Down Expand Up @@ -56,6 +56,7 @@ public function shouldAppendKeyIfNotExist()
#new content
# END
CRON;

$this->assertEquals($expectedCron, $this->manipulatorStub->contents);
Expand All @@ -78,6 +79,7 @@ public function shouldReplaceKeyIfExist()
# KEY key3
foo
# END
CRON;

$cron = new Cron;
Expand All @@ -96,6 +98,7 @@ public function shouldReplaceKeyIfExist()
# KEY key3
foo
# END
CRON;

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

0 comments on commit 9a4ce59

Please sign in to comment.