diff --git a/src/Bundle/ChillPersonBundle/Tests/Controller/AccompanyingCourseApiControllerTest.php b/src/Bundle/ChillPersonBundle/Tests/Controller/AccompanyingCourseApiControllerTest.php index a41e570a5..3f427e811 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Controller/AccompanyingCourseApiControllerTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Controller/AccompanyingCourseApiControllerTest.php @@ -2,8 +2,8 @@ /* * Chill is a software for social workers - * - * Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS, + * + * Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS, * , * * This program is free software: you can redistribute it and/or modify @@ -54,7 +54,7 @@ class AccompanyingCourseApiControllerTest extends WebTestCase { static::bootKernel(); } - + /** * Setup before each test method (see phpunit doc) */ @@ -76,11 +76,11 @@ class AccompanyingCourseApiControllerTest extends WebTestCase $response = $this->client->getResponse(); $this->assertEquals(200, $response->getStatusCode(), "Test that the response of rest api has a status code ok (200)"); - + $data = \json_decode($response->getContent()); $this->assertEquals($data->id, $period->getId(), "test that the response's data contains the id of the period" - ); + ); $this->assertGreaterThan(0, $data->participations); } @@ -106,7 +106,7 @@ class AccompanyingCourseApiControllerTest extends WebTestCase [], \json_encode([ 'type' => 'social_issue', 'id' => $si->getId() ]) ); - + $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); $data = \json_decode($this->client->getResponse()->getContent(), true); @@ -204,7 +204,7 @@ class AccompanyingCourseApiControllerTest extends WebTestCase $response = $this->client->getResponse(); $this->assertEquals(200, $response->getStatusCode()); - // post a third party + // post a third party $this->client->request( Request::METHOD_POST, sprintf('/api/1.0/person/accompanying-course/%d/resource.json', $period->getId()), @@ -269,7 +269,7 @@ class AccompanyingCourseApiControllerTest extends WebTestCase $this->assertInstanceOf(Person::class, $period->getRequestor()); $this->assertEquals($personId, $period->getRequestor()->getId()); - // post a third party + // post a third party $this->client->request( Request::METHOD_POST, sprintf('/api/1.0/person/accompanying-course/%d/requestor.json', $period->getId()), @@ -332,7 +332,7 @@ class AccompanyingCourseApiControllerTest extends WebTestCase $em = self::$container->get(EntityManagerInterface::class); $this->client->request( - Request::METHOD_PATCH, + Request::METHOD_PATCH, sprintf('/api/1.0/person/accompanying-course/%d.json', $period->getId()), [], // parameters [], // files @@ -368,7 +368,7 @@ class AccompanyingCourseApiControllerTest extends WebTestCase ->setParameter('center', $center) ->setMaxResults($maxResults) ->getScalarResult(); - + // create a random order shuffle($personIds); @@ -376,7 +376,7 @@ class AccompanyingCourseApiControllerTest extends WebTestCase ThirdParty::class." t ") ->setMaxResults($maxResults) ->getScalarResult(); - + // create a random order shuffle($thirdPartyIds); @@ -421,7 +421,7 @@ class AccompanyingCourseApiControllerTest extends WebTestCase // check by deownloading the accompanying cours $this->client->request(Request::METHOD_GET, sprintf('/api/1.0/person/accompanying-course/%d.json', $period->getId())); - + $response = $this->client->getResponse(); $data = \json_decode($response->getContent()); @@ -491,9 +491,9 @@ class AccompanyingCourseApiControllerTest extends WebTestCase public function dataGenerateRandomAccompanyingCourseWithSocialIssue() { // note about max result for person query, and maxGenerated: - // + // // in the final loop, an id is popped out of the personIds array twice: - // + // // * one for getting the person, which will in turn provide his accompanying period; // * one for getting the personId to populate to the data manager // @@ -512,7 +512,7 @@ class AccompanyingCourseApiControllerTest extends WebTestCase ->setParameter('center', $center) ->setMaxResults($maxResults) ->getScalarResult(); - + // create a random order shuffle($personIds); @@ -538,9 +538,9 @@ class AccompanyingCourseApiControllerTest extends WebTestCase public function dataGenerateRandomAccompanyingCourse() { // note about max result for person query, and maxGenerated: - // + // // in the final loop, an id is popped out of the personIds array twice: - // + // // * one for getting the person, which will in turn provide his accompanying period; // * one for getting the personId to populate to the data manager // @@ -553,13 +553,26 @@ class AccompanyingCourseApiControllerTest extends WebTestCase $center = $em->getRepository(Center::class) ->findOneBy(array('name' => 'Center A')); - $personIds = $em->createQuery("SELECT p.id FROM ". - Person::class." p ". - " WHERE p.center = :center") + $qb = $em->createQueryBuilder(); + $personIds = $qb + ->select('p.id') + ->from(Person::class, 'p') + ->where( + $qb->expr()->eq( + 'p.center', + ':center' + ) + ) + ->andWhere( + $qb->expr()->gt( + 'SIZE(p.accompanyingPeriodParticipations)', + 0) + ) ->setParameter('center', $center) ->setMaxResults($maxResults) + ->getQuery() ->getScalarResult(); - + // create a random order shuffle($personIds); @@ -597,7 +610,7 @@ class AccompanyingCourseApiControllerTest extends WebTestCase ->setParameter('center', $center) ->setMaxResults(100) ->getScalarResult(); - + // create a random order shuffle($personIds);