mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 05:44:24 +00:00
fix test which randomly failed
This commit is contained in:
parent
0e9933ca41
commit
7a6117a264
@ -1264,15 +1264,24 @@ class Person implements HasCenterInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function getCurrentHousehold(?\DateTimeImmutable $at = null): ?Household
|
public function getCurrentHousehold(?\DateTimeImmutable $at = null): ?Household
|
||||||
|
{
|
||||||
|
$participation = $this->getCurrentHouseholdParticipationShareHousehold($at);
|
||||||
|
|
||||||
|
return $participation instanceof HouseholdMember ?
|
||||||
|
$participation->getHousehold()
|
||||||
|
: null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCurrentHouseholdParticipationShareHousehold(?\DateTimeImmutable $at = null): ?HouseholdMember
|
||||||
{
|
{
|
||||||
$criteria = new Criteria();
|
$criteria = new Criteria();
|
||||||
$expr = Criteria::expr();
|
$expr = Criteria::expr();
|
||||||
$date = NULL === $at ? new \DateTimeImmutable('now') : $at;
|
$date = NULL === $at ? new \DateTimeImmutable('today') : $at;
|
||||||
$datef = $date->format('Y-m-d');
|
$datef = $date->format('Y-m-d');
|
||||||
|
|
||||||
if (
|
if (
|
||||||
NULL !== ($this->currentHouseholdAt[$datef] ?? NULL)) {
|
NULL !== ($this->currentHouseholdParticipationAt[$datef] ?? NULL)) {
|
||||||
return $this->currentHouseholdAt[$datef];
|
return $this->currentHouseholdParticipationAt[$datef];
|
||||||
}
|
}
|
||||||
|
|
||||||
$criteria
|
$criteria
|
||||||
@ -1281,7 +1290,7 @@ class Person implements HasCenterInterface
|
|||||||
$expr->lte('startDate', $date),
|
$expr->lte('startDate', $date),
|
||||||
$expr->orX(
|
$expr->orX(
|
||||||
$expr->isNull('endDate'),
|
$expr->isNull('endDate'),
|
||||||
$expr->gte('endDate', $date)
|
$expr->gt('endDate', $date)
|
||||||
),
|
),
|
||||||
$expr->eq('shareHousehold', true)
|
$expr->eq('shareHousehold', true)
|
||||||
)
|
)
|
||||||
@ -1292,8 +1301,7 @@ class Person implements HasCenterInterface
|
|||||||
;
|
;
|
||||||
|
|
||||||
return $participations->count() > 0 ?
|
return $participations->count() > 0 ?
|
||||||
$this->currentHouseholdAt[$datef] = $participations->first()
|
$this->currentHouseholdParticipationAt[$datef] = $participations->first()
|
||||||
->getHousehold()
|
|
||||||
: null;
|
: null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,6 +61,19 @@ class HouseholdMemberControllerTest extends WebTestCase
|
|||||||
],
|
],
|
||||||
true)
|
true)
|
||||||
);
|
);
|
||||||
|
if ($client->getResponse()->getStatusCode() === 422) {
|
||||||
|
var_dump(\json_decode($client->getResponse()->getContent(), true));
|
||||||
|
var_dump($date);
|
||||||
|
|
||||||
|
$household = self::$container->get(EntityManagerInterface::class)
|
||||||
|
->getRepository(Household::class)
|
||||||
|
->find($householdId);
|
||||||
|
|
||||||
|
$ms = $household->getMembers()->filter(fn ($m) => $m->getPerson()->getId() === $personId);
|
||||||
|
foreach ($ms as $m) {
|
||||||
|
var_dump("id: {$m->getId()}, startDate: {$m->getStartDate()} endDate: {$m->getEndDate()}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$this->assertEquals(Response::HTTP_OK,
|
$this->assertEquals(Response::HTTP_OK,
|
||||||
$client->getResponse()->getStatusCode()
|
$client->getResponse()->getStatusCode()
|
||||||
@ -111,6 +124,20 @@ class HouseholdMemberControllerTest extends WebTestCase
|
|||||||
true)
|
true)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if ($client->getResponse()->getStatusCode() === 422) {
|
||||||
|
var_dump(\json_decode($client->getResponse()->getContent(), true));
|
||||||
|
var_dump($date);
|
||||||
|
|
||||||
|
$household = self::$container->get(EntityManagerInterface::class)
|
||||||
|
->getRepository(Household::class)
|
||||||
|
->find($householdId);
|
||||||
|
|
||||||
|
$ms = $household->getMembers()->filter(fn ($m) => $m->getPerson()->getId() === $personId);
|
||||||
|
foreach ($ms as $m) {
|
||||||
|
var_dump("id: {$m->getId()}, startDate: {$m->getStartDate()} endDate: {$m->getEndDate()}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$this->assertEquals(Response::HTTP_OK,
|
$this->assertEquals(Response::HTTP_OK,
|
||||||
$client->getResponse()->getStatusCode()
|
$client->getResponse()->getStatusCode()
|
||||||
);
|
);
|
||||||
@ -168,6 +195,19 @@ class HouseholdMemberControllerTest extends WebTestCase
|
|||||||
true)
|
true)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if ($client->getResponse()->getStatusCode() === 422) {
|
||||||
|
var_dump(\json_decode($client->getResponse()->getContent(), true));
|
||||||
|
var_dump($date);
|
||||||
|
|
||||||
|
$household = self::$container->get(EntityManagerInterface::class)
|
||||||
|
->getRepository(Household::class)
|
||||||
|
->find($householdId);
|
||||||
|
|
||||||
|
$ms = $household->getMembers()->filter(fn ($m) => $m->getPerson()->getId() === $personId);
|
||||||
|
foreach ($ms as $m) {
|
||||||
|
var_dump("id: {$m->getId()}, startDate: {$m->getStartDate()} endDate: {$m->getEndDate()}");
|
||||||
|
}
|
||||||
|
}
|
||||||
$this->assertEquals(Response::HTTP_OK,
|
$this->assertEquals(Response::HTTP_OK,
|
||||||
$client->getResponse()->getStatusCode()
|
$client->getResponse()->getStatusCode()
|
||||||
);
|
);
|
||||||
@ -205,19 +245,18 @@ class HouseholdMemberControllerTest extends WebTestCase
|
|||||||
{
|
{
|
||||||
self::bootKernel();
|
self::bootKernel();
|
||||||
$em = self::$container->get(EntityManagerInterface::class);
|
$em = self::$container->get(EntityManagerInterface::class);
|
||||||
|
$yesterday = new \DateTimeImmutable('yesterday');
|
||||||
|
|
||||||
$personIds = $em->createQuery("SELECT p.id FROM ".Person::class." p ".
|
$personIds = $em->createQuery("SELECT p.id FROM ".Person::class." p ".
|
||||||
"JOIN p.center c ".
|
"JOIN p.center c ".
|
||||||
"JOIN p.householdParticipations hp ".
|
|
||||||
"WHERE ".
|
"WHERE ".
|
||||||
"c.name = :center ".
|
"c.name = :center "
|
||||||
"AND hp.startDate < CURRENT_DATE() ".
|
|
||||||
"AND hp.endDate IS NULL "
|
|
||||||
)
|
)
|
||||||
->setParameter('center', "Center A")
|
->setParameter('center', "Center A")
|
||||||
->setMaxResults(100)
|
->setMaxResults(100)
|
||||||
->getScalarResult()
|
->getScalarResult()
|
||||||
;
|
;
|
||||||
|
|
||||||
\shuffle($personIds);
|
\shuffle($personIds);
|
||||||
|
|
||||||
$household = new Household();
|
$household = new Household();
|
||||||
@ -229,12 +268,29 @@ class HouseholdMemberControllerTest extends WebTestCase
|
|||||||
->getResult()
|
->getResult()
|
||||||
;
|
;
|
||||||
|
|
||||||
yield [
|
$i = 0;
|
||||||
\array_pop($personIds)['id'],
|
do {
|
||||||
$household->getId(),
|
$id = \array_pop($personIds)['id'];
|
||||||
$positions[\random_int(0, count($positions) - 1)]['id'],
|
$person = self::$container->get(EntityManagerInterface::class)
|
||||||
new \DateTimeImmutable('today')
|
->getRepository(Person::Class)
|
||||||
];
|
->find($id);
|
||||||
|
|
||||||
|
$participation = $person->getCurrentHouseholdParticipationShareHousehold();
|
||||||
|
|
||||||
|
if (NULL !== $participation && NULL === $participation->getEndDate()
|
||||||
|
&& $participation->getStartDate() > $yesterday) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$i++;
|
||||||
|
|
||||||
|
yield [
|
||||||
|
$id,
|
||||||
|
$household->getId(),
|
||||||
|
$positions[\random_int(0, count($positions) - 1)]['id'],
|
||||||
|
new \DateTimeImmutable('tomorrow')
|
||||||
|
];
|
||||||
|
} while ($i <= 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function provideValidDataEditMember(): \Iterator
|
public function provideValidDataEditMember(): \Iterator
|
||||||
|
Loading…
x
Reference in New Issue
Block a user