Skip to content

Commit bd92003

Browse files
committed
Remove outdated test files
- Deleted redundant test files previously associated with deprecated class names and outdated implementations. - Consolidated and migrated relevant test cases into updated test files to reflect current naming conventions and namespaces. - Ensured consistency across the updated namespace, alias usage, and refactored test structure.
1 parent 395fc5b commit bd92003

File tree

62 files changed

+488
-659
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+488
-659
lines changed

src/Bool/Alias/Boolean.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
/**
1010
* @psalm-immutable
1111
*/
12-
readonly class Boolean extends BoolStandard
12+
final readonly class Boolean extends BoolStandard
1313
{
1414
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
*
1414
* @psalm-immutable
1515
*/
16-
readonly class NonNegativeFloat extends FloatNonNegative
16+
readonly class NonNegative extends FloatNonNegative
1717
{
1818
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
/**
1010
* @psalm-immutable
1111
*/
12-
readonly class PositiveFloat extends FloatPositive
12+
readonly class Positive extends FloatPositive
1313
{
1414
}

src/Usage/Float.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
use PhpTypedValues\Float\Alias\Double;
66
use PhpTypedValues\Float\Alias\FloatType;
7-
use PhpTypedValues\Float\Alias\NonNegativeFloat;
8-
use PhpTypedValues\Float\Alias\PositiveFloat;
7+
use PhpTypedValues\Float\Alias\NonNegative;
8+
use PhpTypedValues\Float\Alias\Positive;
99
use PhpTypedValues\Float\FloatNonNegative;
1010
use PhpTypedValues\Float\FloatPositive;
1111
use PhpTypedValues\Float\FloatStandard;
@@ -17,10 +17,10 @@
1717
testFloat(FloatStandard::fromFloat(3.14)->value());
1818

1919
echo FloatStandard::fromString('2.71828')->toString() . \PHP_EOL;
20-
echo NonNegativeFloat::fromString('2.71828')->toString() . \PHP_EOL;
20+
echo NonNegative::fromString('2.71828')->toString() . \PHP_EOL;
2121
echo FloatType::fromString('2.71828')->toString() . \PHP_EOL;
2222
echo Double::fromString('2.71828')->toString() . \PHP_EOL;
23-
echo PositiveFloat::fromString('2.8')->toString() . \PHP_EOL;
23+
echo Positive::fromString('2.8')->toString() . \PHP_EOL;
2424

2525
// PositiveFloat usage
2626
testPositiveFloat(FloatNonNegative::fromFloat(0.5)->value());

tests/Arch/Alias.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use PhpTypedValues\Abstract\Bool\BoolType;
6+
use PhpTypedValues\Abstract\Bool\BoolTypeInterface;
7+
use PhpTypedValues\Abstract\TypeInterface;
8+
9+
arch('Alias Boolean')
10+
->expect('PhpTypedValues\Bool\Alias')
11+
->toBeClasses()
12+
->toBeFinal()
13+
->toExtend(BoolType::class)
14+
->toImplement(TypeInterface::class)
15+
->toImplement(BoolTypeInterface::class)
16+
->toUseNothing()
17+
->toBeReadonly();

tests/Unit/Abstract/DateTime/DateTimeTypeTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,25 @@
44

55
use PhpTypedValues\DateTime\DateTimeAtom;
66

7+
it('fromDateTime returns same instant and toString is ISO 8601', function (): void {
8+
$dt = new DateTimeImmutable('2025-01-02T03:04:05+00:00');
9+
$vo = DateTimeAtom::fromString('2025-01-02T03:04:05+00:00');
10+
11+
expect($dt->format(\DATE_ATOM))->toBe('2025-01-02T03:04:05+00:00')
12+
->and($vo->toString())->toBe('2025-01-02T03:04:05+00:00');
13+
});
14+
15+
it('DateTimeImmutable has false and throws an exception', function (): void {
16+
expect(
17+
fn() => DateTimeAtom::fromString('')
18+
)->toThrow(PhpTypedValues\Exception\DateTimeTypeException::class);
19+
});
20+
21+
it('throws DateTimeTypeException on unexpected conversion when input uses Z instead of +00:00', function (): void {
22+
$call = fn() => DateTimeAtom::fromString('2025-01-02T03:04:05Z');
23+
expect($call)->toThrow(PhpTypedValues\Exception\DateTimeTypeException::class);
24+
});
25+
726
it('__toString proxies to toString for DateTimeType', function (): void {
827
$dt = new DateTimeImmutable('2025-01-02T03:04:05+00:00');
928

tests/Unit/Abstract/Float/FloatTypeTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
declare(strict_types=1);
44

5+
use PhpTypedValues\Exception\FloatTypeException;
56
use PhpTypedValues\Float\FloatStandard;
67

78
it('__toString proxies to toString for FloatType', function (): void {
@@ -12,3 +13,28 @@
1213
->and((string) $v)
1314
->toBe('1.5');
1415
});
16+
17+
it('fromFloat returns exact value and toString matches', function (): void {
18+
$f1 = FloatStandard::fromFloat(-10.5);
19+
expect($f1->value())->toBe(-10.5)
20+
->and($f1->toString())->toBe('-10.5');
21+
22+
$f2 = FloatStandard::fromFloat(0.0);
23+
expect($f2->value())->toBe(0.0)
24+
->and($f2->toString())->toBe('0');
25+
});
26+
27+
it('fromString parses valid float strings including negatives, decimals, and scientific', function (): void {
28+
expect(FloatStandard::fromString('-15.25')->value())->toBe(-15.25)
29+
->and(FloatStandard::fromString('0007.5')->value())->toBe(7.5)
30+
->and(FloatStandard::fromString('+5.0')->value())->toBe(5.0)
31+
->and(FloatStandard::fromString('1e3')->value())->toBe(1000.0)
32+
->and(FloatStandard::fromString('42')->toString())->toBe('42');
33+
});
34+
35+
it('fromString rejects non-numeric strings', function (): void {
36+
$invalid = ['5a', 'a5', '', 'abc', '--5', '5,5'];
37+
foreach ($invalid as $str) {
38+
expect(fn() => FloatStandard::fromString($str))->toThrow(FloatTypeException::class);
39+
}
40+
});

tests/Unit/Abstract/Integer/IntTypeTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
declare(strict_types=1);
44

5+
use PhpTypedValues\Exception\IntegerTypeException;
56
use PhpTypedValues\Integer\IntegerStandard;
67

78
it('__toString proxies to toString for IntType', function (): void {
@@ -12,3 +13,26 @@
1213
->and((string) $v)
1314
->toBe('123');
1415
});
16+
17+
it('fromInt returns exact value and toString matches', function (): void {
18+
$i1 = IntegerStandard::fromInt(-10);
19+
expect($i1->value())->toBe(-10)
20+
->and($i1->toString())->toBe('-10');
21+
22+
$i2 = IntegerStandard::fromInt(0);
23+
expect($i2->value())->toBe(0)
24+
->and($i2->toString())->toBe('0');
25+
});
26+
27+
it('fromString parses valid integer strings including negatives and leading zeros', function (): void {
28+
expect(IntegerStandard::fromString('-15')->value())->toBe(-15)
29+
->and(IntegerStandard::fromString('0')->toString())->toBe('0')
30+
->and(IntegerStandard::fromString('42')->toString())->toBe('42');
31+
});
32+
33+
it('fromString rejects non-integer strings', function (): void {
34+
$invalid = ['5a', 'a5', '', 'abc', ' 5', '5 ', '+5', '05', '--5', '3.14'];
35+
foreach ($invalid as $str) {
36+
expect(fn() => IntegerStandard::fromString($str))->toThrow(IntegerTypeException::class);
37+
}
38+
});

tests/Unit/Abstract/String/StrTypeTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,23 @@
1212
->and((string) $v)
1313
->toBe('abc');
1414
});
15+
16+
it('fromString returns exact value and toString matches', function (): void {
17+
$s1 = StringStandard::fromString('hello');
18+
expect($s1->value())->toBe('hello')
19+
->and($s1->toString())->toBe('hello');
20+
21+
$s2 = StringStandard::fromString('');
22+
expect($s2->value())->toBe('')
23+
->and($s2->toString())->toBe('');
24+
});
25+
26+
it('handles unicode and whitespace transparently', function (): void {
27+
$unicode = StringStandard::fromString('Привет 🌟');
28+
expect($unicode->value())->toBe('Привет 🌟')
29+
->and($unicode->toString())->toBe('Привет 🌟');
30+
31+
$ws = StringStandard::fromString(' spaced ');
32+
expect($ws->value())->toBe(' spaced ')
33+
->and($ws->toString())->toBe(' spaced ');
34+
});
File renamed without changes.

0 commit comments

Comments
 (0)