Skip to content

Commit

Permalink
Enhancement: Allow bumping Major, Minor, and Patch
Browse files Browse the repository at this point in the history
  • Loading branch information
localheinz committed Dec 25, 2023
1 parent 0bff890 commit 60be3cd
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 0 deletions.
49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,22 @@ $major = Version\Major::fromString('1');
echo $major->toString(); // 1
```

### Bump a `Major`

```php
<?php

declare(strict_types=1);

use Ergebnis\Version;

$one = Version\Major::::fromString('1');

$two = $one->bump();

echo $two->toString(); // 2
```

### Compare a `Major` with another `Major`

```php
Expand All @@ -108,6 +124,7 @@ $one->equals($three); // false
$one->equals($two); // true
```


### Create a `Minor` from an `int`

```php
Expand Down Expand Up @@ -136,6 +153,22 @@ $minor = Version\Minor::fromString('1');
echo $minor->toString(); // 1
```

### Bump a `Minor`

```php
<?php

declare(strict_types=1);

use Ergebnis\Version;

$one = Version\Minor::::fromString('1');

$two = $one->bump();

echo $two->toString(); // 2
```

### Compare a `Minor` with another `Minor`

```php
Expand Down Expand Up @@ -183,6 +216,22 @@ $patch = Version\Patch::fromString('1');
echo $patch->toString(); // 1
```

### Bump a `Patch`

```php
<?php

declare(strict_types=1);

use Ergebnis\Version;

$one = Version\Patch::::fromString('1');

$two = $one->bump();

echo $two->toString(); // 2
```

### Compare a `Patch` with another `Patch`

```php
Expand Down
27 changes: 27 additions & 0 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,49 @@
</PossiblyUnusedMethod>
</file>
<file src="test/Unit/MajorTest.php">
<MixedAssignment>
<code>$two</code>
</MixedAssignment>
<MixedMethodCall>
<code>toInt</code>
</MixedMethodCall>
<PossiblyUnusedMethod>
<code>provideInvalidStringValue</code>
<code>provideValidStringValue</code>
</PossiblyUnusedMethod>
<UndefinedMethod>
<code>bump</code>
</UndefinedMethod>
</file>
<file src="test/Unit/MinorTest.php">
<MixedAssignment>
<code>$two</code>
</MixedAssignment>
<MixedMethodCall>
<code>toInt</code>
</MixedMethodCall>
<PossiblyUnusedMethod>
<code>provideInvalidStringValue</code>
<code>provideValidStringValue</code>
</PossiblyUnusedMethod>
<UndefinedMethod>
<code>bump</code>
</UndefinedMethod>
</file>
<file src="test/Unit/PatchTest.php">
<MixedAssignment>
<code>$two</code>
</MixedAssignment>
<MixedMethodCall>
<code>toInt</code>
</MixedMethodCall>
<PossiblyUnusedMethod>
<code>provideInvalidStringValue</code>
<code>provideValidStringValue</code>
</PossiblyUnusedMethod>
<UndefinedMethod>
<code>bump</code>
</UndefinedMethod>
</file>
<file src="test/Unit/PreReleaseTest.php">
<PossiblyUnusedMethod>
Expand Down
5 changes: 5 additions & 0 deletions src/Major.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ public function toString(): string
return (string) $this->value;
}

public function bump(): self
{
return new self($this->value + 1);
}

public function equals(self $other): bool
{
return $this->value === $other->value;
Expand Down
7 changes: 7 additions & 0 deletions src/Minor.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ public function toString(): string
return (string) $this->value;
}

public function bump(): self
{
return new self($this->value + 1);
}



public function equals(self $other): bool
{
return $this->value === $other->value;
Expand Down
7 changes: 7 additions & 0 deletions src/Patch.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ public function toString(): string
return (string) $this->value;
}

public function bump(): self
{
return new self($this->value + 1);
}



public function equals(self $other): bool
{
return $this->value === $other->value;
Expand Down
10 changes: 10 additions & 0 deletions test/Unit/MajorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,16 @@ public static function provideValidStringValue(): \Generator
}
}

public function testBumpReturnsMajorWithIncrementedValue(): void
{
$one = Major::fromInt(self::faker()->numberBetween(0, \PHP_INT_MAX - 1));

$two = $one->bump();

self::assertNotSame($one, $two);
self::assertSame($one->toInt() + 1, $two->toInt());
}

public function testEqualsReturnsFalseWhenValuesAreDifferent(): void
{
$faker = self::faker()->unique();
Expand Down
10 changes: 10 additions & 0 deletions test/Unit/MinorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,16 @@ public static function provideValidStringValue(): \Generator
}
}

public function testBumpReturnsMinorWithIncrementedValue(): void
{
$one = Minor::fromInt(self::faker()->numberBetween(0, \PHP_INT_MAX - 1));

$two = $one->bump();

self::assertNotSame($one, $two);
self::assertSame($one->toInt() + 1, $two->toInt());
}

public function testEqualsReturnsFalseWhenValuesAreDifferent(): void
{
$faker = self::faker()->unique();
Expand Down
10 changes: 10 additions & 0 deletions test/Unit/PatchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,16 @@ public static function provideValidStringValue(): \Generator
}
}

public function testBumpReturnsPatchWithIncrementedValue(): void
{
$one = Patch::fromInt(self::faker()->numberBetween(0, \PHP_INT_MAX - 1));

$two = $one->bump();

self::assertNotSame($one, $two);
self::assertSame($one->toInt() + 1, $two->toInt());
}

public function testEqualsReturnsFalseWhenValuesAreDifferent(): void
{
$faker = self::faker()->unique();
Expand Down

0 comments on commit 60be3cd

Please sign in to comment.