Skip to content

Commit

Permalink
Merge pull request #4 from generationtux/OP-437-trim-whitespace-commi…
Browse files Browse the repository at this point in the history
…t-file

OP-437 Remove trailing whitespace from commit.txt
  • Loading branch information
weklund authored Dec 15, 2016
2 parents d32cc5a + 448ee6d commit 88bea1a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/HealthVersion.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function __construct($customPath = __DIR__.'/commit.txt')
public function checkVersion($inputHash)
{
if (file_exists($this->customPath)) {
return (file_get_contents($this->customPath) == $inputHash);
return (trim(file_get_contents($this->customPath)) == $inputHash);
} else {
return false;
}
Expand Down
11 changes: 11 additions & 0 deletions tests/HealthVersionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@ class HealthVersionTest extends \TestCase

protected $badPathHealthVersion;

protected $trailingNewlinePathHealthVersion;

public function setUp()
{
parent::setUp();


$this->correctPathHealthVersion = new HealthVersion('tests/commit.txt');
$this->badPathHealthVersion = new HealthVersion("badpath.txt");
$this->trailingNewlinePathHealthVersion = new HealthVersion('tests/trailing-newline-commit.txt');
}

/** @test */
Expand All @@ -38,4 +42,11 @@ public function it_returns_false_when_text_file_not_found()
{
$this->assertFalse($this->badPathHealthVersion->checkVersion("2d39ff989b3f18bd332cfc7a5c2a0abea1308e27"));
}

/** @test */
public function it_trims_whitespace_from_commit_txt_file_contents()
{
$this->assertTrue($this->trailingNewlinePathHealthVersion->checkVersion("2d39ff989b3f18bd332cfc7a5c2a0abea1308e27"));
$this->assertFalse($this->trailingNewlinePathHealthVersion->checkVersion("hurdygurdy"));
}
}
3 changes: 3 additions & 0 deletions tests/trailing-newline-commit.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
2d39ff989b3f18bd332cfc7a5c2a0abea1308e27


0 comments on commit 88bea1a

Please sign in to comment.