-
Notifications
You must be signed in to change notification settings - Fork 14
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
7 changed files
with
331 additions
and
5 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
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
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
5 changes: 5 additions & 0 deletions
5
...contracts/Repository/Values/Content/Query/Aggregation/Ranges/RangesGeneratorInterface.php
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
114 changes: 114 additions & 0 deletions
114
...re/Repository/Values/Content/Query/Aggregation/Ranges/DateTimeStepRangesGeneratorTest.php
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,114 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\Tests\Integration\Core\Repository\Values\Content\Query\Aggregation\Ranges; | ||
|
||
use DateInterval; | ||
use DateTimeImmutable; | ||
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Aggregation\Range; | ||
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Aggregation\Ranges\DateTimeStepRangesGenerator; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class DateTimeStepRangesGeneratorTest extends TestCase | ||
{ | ||
public function testGenerateOpenRangesSequence(): void | ||
{ | ||
self::assertGeneratorResults( | ||
[ | ||
$this->createRange(Range::INF, '01-01-2023'), | ||
$this->createRange('01-01-2023', '02-01-2023'), | ||
$this->createRange('02-01-2023', '03-01-2023'), | ||
$this->createRange('03-01-2023', Range::INF), | ||
], | ||
new DateTimeStepRangesGenerator( | ||
new DateTimeImmutable('01-01-2023 00:00:00'), | ||
new DateTimeImmutable('03-01-2023 00:00:00') | ||
) | ||
); | ||
} | ||
|
||
public function testGenerateCloseRangesSequence(): void | ||
{ | ||
$generator = new DateTimeStepRangesGenerator( | ||
new DateTimeImmutable('01-01-2023 00:00:00'), | ||
new DateTimeImmutable('03-01-2023 00:00:00') | ||
); | ||
$generator->setLeftOpen(false); | ||
$generator->setRightOpen(false); | ||
|
||
self::assertGeneratorResults( | ||
[ | ||
$this->createRange('01-01-2023', '02-01-2023'), | ||
$this->createRange('02-01-2023', '03-01-2023'), | ||
], | ||
$generator | ||
); | ||
} | ||
|
||
public function testGenerateRangesWithCustomStep(): void | ||
{ | ||
$generator = new DateTimeStepRangesGenerator( | ||
new DateTimeImmutable('01-01-2023 00:00:00'), | ||
new DateTimeImmutable('05-01-2023 00:00:00') | ||
); | ||
$generator->setStep(new DateInterval('P2D')); | ||
|
||
self::assertGeneratorResults( | ||
[ | ||
$this->createRange(Range::INF, '01-01-2023'), | ||
$this->createRange('01-01-2023', '03-01-2023'), | ||
$this->createRange('03-01-2023', '05-01-2023'), | ||
$this->createRange('05-01-2023', Range::INF), | ||
], | ||
$generator | ||
); | ||
} | ||
|
||
public function testGenerateInfRangesSequence(): void | ||
{ | ||
$generator = new DateTimeStepRangesGenerator( | ||
new DateTimeImmutable('01-01-1970 00:00:00'), | ||
new DateTimeImmutable('01-01-1970 00:00:00'), | ||
); | ||
|
||
self::assertGeneratorResults( | ||
[ | ||
Range::ofDateTime(Range::INF, Range::INF), | ||
], | ||
$generator | ||
); | ||
} | ||
|
||
public function testGenerateEmptyRangesSequence(): void | ||
{ | ||
$generator = new DateTimeStepRangesGenerator( | ||
new DateTimeImmutable('01-01-1970 00:00:00'), | ||
new DateTimeImmutable('01-01-1970 00:00:00'), | ||
); | ||
$generator->setLeftOpen(false); | ||
$generator->setRightOpen(false); | ||
|
||
self::assertGeneratorResults([], $generator); | ||
} | ||
|
||
private function createRange(?string $start, ?string $end): Range | ||
{ | ||
return Range::ofDateTime( | ||
$start !== null ? new DateTimeImmutable($start . ' 00:00:00') : null, | ||
$end !== null ? new DateTimeImmutable($end . ' 00:00:00') : null | ||
); | ||
} | ||
|
||
/** | ||
* @param \Ibexa\Contracts\Core\Repository\Values\Content\Query\Aggregation\Range[] $expectedResult | ||
*/ | ||
private static function assertGeneratorResults(array $expectedResult, DateTimeStepRangesGenerator $generator): void | ||
{ | ||
self::assertEquals($expectedResult, $generator->generate()); | ||
} | ||
} |
91 changes: 91 additions & 0 deletions
91
.../Core/Repository/Values/Content/Query/Aggregation/Ranges/FloatStepRangesGeneratorTest.php
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,91 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\Tests\Integration\Core\Repository\Values\Content\Query\Aggregation\Ranges; | ||
|
||
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Aggregation\Range; | ||
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Aggregation\Ranges\FloatStepRangesGenerator; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class FloatStepRangesGeneratorTest extends TestCase | ||
{ | ||
public function testGenerateOpenRangesSequence(): void | ||
{ | ||
self::assertGeneratorResults( | ||
[ | ||
Range::ofFloat(Range::INF, 1.0), | ||
Range::ofFloat(1.0, 2.0), | ||
Range::ofFloat(2.0, 3.0), | ||
Range::ofFloat(3.0, Range::INF), | ||
], | ||
new FloatStepRangesGenerator(1.0, 3.0) | ||
); | ||
} | ||
|
||
public function testGenerateCloseRangesSequence(): void | ||
{ | ||
$generator = new FloatStepRangesGenerator(1.0, 3.0); | ||
$generator->setLeftOpen(false); | ||
$generator->setRightOpen(false); | ||
|
||
self::assertGeneratorResults( | ||
[ | ||
Range::ofFloat(1.0, 2.0), | ||
Range::ofFloat(2.0, 3.0), | ||
], | ||
$generator | ||
); | ||
} | ||
|
||
public function testGenerateRangesWithCustomStep(): void | ||
{ | ||
$generator = new FloatStepRangesGenerator(1.0, 10.0); | ||
$generator->setStep(2.0); | ||
|
||
self::assertGeneratorResults( | ||
[ | ||
Range::ofFloat(Range::INF, 1.0), | ||
Range::ofFloat(1.0, 3.0), | ||
Range::ofFloat(3.0, 5.0), | ||
Range::ofFloat(5.0, 7.0), | ||
Range::ofFloat(7.0, 9.0), | ||
Range::ofFloat(10.0, Range::INF), | ||
], | ||
$generator | ||
); | ||
} | ||
|
||
public function testGenerateInfRangesSequence(): void | ||
{ | ||
$generator = new FloatStepRangesGenerator(0.0, 0.0); | ||
|
||
self::assertGeneratorResults( | ||
[ | ||
Range::ofFloat(Range::INF, Range::INF), | ||
], | ||
$generator | ||
); | ||
} | ||
|
||
public function testGenerateEmptyRangesSequence(): void | ||
{ | ||
$generator = new FloatStepRangesGenerator(0.0, 0.0); | ||
$generator->setLeftOpen(false); | ||
$generator->setRightOpen(false); | ||
|
||
self::assertGeneratorResults([], $generator); | ||
} | ||
|
||
/** | ||
* @param \Ibexa\Contracts\Core\Repository\Values\Content\Query\Aggregation\Range[] $expectedResult | ||
*/ | ||
private static function assertGeneratorResults(array $expectedResult, FloatStepRangesGenerator $generator): void | ||
{ | ||
self::assertEquals($expectedResult, $generator->generate()); | ||
} | ||
} |
Oops, something went wrong.