-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
401 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of OpenSolid package. | ||
* | ||
* (c) Yonel Ceruto <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace OpenSolid\Domain\Tests\Model\Integer; | ||
|
||
use OpenSolid\Domain\Model\Integer\Integer; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class IntegerTest extends TestCase | ||
{ | ||
public function testCreate(): void | ||
{ | ||
$i = Integer::from(1); | ||
|
||
$this->assertSame(1, $i->value()); | ||
} | ||
|
||
public function testEquals(): void | ||
{ | ||
$i = Integer::from(1); | ||
$j = Integer::from(1); | ||
$k = Integer::from(2); | ||
|
||
$this->assertTrue($i->equals($j)); | ||
$this->assertFalse($i->equals($k)); | ||
} | ||
|
||
public function testGreaterThan(): void | ||
{ | ||
$i = Integer::from(2); | ||
$j = Integer::from(1); | ||
$k = Integer::from(2); | ||
|
||
$this->assertTrue($i->greaterThan($j)); | ||
$this->assertFalse($i->greaterThan($k)); | ||
} | ||
|
||
public function testGreaterThanOrEqual(): void | ||
{ | ||
$i = Integer::from(2); | ||
$j = Integer::from(1); | ||
$k = Integer::from(2); | ||
|
||
$this->assertTrue($i->greaterThanOrEqual($j)); | ||
$this->assertTrue($i->greaterThanOrEqual($k)); | ||
} | ||
|
||
public function testLessThan(): void | ||
{ | ||
$i = Integer::from(2); | ||
$j = Integer::from(1); | ||
$k = Integer::from(2); | ||
|
||
$this->assertTrue($j->lessThan($i)); | ||
$this->assertFalse($k->lessThan($i)); | ||
} | ||
|
||
public function testLessThanOrEqual(): void | ||
{ | ||
$i = Integer::from(2); | ||
$j = Integer::from(1); | ||
$k = Integer::from(2); | ||
|
||
$this->assertTrue($j->lessThanOrEqual($i)); | ||
$this->assertTrue($k->lessThanOrEqual($i)); | ||
} | ||
|
||
public function testMultiply(): void | ||
{ | ||
$i = Integer::from(2); | ||
$j = Integer::from(3); | ||
$k = Integer::from(6); | ||
|
||
$this->assertTrue($k->equals($i->multiply($j))); | ||
} | ||
|
||
public function testDivide(): void | ||
{ | ||
$i = Integer::from(6); | ||
$j = Integer::from(3); | ||
$k = Integer::from(2); | ||
|
||
$this->assertTrue($k->equals($i->divide($j))); | ||
} | ||
|
||
public function testModule(): void | ||
{ | ||
$i = Integer::from(6); | ||
$j = Integer::from(3); | ||
$k = Integer::from(0); | ||
|
||
$this->assertTrue($k->equals($i->module($j))); | ||
} | ||
|
||
public function testToString(): void | ||
{ | ||
$i = Integer::from(1); | ||
|
||
$this->assertSame('1', $i->toString()); | ||
$this->assertSame('1', (string) $i); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of OpenSolid package. | ||
* | ||
* (c) Yonel Ceruto <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace OpenSolid\Domain\Tests\Model\Integer; | ||
|
||
use OpenSolid\Domain\Error\InvariantViolation; | ||
use OpenSolid\Domain\Model\Integer\PositiveInteger; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class PositiveIntegerTest extends TestCase | ||
{ | ||
public function testPositiveInteger(): void | ||
{ | ||
$i = PositiveInteger::from(1); | ||
|
||
$this->assertSame(1, $i->value()); | ||
} | ||
|
||
public function testNegativeInteger(): void | ||
{ | ||
$this->expectException(InvariantViolation::class); | ||
$this->expectExceptionMessage('Value must be positive.'); | ||
|
||
PositiveInteger::from(-1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of OpenSolid package. | ||
* | ||
* (c) Yonel Ceruto <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace OpenSolid\Domain\Tests\Model\String; | ||
|
||
use OpenSolid\Domain\Error\InvariantViolation; | ||
use OpenSolid\Domain\Model\String\NonEmptyString; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class NonEmptyStringTest extends TestCase | ||
{ | ||
public function testEmptyError(): void | ||
{ | ||
$this->expectException(InvariantViolation::class); | ||
$this->expectExceptionMessage('String cannot be empty.'); | ||
|
||
NonEmptyString::from(''); | ||
} | ||
|
||
public function testEmptyWithBlankSpacesError(): void | ||
{ | ||
$this->expectException(InvariantViolation::class); | ||
$this->expectExceptionMessage('String cannot be empty.'); | ||
|
||
NonEmptyString::from(' '); | ||
} | ||
|
||
public function testTrimString(): void | ||
{ | ||
$this->assertSame('A', NonEmptyString::from(' A ')->value()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of OpenSolid package. | ||
* | ||
* (c) Yonel Ceruto <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace OpenSolid\Domain\Tests\Model\String; | ||
|
||
use OpenSolid\Domain\Model\String\Str; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class StrTest extends TestCase | ||
{ | ||
public function testCreate(): void | ||
{ | ||
$s = Str::from('foo'); | ||
|
||
$this->assertSame('foo', $s->value()); | ||
} | ||
|
||
public function testEquals(): void | ||
{ | ||
$s1 = Str::from('foo'); | ||
$s2 = Str::from('foo'); | ||
$s3 = Str::from('bar'); | ||
|
||
$this->assertTrue($s1->equalsTo($s2)); | ||
$this->assertFalse($s1->equalsTo($s3)); | ||
} | ||
|
||
public function testToString(): void | ||
{ | ||
$s = Str::from('foo'); | ||
|
||
$this->assertSame('foo', (string) $s); | ||
$this->assertSame('foo', $s->toString()); | ||
} | ||
|
||
public function testLength(): void | ||
{ | ||
$s = Str::from('foo'); | ||
|
||
$this->assertSame(3, $s->length()); | ||
} | ||
|
||
public function testIsEmpty(): void | ||
{ | ||
$s1 = Str::from('foo'); | ||
$s2 = Str::from(''); | ||
|
||
$this->assertFalse($s1->isEmpty()); | ||
$this->assertTrue($s2->isEmpty()); | ||
} | ||
|
||
public function testTrim(): void | ||
{ | ||
$s = Str::from(' foo '); | ||
|
||
$this->assertSame('foo', $s->trim()->value()); | ||
} | ||
|
||
public function testToLower(): void | ||
{ | ||
$s = Str::from('FOO'); | ||
|
||
$this->assertSame('foo', $s->lower()->value()); | ||
} | ||
|
||
public function testToUpper(): void | ||
{ | ||
$s = Str::from('foo'); | ||
|
||
$this->assertSame('FOO', $s->upper()->value()); | ||
} | ||
|
||
public function testToTitle(): void | ||
{ | ||
$s = Str::from('foo bar'); | ||
|
||
$this->assertSame('Foo bar', $s->title()->value()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of OpenSolid package. | ||
* | ||
* (c) Yonel Ceruto <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace OpenSolid\Domain\Tests\Model\Uid; | ||
|
||
use OpenSolid\Domain\Error\InvariantViolation; | ||
use OpenSolid\Domain\Model\Uid\UuidV7Base58; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class UuidV7Base58Test extends TestCase | ||
{ | ||
public function testCreate(): void | ||
{ | ||
$id = UuidV7Base58::create(); | ||
|
||
$this->assertSame(22, strlen($id->value())); | ||
} | ||
|
||
public function testCreateFromString(): void | ||
{ | ||
$id = UuidV7Base58::from('1C4Gx3HwRKMqqm8pYTjiXg'); | ||
|
||
$this->assertSame(22, strlen($id->value())); | ||
$this->assertSame('1C4Gx3HwRKMqqm8pYTjiXg', $id->value()); | ||
} | ||
|
||
public function testCreateFromStringInvalid(): void | ||
{ | ||
$this->expectException(InvariantViolation::class); | ||
$this->expectExceptionMessage('Invalid UUID: "1C4Gx"'); | ||
|
||
UuidV7Base58::from('1C4Gx'); | ||
} | ||
|
||
public function testEquals(): void | ||
{ | ||
$id1 = UuidV7Base58::from('1C4Gx3HwRKMqqm8pYTjiXg'); | ||
$id2 = UuidV7Base58::from('1C4Gx3HwRKMqqm8pYTjiXg'); | ||
$id3 = UuidV7Base58::from('1C4Gx3HwRKMqqm8pYTjiXh'); | ||
|
||
$this->assertTrue($id1->equals($id2)); | ||
$this->assertFalse($id1->equals($id3)); | ||
} | ||
|
||
public function testToString(): void | ||
{ | ||
$id = UuidV7Base58::from('1C4Gx3HwRKMqqm8pYTjiXg'); | ||
|
||
$this->assertSame('1C4Gx3HwRKMqqm8pYTjiXg', (string) $id); | ||
} | ||
} |
Oops, something went wrong.