mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 15:13:50 +00:00
cs: Fix code style (safe rules only).
This commit is contained in:
@@ -1,35 +1,47 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Tests\Util;
|
||||
|
||||
use Chill\MainBundle\Util\DateRangeCovering;
|
||||
use DateTime;
|
||||
use DateTimeZone;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use function usort;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
class DateRangeCoveringTest extends TestCase
|
||||
{
|
||||
|
||||
public function testCoveringWithMinCover1()
|
||||
{
|
||||
$cover = new DateRangeCovering(1, new \DateTimeZone('Europe/Brussels'));
|
||||
$cover = new DateRangeCovering(1, new DateTimeZone('Europe/Brussels'));
|
||||
$cover
|
||||
->add(new \DateTime('2010-01-01'), new \DateTime('2010-12-01'), 1)
|
||||
->add(new \DateTime('2010-06-01'), new \DateTime('2011-06-01'), 2)
|
||||
->add(new \DateTime('2019-06-01'), new \DateTime('2019-06-01'), 3)
|
||||
->compute()
|
||||
;
|
||||
->add(new DateTime('2010-01-01'), new DateTime('2010-12-01'), 1)
|
||||
->add(new DateTime('2010-06-01'), new DateTime('2011-06-01'), 2)
|
||||
->add(new DateTime('2019-06-01'), new DateTime('2019-06-01'), 3)
|
||||
->compute();
|
||||
|
||||
$this->assertTrue($cover->hasIntersections());
|
||||
$this->assertIsArray($cover->getIntersections());
|
||||
$this->assertCount(1, $cover->getIntersections());
|
||||
$this->assertEquals(
|
||||
new \DateTime('2010-06-01'),
|
||||
new DateTime('2010-06-01'),
|
||||
$cover->getIntersections()[0][0],
|
||||
"assert date start are the intersection"
|
||||
'assert date start are the intersection'
|
||||
);
|
||||
$this->assertEquals(
|
||||
new \DateTime('2010-12-01'),
|
||||
new DateTime('2010-12-01'),
|
||||
$cover->getIntersections()[0][1],
|
||||
"assert date end are the intersection"
|
||||
'assert date end are the intersection'
|
||||
);
|
||||
$this->assertIsArray($cover->getIntersections()[0][2]);
|
||||
$this->assertContains(1, $cover->getIntersections()[0][2]);
|
||||
@@ -37,28 +49,26 @@ class DateRangeCoveringTest extends TestCase
|
||||
$this->assertNotContains(3, $cover->getIntersections()[0][2]);
|
||||
}
|
||||
|
||||
public function testCoveringWithMinCover1_NoCoveringWithNullDates()
|
||||
public function testCoveringWithMinCover1NoCoveringWithNullDates()
|
||||
{
|
||||
$cover = new DateRangeCovering(1, new \DateTimeZone('Europe/Brussels'));
|
||||
$cover = new DateRangeCovering(1, new DateTimeZone('Europe/Brussels'));
|
||||
$cover
|
||||
->add(new \DateTime('2021-10-05'), new \DateTime('2021-10-18'), 521)
|
||||
->add(new \DateTime('2021-10-26'), null, 663)
|
||||
->compute()
|
||||
;
|
||||
->add(new DateTime('2021-10-05'), new DateTime('2021-10-18'), 521)
|
||||
->add(new DateTime('2021-10-26'), null, 663)
|
||||
->compute();
|
||||
|
||||
$this->assertFalse($cover->hasIntersections());
|
||||
}
|
||||
|
||||
public function testCoveringWithMinCover1WithTwoIntersections()
|
||||
{
|
||||
$cover = new DateRangeCovering(1, new \DateTimeZone('Europe/Brussels'));
|
||||
$cover = new DateRangeCovering(1, new DateTimeZone('Europe/Brussels'));
|
||||
$cover
|
||||
->add(new \DateTime('2010-01-01'), new \DateTime('2010-12-01'), 1)
|
||||
->add(new \DateTime('2010-06-01'), new \DateTime('2011-06-01'), 2)
|
||||
->add(new \DateTime('2019-01-01'), new \DateTime('2019-12-01'), 3)
|
||||
->add(new \DateTime('2019-06-01'), new \DateTime('2020-06-01'), 4)
|
||||
->compute()
|
||||
;
|
||||
->add(new DateTime('2010-01-01'), new DateTime('2010-12-01'), 1)
|
||||
->add(new DateTime('2010-06-01'), new DateTime('2011-06-01'), 2)
|
||||
->add(new DateTime('2019-01-01'), new DateTime('2019-12-01'), 3)
|
||||
->add(new DateTime('2019-06-01'), new DateTime('2020-06-01'), 4)
|
||||
->compute();
|
||||
|
||||
$this->assertTrue($cover->hasIntersections());
|
||||
$this->assertIsArray($cover->getIntersections());
|
||||
@@ -67,7 +77,7 @@ class DateRangeCoveringTest extends TestCase
|
||||
$intersections = $cover->getIntersections();
|
||||
|
||||
// sort the intersections to compare them in expected order
|
||||
\usort($intersections, function($a, $b) {
|
||||
usort($intersections, function ($a, $b) {
|
||||
if ($a[0] === $b[0]) {
|
||||
return $a[1] <=> $b[1];
|
||||
}
|
||||
@@ -77,14 +87,14 @@ class DateRangeCoveringTest extends TestCase
|
||||
|
||||
// first intersection
|
||||
$this->assertEquals(
|
||||
new \DateTime('2010-06-01'),
|
||||
new DateTime('2010-06-01'),
|
||||
$intersections[0][0],
|
||||
"assert date start are the intersection"
|
||||
'assert date start are the intersection'
|
||||
);
|
||||
$this->assertEquals(
|
||||
new \DateTime('2010-12-01'),
|
||||
new DateTime('2010-12-01'),
|
||||
$intersections[0][1],
|
||||
"assert date end are the intersection"
|
||||
'assert date end are the intersection'
|
||||
);
|
||||
$this->assertIsArray($intersections[0][2]);
|
||||
$this->assertContains(1, $intersections[0][2]);
|
||||
@@ -94,14 +104,14 @@ class DateRangeCoveringTest extends TestCase
|
||||
|
||||
// second intersection
|
||||
$this->assertEquals(
|
||||
new \DateTime('2019-06-01'),
|
||||
new DateTime('2019-06-01'),
|
||||
$intersections[1][0],
|
||||
"assert date start are the intersection"
|
||||
'assert date start are the intersection'
|
||||
);
|
||||
$this->assertEquals(
|
||||
new \DateTime('2019-12-01'),
|
||||
new DateTime('2019-12-01'),
|
||||
$intersections[1][1],
|
||||
"assert date end are the intersection"
|
||||
'assert date end are the intersection'
|
||||
);
|
||||
$this->assertIsArray($intersections[1][2]);
|
||||
$this->assertContains(3, $intersections[1][2]);
|
||||
@@ -112,28 +122,27 @@ class DateRangeCoveringTest extends TestCase
|
||||
|
||||
public function testCoveringWithMinCover2()
|
||||
{
|
||||
$cover = new DateRangeCovering(2, new \DateTimeZone('Europe/Brussels'));
|
||||
$cover = new DateRangeCovering(2, new DateTimeZone('Europe/Brussels'));
|
||||
$cover
|
||||
->add(new \DateTime('2010-01-01'), new \DateTime('2010-10-01'), 1)
|
||||
->add(new \DateTime('2010-06-01'), new \DateTime('2010-09-01'), 2)
|
||||
->add(new \DateTime('2010-04-01'), new \DateTime('2010-12-01'), 3)
|
||||
->add(new \DateTime('2019-01-01'), new \DateTime('2019-10-01'), 4)
|
||||
->add(new \DateTime('2019-06-01'), new \DateTime('2019-09-01'), 5)
|
||||
->compute()
|
||||
;
|
||||
->add(new DateTime('2010-01-01'), new DateTime('2010-10-01'), 1)
|
||||
->add(new DateTime('2010-06-01'), new DateTime('2010-09-01'), 2)
|
||||
->add(new DateTime('2010-04-01'), new DateTime('2010-12-01'), 3)
|
||||
->add(new DateTime('2019-01-01'), new DateTime('2019-10-01'), 4)
|
||||
->add(new DateTime('2019-06-01'), new DateTime('2019-09-01'), 5)
|
||||
->compute();
|
||||
$this->assertTrue($cover->hasIntersections());
|
||||
$this->assertIsArray($cover->getIntersections());
|
||||
$this->assertCount(1, $cover->getIntersections());
|
||||
|
||||
$this->assertEquals(
|
||||
new \DateTime('2010-06-01'),
|
||||
new DateTime('2010-06-01'),
|
||||
$cover->getIntersections()[0][0],
|
||||
"assert date start are the intersection"
|
||||
'assert date start are the intersection'
|
||||
);
|
||||
$this->assertEquals(
|
||||
new \DateTime('2010-09-01'),
|
||||
new DateTime('2010-09-01'),
|
||||
$cover->getIntersections()[0][1],
|
||||
"assert date end are the intersection"
|
||||
'assert date end are the intersection'
|
||||
);
|
||||
$this->assertIsArray($cover->getIntersections()[0][2]);
|
||||
$this->assertContains(1, $cover->getIntersections()[0][2]);
|
||||
@@ -145,30 +154,29 @@ class DateRangeCoveringTest extends TestCase
|
||||
|
||||
public function testCoveringWithMinCover2AndThreePeriodsCovering()
|
||||
{
|
||||
$cover = new DateRangeCovering(2, new \DateTimeZone('Europe/Brussels'));
|
||||
$cover = new DateRangeCovering(2, new DateTimeZone('Europe/Brussels'));
|
||||
$cover
|
||||
->add(new \DateTime('2010-01-01'), new \DateTime('2010-10-01'), 1)
|
||||
->add(new \DateTime('2010-06-01'), new \DateTime('2010-09-01'), 2)
|
||||
->add(new \DateTime('2010-04-01'), new \DateTime('2010-12-01'), 3)
|
||||
->add(new \DateTime('2009-01-01'), new \DateTime('2010-09-15'), 4)
|
||||
->add(new \DateTime('2019-01-01'), new \DateTime('2019-10-01'), 5)
|
||||
->add(new \DateTime('2019-06-01'), new \DateTime('2019-09-01'), 6)
|
||||
->compute()
|
||||
;
|
||||
->add(new DateTime('2010-01-01'), new DateTime('2010-10-01'), 1)
|
||||
->add(new DateTime('2010-06-01'), new DateTime('2010-09-01'), 2)
|
||||
->add(new DateTime('2010-04-01'), new DateTime('2010-12-01'), 3)
|
||||
->add(new DateTime('2009-01-01'), new DateTime('2010-09-15'), 4)
|
||||
->add(new DateTime('2019-01-01'), new DateTime('2019-10-01'), 5)
|
||||
->add(new DateTime('2019-06-01'), new DateTime('2019-09-01'), 6)
|
||||
->compute();
|
||||
|
||||
$this->assertTrue($cover->hasIntersections());
|
||||
$this->assertIsArray($cover->getIntersections());
|
||||
$this->assertCount(1, $cover->getIntersections());
|
||||
|
||||
$this->assertEquals(
|
||||
new \DateTime('2010-04-01'),
|
||||
new DateTime('2010-04-01'),
|
||||
$cover->getIntersections()[0][0],
|
||||
"assert date start are the intersection"
|
||||
'assert date start are the intersection'
|
||||
);
|
||||
$this->assertEquals(
|
||||
new \DateTime('2010-09-15'),
|
||||
new DateTime('2010-09-15'),
|
||||
$cover->getIntersections()[0][1],
|
||||
"assert date end are the intersection"
|
||||
'assert date end are the intersection'
|
||||
);
|
||||
$this->assertIsArray($cover->getIntersections()[0][2]);
|
||||
$this->assertContains(1, $cover->getIntersections()[0][2]);
|
||||
@@ -181,46 +189,43 @@ class DateRangeCoveringTest extends TestCase
|
||||
|
||||
public function testCoveringWithMinCover2AndThreePeriodsCoveringWithNullMetadata()
|
||||
{
|
||||
$cover = new DateRangeCovering(2, new \DateTimeZone('Europe/Brussels'));
|
||||
$cover = new DateRangeCovering(2, new DateTimeZone('Europe/Brussels'));
|
||||
$cover
|
||||
->add(new \DateTime('2010-01-01'), new \DateTime('2010-10-01'), null)
|
||||
->add(new \DateTime('2010-06-01'), new \DateTime('2010-09-01'), null)
|
||||
->add(new \DateTime('2010-04-01'), new \DateTime('2010-12-01'), null)
|
||||
->add(new \DateTime('2009-01-01'), new \DateTime('2010-09-15'), null)
|
||||
->add(new \DateTime('2019-01-01'), new \DateTime('2019-10-01'), null)
|
||||
->add(new \DateTime('2019-06-01'), new \DateTime('2019-09-01'), null)
|
||||
->compute()
|
||||
;
|
||||
->add(new DateTime('2010-01-01'), new DateTime('2010-10-01'), null)
|
||||
->add(new DateTime('2010-06-01'), new DateTime('2010-09-01'), null)
|
||||
->add(new DateTime('2010-04-01'), new DateTime('2010-12-01'), null)
|
||||
->add(new DateTime('2009-01-01'), new DateTime('2010-09-15'), null)
|
||||
->add(new DateTime('2019-01-01'), new DateTime('2019-10-01'), null)
|
||||
->add(new DateTime('2019-06-01'), new DateTime('2019-09-01'), null)
|
||||
->compute();
|
||||
|
||||
$this->assertTrue($cover->hasIntersections());
|
||||
$this->assertIsArray($cover->getIntersections());
|
||||
$this->assertCount(1, $cover->getIntersections());
|
||||
|
||||
$this->assertEquals(
|
||||
new \DateTime('2010-04-01'),
|
||||
new DateTime('2010-04-01'),
|
||||
$cover->getIntersections()[0][0],
|
||||
"assert date start are the intersection"
|
||||
'assert date start are the intersection'
|
||||
);
|
||||
$this->assertEquals(
|
||||
new \DateTime('2010-09-15'),
|
||||
new DateTime('2010-09-15'),
|
||||
$cover->getIntersections()[0][1],
|
||||
"assert date end are the intersection"
|
||||
'assert date end are the intersection'
|
||||
);
|
||||
$this->assertIsArray($cover->getIntersections()[0][2]);
|
||||
}
|
||||
|
||||
|
||||
public function testCoveringWithMinCover3Absent()
|
||||
{
|
||||
$cover = new DateRangeCovering(3, new \DateTimeZone('Europe/Brussels'));
|
||||
$cover = new DateRangeCovering(3, new DateTimeZone('Europe/Brussels'));
|
||||
$cover
|
||||
->add(new \DateTime('2010-01-01'), new \DateTime('2010-10-01'), 1)
|
||||
->add(new \DateTime('2010-06-01'), new \DateTime('2010-09-01'), 2)
|
||||
->add(new \DateTime('2010-04-01'), new \DateTime('2010-12-01'), 3)
|
||||
->add(new \DateTime('2019-01-01'), new \DateTime('2019-10-01'), 4)
|
||||
->add(new \DateTime('2019-06-01'), new \DateTime('2019-09-01'), 5)
|
||||
->compute()
|
||||
;
|
||||
->add(new DateTime('2010-01-01'), new DateTime('2010-10-01'), 1)
|
||||
->add(new DateTime('2010-06-01'), new DateTime('2010-09-01'), 2)
|
||||
->add(new DateTime('2010-04-01'), new DateTime('2010-12-01'), 3)
|
||||
->add(new DateTime('2019-01-01'), new DateTime('2019-10-01'), 4)
|
||||
->add(new DateTime('2019-06-01'), new DateTime('2019-09-01'), 5)
|
||||
->compute();
|
||||
$this->assertFalse($cover->hasIntersections());
|
||||
$this->assertIsArray($cover->getIntersections());
|
||||
$this->assertCount(0, $cover->getIntersections());
|
||||
|
Reference in New Issue
Block a user