diff --git a/src/MartinGeorgiev/Doctrine/DBAL/Types/ValueObject/Range.php b/src/MartinGeorgiev/Doctrine/DBAL/Types/ValueObject/Range.php index a9159b55..28f2dce5 100644 --- a/src/MartinGeorgiev/Doctrine/DBAL/Types/ValueObject/Range.php +++ b/src/MartinGeorgiev/Doctrine/DBAL/Types/ValueObject/Range.php @@ -23,6 +23,10 @@ abstract class Range implements \Stringable protected const EMPTY_RANGE_STRING = 'empty'; + /** + * @param R|null $lower + * @param R|null $upper + */ public function __construct( protected readonly mixed $lower, protected readonly mixed $upper, @@ -140,4 +144,29 @@ public static function infinite(): static { return new static(null, null, false, false); } + + public function getLower(): \DateTimeInterface|float|int|null + { + return $this->lower; + } + + public function getUpper(): \DateTimeInterface|float|int|null + { + return $this->upper; + } + + public function isLowerBracketInclusive(): bool + { + return $this->isLowerBracketInclusive; + } + + public function isUpperBracketInclusive(): bool + { + return $this->isUpperBracketInclusive; + } + + public function isExplicitlyEmpty(): bool + { + return $this->isExplicitlyEmpty; + } } diff --git a/tests/Unit/MartinGeorgiev/Doctrine/DBAL/Types/ValueObject/BaseRangeTestCase.php b/tests/Unit/MartinGeorgiev/Doctrine/DBAL/Types/ValueObject/BaseRangeTestCase.php index b4354e47..f5c546d9 100644 --- a/tests/Unit/MartinGeorgiev/Doctrine/DBAL/Types/ValueObject/BaseRangeTestCase.php +++ b/tests/Unit/MartinGeorgiev/Doctrine/DBAL/Types/ValueObject/BaseRangeTestCase.php @@ -110,6 +110,61 @@ public function can_handle_comparison_via_is_empty(): void } } + #[Test] + public function can_get_lower_bound(): void + { + $range = $this->createSimpleRange(); + $lower = $range->getLower(); + + $this->assertNotNull($lower, 'Simple range should have a lower bound'); + } + + #[Test] + public function can_get_upper_bound(): void + { + $range = $this->createSimpleRange(); + $upper = $range->getUpper(); + + $this->assertNotNull($upper, 'Simple range should have an upper bound'); + } + + #[Test] + public function can_get_null_bounds_for_infinite_range(): void + { + $range = $this->createInfiniteRange(); + + $this->assertNull($range->getLower(), 'Infinite range should have null lower bound'); + $this->assertNull($range->getUpper(), 'Infinite range should have null upper bound'); + } + + #[Test] + public function can_get_bracket_inclusivity(): void + { + $range = $this->createSimpleRange(); + + $this->assertTrue($range->isLowerBracketInclusive(), 'Simple range should have inclusive lower bracket'); + $this->assertFalse($range->isUpperBracketInclusive(), 'Simple range should have exclusive upper bracket'); + } + + #[Test] + public function can_get_inclusive_bracket_state(): void + { + $range = $this->createInclusiveRange(); + + $this->assertTrue($range->isLowerBracketInclusive(), 'Inclusive range should have inclusive lower bracket'); + $this->assertTrue($range->isUpperBracketInclusive(), 'Inclusive range should have inclusive upper bracket'); + } + + #[Test] + public function can_get_explicitly_empty_state(): void + { + $emptyRange = $this->createEmptyRange(); + $normalRange = $this->createSimpleRange(); + + $this->assertTrue($emptyRange->isExplicitlyEmpty(), 'Empty range should be explicitly empty'); + $this->assertFalse($normalRange->isExplicitlyEmpty(), 'Normal range should not be explicitly empty'); + } + /** * Create a simple range for basic testing. * diff --git a/tests/Unit/MartinGeorgiev/Doctrine/DBAL/Types/ValueObject/DateRangeTest.php b/tests/Unit/MartinGeorgiev/Doctrine/DBAL/Types/ValueObject/DateRangeTest.php index 88e242be..93bdcf25 100644 --- a/tests/Unit/MartinGeorgiev/Doctrine/DBAL/Types/ValueObject/DateRangeTest.php +++ b/tests/Unit/MartinGeorgiev/Doctrine/DBAL/Types/ValueObject/DateRangeTest.php @@ -234,6 +234,7 @@ public function throws_exception_for_invalid_lower_bound(): void $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('Lower bound must be DateTimeInterface'); + /* @phpstan-ignore-next-line Intentionally testing invalid input */ new DateRange('invalid', new \DateTimeImmutable('2023-12-31')); } @@ -243,6 +244,7 @@ public function throws_exception_for_invalid_upper_bound(): void $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('Upper bound must be DateTimeInterface'); + /* @phpstan-ignore-next-line Intentionally testing invalid input */ new DateRange(new \DateTimeImmutable('2023-01-01'), 'invalid'); } diff --git a/tests/Unit/MartinGeorgiev/Doctrine/DBAL/Types/ValueObject/NumericRangeTest.php b/tests/Unit/MartinGeorgiev/Doctrine/DBAL/Types/ValueObject/NumericRangeTest.php index 280277d7..c69d9ab8 100644 --- a/tests/Unit/MartinGeorgiev/Doctrine/DBAL/Types/ValueObject/NumericRangeTest.php +++ b/tests/Unit/MartinGeorgiev/Doctrine/DBAL/Types/ValueObject/NumericRangeTest.php @@ -116,6 +116,7 @@ public function throws_exception_for_invalid_lower_bound(): void $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('Lower bound must be numeric'); + /* @phpstan-ignore-next-line Intentionally testing invalid input */ new NumericRange('invalid', 10); } @@ -125,6 +126,7 @@ public function throws_exception_for_invalid_upper_bound(): void $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('Upper bound must be numeric'); + /* @phpstan-ignore-next-line Intentionally testing invalid input */ new NumericRange(1, 'invalid'); }