diff --git a/.gitattributes b/.gitattributes index 27356a7..655489b 100644 --- a/.gitattributes +++ b/.gitattributes @@ -10,6 +10,7 @@ /.gitattributes export-ignore /.gitignore export-ignore /phpstan.neon export-ignore +/phpunit.xml export-ignore # Explicit text file types *.php text diff --git a/.github/workflows/PHPUnit.yml b/.github/workflows/PHPUnit.yml new file mode 100644 index 0000000..3d8ae28 --- /dev/null +++ b/.github/workflows/PHPUnit.yml @@ -0,0 +1,18 @@ +name: PHPUnit + +on: + pull_request: + +permissions: read-all + +jobs: + build: + uses: The-FireHub-Project/.github/.github/workflows/RunCommandOnMatrix.yml@master + with: + title: "Run PHPUnit" + phpVersions: ${{ vars.PHP_VERSIONS }} + phpExtensions: ${{ vars.PHP_EXTENSIONS }} + tools: "phpunit:13.x" + command: "phpunit" + secrets: + GH_TOKEN: ${{ secrets.GH_TOKEN }} \ No newline at end of file diff --git a/README.md b/README.md index 6a6e86b..7ebe6dd 100644 --- a/README.md +++ b/README.md @@ -23,19 +23,19 @@
@@ -45,47 +45,82 @@ Standard provides the base classes, kernel, domain layer, and minimal runtime ut --- -##
+
+
+
* The Value Object to compare against. *
* * @return bool True if the VOs are equal, false otherwise. + *@uses \FireHub\Core\Type\ValueObject::value() To compare the VO values. + * + * @since 1.0.0 + * + * @uses \FireHub\Core\Type\ValueObject::sameAs() To compare the VO types. */ final public function equals (self $other):bool { @@ -66,13 +66,13 @@ final public function equals (self $other):bool { * ### Checks strict identity equality of a Value Object type * * Ensures both objects are of the same concrete class without comparing values. - * @since 1.0.0 - * * @param \FireHub\Core\Type\ValueObject* The Value Object to compare against. *
* * @return bool True if the objects are of the same type, false otherwise. + *@since 1.0.0 + * */ final public function sameAs (self $other):bool { diff --git a/tests/Stubs/Type/DummyIntVO.php b/tests/Stubs/Type/DummyIntVO.php new file mode 100644 index 0000000..28537cb --- /dev/null +++ b/tests/Stubs/Type/DummyIntVO.php @@ -0,0 +1,55 @@ + + * @copyright 2026-present The FireHub Project - All rights reserved + * @license https://opensource.org/license/Apache-2-0 Apache License, Version 2.0 + * + * @php-version >=8.2 + * @package Core\Tests + */ + +namespace FireHub\Tests\Core\Stubs\Type; + +use FireHub\Core\Type\ValueObject; +use InvalidArgumentException; + +/** + * ### Dummy int Value Object + * @since 1.0.0 + */ +readonly class DummyIntVO extends ValueObject { + + /** + * ### Constructor + * @since 1.0.0 + * + * @param int $value + * + * @return void + */ + public function __construct ( + private int $value = 1 + ) { + + $this->guard( + fn() => $this->value > 0, + fn() => new InvalidArgumentException('Value must be positive.') + ); + + } + + /** + * @inheritDoc + * + * @since 1.0.0 + */ + public function value ():int { + + return $this->value; + + } + +} \ No newline at end of file diff --git a/tests/Stubs/Type/DummyStringVO.php b/tests/Stubs/Type/DummyStringVO.php new file mode 100644 index 0000000..a4e9be0 --- /dev/null +++ b/tests/Stubs/Type/DummyStringVO.php @@ -0,0 +1,55 @@ + + * @copyright 2026-present The FireHub Project - All rights reserved + * @license https://opensource.org/license/Apache-2-0 Apache License, Version 2.0 + * + * @php-version >=8.2 + * @package Core\Tests + */ + +namespace FireHub\Tests\Core\Stubs\Type; + +use FireHub\Core\Type\ValueObject; +use InvalidArgumentException; + +/** + * ### Dummy string Value Object + * @since 1.0.0 + */ +readonly class DummyStringVO extends ValueObject { + + /** + * ### Constructor + * @since 1.0.0 + * + * @param string $value + * + * @return void + */ + public function __construct ( + private string $value = 'default' + ) { + + $this->guard( + fn() => $this->value !== '', + fn() => new InvalidArgumentException('Value cannot be empty.') + ); + + } + + /** + * @inheritDoc + * + * @since 1.0.0 + */ + public function value ():string { + + return $this->value; + + } + +} \ No newline at end of file diff --git a/tests/Unit/Type/ValueObjectTest.php b/tests/Unit/Type/ValueObjectTest.php new file mode 100644 index 0000000..a4682a1 --- /dev/null +++ b/tests/Unit/Type/ValueObjectTest.php @@ -0,0 +1,74 @@ + + * @copyright 2026-present The FireHub Project - All rights reserved + * @license https://opensource.org/license/Apache-2-0 Apache License, Version 2.0 + * + * @php-version >=7.0 + * @package Core\Tests + */ + +namespace FireHub\Tests\Core\Unit\Type; + +use FireHub\Testing\FireHubTestCase; +use FireHub\Core\Type\ValueObject; +use FireHub\Tests\Core\Stubs\Type\ { + DummyIntVO, DummyStringVO +}; +use PHPUnit\Framework\Attributes\ { + CoversClass, Group, Small, TestWith +}; + +/** + * ### Test Base Value Object + * @since 1.0.0 + */ +#[Small] +#[Group('type')] +#[CoversClass(ValueObject::class)] +final class ValueObjectTest extends FireHubTestCase { + + /** + * @since 1.0.0 + * + * @param string $a + * @param string $b + * @param bool $expected + * + * @return void + */ + #[TestWith(['x', 'x', true])] + #[TestWith(['x', 'y', false])] + public function testEquals (string $a, string $b, bool $expected):void { + + $a = new DummyStringVO($a); + $b = new DummyStringVO($b); + + $this::assertEquals($expected, $a->equals($b)); + + } + + /** + * @since 1.0.0 + * + * @param string $a + * @param string $b + * @param bool $expected + * + * @return void + */ + #[TestWith([DummyStringVO::class, DummyStringVO::class, true])] + #[TestWith([DummyStringVO::class, DummyIntVO::class, false])] + public function testSameAs (string $a, string $b, bool $expected):void { + + $a = new $a; + $b = new $b; + + $this::assertEquals($expected, $a->sameAs($b)); + + } + +} \ No newline at end of file