From bcbd8d5b849f3cc5d87e76f3257c14f6d7a21fac Mon Sep 17 00:00:00 2001 From: Dan Untenzu Date: Thu, 23 Jul 2020 17:06:32 +0200 Subject: [PATCH] Create a semver file if using the SemVer task for the first time (#960) * [FEATURE] Add SemVer unit test * [BUGFIX] Remove redundant check preventing file writes Remove the check that a given filename is writetable, since this requires the file to exist beforehand. We dont expect the file to exist however. Therefore this check should not be made or create a file if failing. Since this check is included in file_put_contents anyway we may remove the check safely. Closes #959 --- src/Task/Development/SemVer.php | 4 ++- tests/integration/SemVerTest.php | 43 ++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 tests/integration/SemVerTest.php diff --git a/src/Task/Development/SemVer.php b/src/Task/Development/SemVer.php index 1c021baf8..f1c0ffce8 100644 --- a/src/Task/Development/SemVer.php +++ b/src/Task/Development/SemVer.php @@ -226,6 +226,7 @@ protected function dump() if (empty($this->path)) { return true; } + $semver = sprintf( self::SEMVER, $this->version['major'], @@ -234,7 +235,8 @@ protected function dump() $this->version['special'], $this->version['metadata'] ); - if (is_writeable($this->path) === false || file_put_contents($this->path, $semver) === false) { + + if (file_put_contents($this->path, $semver) === false) { throw new TaskException($this, 'Failed to write semver file.'); } return true; diff --git a/tests/integration/SemVerTest.php b/tests/integration/SemVerTest.php new file mode 100644 index 000000000..57dd9a9db --- /dev/null +++ b/tests/integration/SemVerTest.php @@ -0,0 +1,43 @@ +fixtures = new Fixtures(); + $this->initTestTasksTrait(); + } + + public function tearDown() + { + $this->fixtures->cleanup(); + } + + public function testSemVerFileWrite() + { + $this->fixtures->createAndCdToSandbox(); + + $sampleCss = $this->fixtures->dataFile('sample.css'); + + $outputFile = '.semver'; + + $result = $this->taskSemVer($outputFile) + ->increment() + ->run(); + + $this->assertTrue($result->wasSuccessful(), $result->getMessage()); + + $this->assertFileExists($outputFile); + $outputFileContents = file_get_contents($outputFile); + $this->assertContains('major', $outputFileContents, 'Semver file has expected structure'); + } +}