mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 22:53:49 +00:00
add a discrimnator type on onbjects
This commit is contained in:
@@ -100,14 +100,14 @@ class AccompanyingCourseApiControllerTest extends WebTestCase
|
||||
[], // parameters
|
||||
[], // files
|
||||
[], // server parameters
|
||||
\json_encode([ 'person_id' => $personId ])
|
||||
\json_encode([ 'type' => 'person', 'id' => $personId ])
|
||||
);
|
||||
$response = $this->client->getResponse();
|
||||
$data = \json_decode($response->getContent(), true);
|
||||
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
$this->assertArrayHasKey('person_id', $data);
|
||||
$this->assertEquals($personId, $data['person_id']);
|
||||
$this->assertArrayHasKey('id', $data);
|
||||
$this->assertEquals($personId, $data['id']);
|
||||
|
||||
// check into database
|
||||
$period = $em->getRepository(AccompanyingPeriod::class)
|
||||
@@ -122,14 +122,14 @@ class AccompanyingCourseApiControllerTest extends WebTestCase
|
||||
[], // parameters
|
||||
[], // files
|
||||
[], // server parameters
|
||||
\json_encode([ 'thirdparty_id' => $thirdPartyId ])
|
||||
\json_encode([ 'type' => 'thirdparty', 'id' => $thirdPartyId ])
|
||||
);
|
||||
$response = $this->client->getResponse();
|
||||
$data = \json_decode($response->getContent(), true);
|
||||
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
$this->assertArrayHasKey('thirdparty_id', $data);
|
||||
$this->assertEquals($thirdPartyId, $data['thirdparty_id']);
|
||||
$this->assertArrayHasKey('id', $data);
|
||||
$this->assertEquals($thirdPartyId, $data['id']);
|
||||
|
||||
// check into database
|
||||
$period = $em->getRepository(AccompanyingPeriod::class)
|
||||
@@ -152,6 +152,36 @@ class AccompanyingCourseApiControllerTest extends WebTestCase
|
||||
$this->assertNull($period->getRequestor());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @dataProvider dataGenerateRandomAccompanyingCourse
|
||||
*/
|
||||
public function testAccompanyingPeriodPatch(int $personId, AccompanyingPeriod $period)
|
||||
{
|
||||
$initialValueEmergency = $period->isEmergency();
|
||||
$em = self::$container->get(EntityManagerInterface::class);
|
||||
|
||||
$this->client->request(
|
||||
Request::METHOD_PATCH,
|
||||
sprintf('/api/1.0/person/accompanying-course/%d.json', $period->getId()),
|
||||
[], // parameters
|
||||
[], // files
|
||||
[], // server parameters
|
||||
\json_encode([ 'type' => 'accompanying_period', 'emergency' => !$initialValueEmergency ])
|
||||
);
|
||||
$response = $this->client->getResponse();
|
||||
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
$period = $em->getRepository(AccompanyingPeriod::class)
|
||||
->find($period->getId());
|
||||
$em->refresh($period);
|
||||
$this->assertEquals(!$initialValueEmergency, $period->isEmergency());
|
||||
|
||||
// restore the initial valud
|
||||
$period->setEmergency($initialValueEmergency);
|
||||
$em->flush();
|
||||
}
|
||||
|
||||
public function dataGenerateRandomRequestorValidData(): \Iterator
|
||||
{
|
||||
$dataLength = 2;
|
||||
@@ -208,7 +238,7 @@ class AccompanyingCourseApiControllerTest extends WebTestCase
|
||||
[], // parameters
|
||||
[], // files
|
||||
[], // server parameters
|
||||
\json_encode([ 'person_id' => $personId ])
|
||||
\json_encode([ 'type' => 'person', 'id' => $personId ])
|
||||
);
|
||||
$response = $this->client->getResponse();
|
||||
$data = \json_decode($response->getContent(), true);
|
||||
@@ -227,7 +257,7 @@ class AccompanyingCourseApiControllerTest extends WebTestCase
|
||||
|
||||
// check that the person id is contained
|
||||
$participationsPersonsIds = \array_map(
|
||||
function($participation) { return $participation->person->person_id; },
|
||||
function($participation) { return $participation->person->id; },
|
||||
$data->participations);
|
||||
|
||||
$this->assertContains($personId, $participationsPersonsIds);
|
||||
@@ -239,7 +269,7 @@ class AccompanyingCourseApiControllerTest extends WebTestCase
|
||||
[], // parameters
|
||||
[], // files
|
||||
[], // server parameters
|
||||
\json_encode([ 'person_id' => $personId ])
|
||||
\json_encode([ 'type' => 'person', 'id' => $personId ])
|
||||
);
|
||||
$response = $this->client->getResponse();
|
||||
$data = \json_decode($response->getContent(), true);
|
||||
|
Reference in New Issue
Block a user