Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/MartinGeorgiev/Doctrine/DBAL/Types/ValueObject/Range.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}

Expand All @@ -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');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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');
}

Expand Down
Loading