From 448ee6d8e5409420c0997588964fbfbcf33d4c90 Mon Sep 17 00:00:00 2001 From: Troy Harvey Date: Thu, 15 Dec 2016 12:08:21 -0500 Subject: [PATCH] Remove trailing whitespace from commit.txt --- src/HealthVersion.php | 2 +- tests/HealthVersionTest.php | 11 +++++++++++ tests/trailing-newline-commit.txt | 3 +++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 tests/trailing-newline-commit.txt diff --git a/src/HealthVersion.php b/src/HealthVersion.php index 3eda151..4fd2089 100644 --- a/src/HealthVersion.php +++ b/src/HealthVersion.php @@ -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; } diff --git a/tests/HealthVersionTest.php b/tests/HealthVersionTest.php index 74d1a16..2e6a5e1 100644 --- a/tests/HealthVersionTest.php +++ b/tests/HealthVersionTest.php @@ -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 */ @@ -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")); + } } diff --git a/tests/trailing-newline-commit.txt b/tests/trailing-newline-commit.txt new file mode 100644 index 0000000..57e1d5b --- /dev/null +++ b/tests/trailing-newline-commit.txt @@ -0,0 +1,3 @@ +2d39ff989b3f18bd332cfc7a5c2a0abea1308e27 + +