Skip to content

Commit

Permalink
Create a semver file if using the SemVer task for the first time (#960)
Browse files Browse the repository at this point in the history
* [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
  • Loading branch information
pixelbrackets authored Jul 23, 2020
1 parent f676455 commit bcbd8d5
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Task/Development/SemVer.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ protected function dump()
if (empty($this->path)) {
return true;
}

$semver = sprintf(
self::SEMVER,
$this->version['major'],
Expand All @@ -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;
Expand Down
43 changes: 43 additions & 0 deletions tests/integration/SemVerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
namespace Robo;

use PHPUnit\Framework\TestCase;
use Robo\Traits\TestTasksTrait;

class SemVerTest extends TestCase
{
use TestTasksTrait;
use Task\Development\loadTasks;

protected $fixtures;

public function setUp()
{
$this->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');
}
}

0 comments on commit bcbd8d5

Please sign in to comment.