Skip to content

Commit 9ba319e

Browse files
fix(#473): add public getter methods to Range value objects (#477)
1 parent 75b025d commit 9ba319e

File tree

4 files changed

+88
-0
lines changed

4 files changed

+88
-0
lines changed

src/MartinGeorgiev/Doctrine/DBAL/Types/ValueObject/Range.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ abstract class Range implements \Stringable
2323

2424
protected const EMPTY_RANGE_STRING = 'empty';
2525

26+
/**
27+
* @param R|null $lower
28+
* @param R|null $upper
29+
*/
2630
public function __construct(
2731
protected readonly mixed $lower,
2832
protected readonly mixed $upper,
@@ -140,4 +144,29 @@ public static function infinite(): static
140144
{
141145
return new static(null, null, false, false);
142146
}
147+
148+
public function getLower(): \DateTimeInterface|float|int|null
149+
{
150+
return $this->lower;
151+
}
152+
153+
public function getUpper(): \DateTimeInterface|float|int|null
154+
{
155+
return $this->upper;
156+
}
157+
158+
public function isLowerBracketInclusive(): bool
159+
{
160+
return $this->isLowerBracketInclusive;
161+
}
162+
163+
public function isUpperBracketInclusive(): bool
164+
{
165+
return $this->isUpperBracketInclusive;
166+
}
167+
168+
public function isExplicitlyEmpty(): bool
169+
{
170+
return $this->isExplicitlyEmpty;
171+
}
143172
}

tests/Unit/MartinGeorgiev/Doctrine/DBAL/Types/ValueObject/BaseRangeTestCase.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,61 @@ public function can_handle_comparison_via_is_empty(): void
110110
}
111111
}
112112

113+
#[Test]
114+
public function can_get_lower_bound(): void
115+
{
116+
$range = $this->createSimpleRange();
117+
$lower = $range->getLower();
118+
119+
$this->assertNotNull($lower, 'Simple range should have a lower bound');
120+
}
121+
122+
#[Test]
123+
public function can_get_upper_bound(): void
124+
{
125+
$range = $this->createSimpleRange();
126+
$upper = $range->getUpper();
127+
128+
$this->assertNotNull($upper, 'Simple range should have an upper bound');
129+
}
130+
131+
#[Test]
132+
public function can_get_null_bounds_for_infinite_range(): void
133+
{
134+
$range = $this->createInfiniteRange();
135+
136+
$this->assertNull($range->getLower(), 'Infinite range should have null lower bound');
137+
$this->assertNull($range->getUpper(), 'Infinite range should have null upper bound');
138+
}
139+
140+
#[Test]
141+
public function can_get_bracket_inclusivity(): void
142+
{
143+
$range = $this->createSimpleRange();
144+
145+
$this->assertTrue($range->isLowerBracketInclusive(), 'Simple range should have inclusive lower bracket');
146+
$this->assertFalse($range->isUpperBracketInclusive(), 'Simple range should have exclusive upper bracket');
147+
}
148+
149+
#[Test]
150+
public function can_get_inclusive_bracket_state(): void
151+
{
152+
$range = $this->createInclusiveRange();
153+
154+
$this->assertTrue($range->isLowerBracketInclusive(), 'Inclusive range should have inclusive lower bracket');
155+
$this->assertTrue($range->isUpperBracketInclusive(), 'Inclusive range should have inclusive upper bracket');
156+
}
157+
158+
#[Test]
159+
public function can_get_explicitly_empty_state(): void
160+
{
161+
$emptyRange = $this->createEmptyRange();
162+
$normalRange = $this->createSimpleRange();
163+
164+
$this->assertTrue($emptyRange->isExplicitlyEmpty(), 'Empty range should be explicitly empty');
165+
$this->assertFalse($normalRange->isExplicitlyEmpty(), 'Normal range should not be explicitly empty');
166+
}
167+
113168
/**
114169
* Create a simple range for basic testing.
115170
*

tests/Unit/MartinGeorgiev/Doctrine/DBAL/Types/ValueObject/DateRangeTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ public function throws_exception_for_invalid_lower_bound(): void
234234
$this->expectException(\InvalidArgumentException::class);
235235
$this->expectExceptionMessage('Lower bound must be DateTimeInterface');
236236

237+
/* @phpstan-ignore-next-line Intentionally testing invalid input */
237238
new DateRange('invalid', new \DateTimeImmutable('2023-12-31'));
238239
}
239240

@@ -243,6 +244,7 @@ public function throws_exception_for_invalid_upper_bound(): void
243244
$this->expectException(\InvalidArgumentException::class);
244245
$this->expectExceptionMessage('Upper bound must be DateTimeInterface');
245246

247+
/* @phpstan-ignore-next-line Intentionally testing invalid input */
246248
new DateRange(new \DateTimeImmutable('2023-01-01'), 'invalid');
247249
}
248250

tests/Unit/MartinGeorgiev/Doctrine/DBAL/Types/ValueObject/NumericRangeTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ public function throws_exception_for_invalid_lower_bound(): void
116116
$this->expectException(\InvalidArgumentException::class);
117117
$this->expectExceptionMessage('Lower bound must be numeric');
118118

119+
/* @phpstan-ignore-next-line Intentionally testing invalid input */
119120
new NumericRange('invalid', 10);
120121
}
121122

@@ -125,6 +126,7 @@ public function throws_exception_for_invalid_upper_bound(): void
125126
$this->expectException(\InvalidArgumentException::class);
126127
$this->expectExceptionMessage('Upper bound must be numeric');
127128

129+
/* @phpstan-ignore-next-line Intentionally testing invalid input */
128130
new NumericRange(1, 'invalid');
129131
}
130132

0 commit comments

Comments
 (0)