Skip to content

Commit

Permalink
#1 - wip: added helper class, updated tests and readme
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilpiech97 committed Apr 4, 2024
1 parent 4bf09bf commit 31c0327
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 1 deletion.
11 changes: 11 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,18 @@ use Blumilk\Version\Version;

$version = (new Version(true))->generate();
```
#### Helper class
You can use also the `VersionHelper` class to generate version strings:
```php
<?php

declare(strict_types=1);

use Blumilk\Version\VersionHelper;

$shortVersion = VersionHelper::generateShortVersion();
$longVersion = VersionHelper::generateLongVersion();
```
### Contributing
In cloned or forked repository, run:
```shell
Expand Down
18 changes: 18 additions & 0 deletions src/VersionHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace Blumilk\Version;

class VersionHelper
{
public static function generateShortVersion(): string
{
return (new Version())->generate();
}

public static function generateLongVersion(): string
{
return (new Version(long: true))->generate();
}
}
27 changes: 27 additions & 0 deletions tests/VersionHelperTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

use Blumilk\Version\VersionHelper;
use PHPUnit\Framework\TestCase;

class VersionHelperTest extends TestCase
{
public function testGeneratingVersionBasedOnGit(): void
{
$version = VersionHelper::generateShortVersion();

$this->assertIsString($version);
$this->assertStringNotContainsString("|", $version);
}

public function testGeneratingLongVersionBasedOnGit(): void
{
$version = VersionHelper::generateLongVersion();
$versionHash = trim(shell_exec("git log --format='%h' -n 1"));

$this->assertIsString($version);
$this->assertStringContainsString("|", $version);
$this->assertStringContainsString($versionHash, $version);
}
}
2 changes: 1 addition & 1 deletion tests/GenerateVersionTest.php → tests/VersionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Blumilk\Version\Version;
use PHPUnit\Framework\TestCase;

class GenerateVersionTest extends TestCase
class VersionTest extends TestCase
{
public function testGeneratingVersionBasedOnGit(): void
{
Expand Down

0 comments on commit 31c0327

Please sign in to comment.