Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/code-quality.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
name: "Code Quality (PHP${{matrix.php_versions}})"
strategy:
matrix:
php_versions: ['7.4', '8.0', '8.1', '8.2', '8.3']
php_versions: ['8.0', '8.1', '8.2', '8.3', '8.4', '8.5']
fail-fast: true
runs-on: ubuntu-latest
timeout-minutes: 15
Expand Down Expand Up @@ -54,5 +54,4 @@ jobs:
run: ./vendor/bin/phpunit

- name: Mutation Tests
if: matrix.php_versions != '7.4'
run: infection run -c infection.dist.json
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@
],
"config": {
"platform": {
"php": "7.4"
"php": "8.0"
}
},
"require": {
"php": ">=8.0"
},
"require-dev": {
"phpunit/phpunit": "*",
"vimeo/psalm": "^5.1"
Expand Down
14 changes: 8 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/Number/Integer.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final public function getValue(): int
final public static function fromNumeric($value): self
{
if (is_numeric($value)) {
return new self((int)$value);
return new static((int)$value);
}

throw new InvalidArgumentException('Value is not numeric.');
Expand Down
20 changes: 20 additions & 0 deletions tests/Number/IntegerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Epignosis\Types\Number\Integer;
use Epignosis\Types\Number\PositiveInteger;
use InvalidArgumentException;
use PHPUnit\Framework\TestCase;

final class IntegerTest extends TestCase
Expand All @@ -31,6 +32,25 @@ public function test_canBeCreatedFromFloat(): void
$this->assertEquals(42, $result);
}

public function test_canBeCreatedFromNegativeNumericString(): void
{
$result = Integer::fromNumeric('-42')->getValue();

$this->assertEquals(-42, $result);
}

public function test_fromNumericReturnsPlainInteger(): void
{
$this->assertSame(Integer::class, get_class(Integer::fromNumeric('42')));
}

public function test_CannotBeCreatedFromNonNumericString(): void
{
$this->expectException(InvalidArgumentException::class);

Integer::fromNumeric('abc');
}

public function test_IsEqualToSameTypeWithSameValue(): void
{
$integer1 = new Integer(42);
Expand Down
26 changes: 26 additions & 0 deletions tests/Number/NonNegativeIntegerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,32 @@ public function test_canBeCreatedFromFloat(): void
$this->assertEquals(42, $result);
}

public function test_fromNumericReturnsInstanceOfCalledClass(): void
{
$this->assertInstanceOf(NonNegativeInteger::class, NonNegativeInteger::fromNumeric('42'));
}

public function test_canBeCreatedFromZeroNumericString(): void
{
$result = NonNegativeInteger::fromNumeric('0')->getValue();

$this->assertEquals(0, $result);
}

public function test_CannotBeCreatedFromNegativeNumericString(): void
{
$this->expectException(InvalidArgumentException::class);

NonNegativeInteger::fromNumeric('-42');
}

public function test_CannotBeCreatedFromNegativeFloat(): void
{
$this->expectException(InvalidArgumentException::class);

NonNegativeInteger::fromNumeric(-42.3);
}

public function test_CannotBeCreatedFromNegativeInteger(): void
{
$this->expectException(InvalidArgumentException::class);
Expand Down
26 changes: 26 additions & 0 deletions tests/Number/PositiveIntegerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,30 @@ public function test_isNotEqualToDifferentType(): void
$this->assertFalse($integer1->equals($integer2));
$this->assertFalse($integer2->equals($integer1));
}

public function test_fromNumericReturnsInstanceOfCalledClass(): void
{
$this->assertInstanceOf(PositiveInteger::class, PositiveInteger::fromNumeric('42'));
}

public function test_CannotBeCreatedFromNegativeNumericString(): void
{
$this->expectException(InvalidArgumentException::class);

PositiveInteger::fromNumeric('-42');
}

public function test_CannotBeCreatedFromZeroNumericString(): void
{
$this->expectException(InvalidArgumentException::class);

PositiveInteger::fromNumeric('0');
}

public function test_CannotBeCreatedFromNegativeFloat(): void
{
$this->expectException(InvalidArgumentException::class);

PositiveInteger::fromNumeric(-42.3);
}
}
Loading