cs: Fix code style (safe rules only).

This commit is contained in:
Pol Dellaiera
2021-11-23 14:06:38 +01:00
parent 149d7ce991
commit 8f96a1121d
1223 changed files with 65199 additions and 64625 deletions

View File

@@ -1,17 +1,31 @@
<?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.
*/
declare(strict_types=1);
namespace Chill\PersonBundle\Tests\Controller;
use Chill\MainBundle\Test\PrepareClientTrait;
use Chill\PersonBundle\DataFixtures\Helper\PersonRandomHelper;
use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Entity\Relationships\Relation;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Component\HttpFoundation\Request;
use Chill\PersonBundle\Repository\PersonRepository;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\HttpFoundation\Request;
use function array_rand;
use function json_encode;
use function random_int;
/**
* @internal
* @coversNothing
*/
class RelationshipApiControllerTest extends WebTestCase
{
use PrepareClientTrait;
@@ -19,8 +33,9 @@ class RelationshipApiControllerTest extends WebTestCase
private KernelBrowser $client;
/**
* A cache for all relations
* @var array|null|Relation[]
* A cache for all relations.
*
* @var array|Relation[]|null
*/
private ?array $relations = null;
@@ -30,80 +45,6 @@ class RelationshipApiControllerTest extends WebTestCase
$this->client = $this->getClientAuthenticated();
}
/**
* @dataProvider personProvider
*/
public function testGetRelationshipByPerson($personId)
{
$this->client->request(Request::METHOD_GET, sprintf('/api/1.0/relations/relationship/by-person/%d.json', $personId));
$response = $this->client->getResponse();
$this->assertEquals(200, $response->getStatusCode(), 'Test to see that API response returns a status code 200');
}
/**
* @dataProvider relationProvider
*/
public function testPostRelationship($fromPersonId, $toPersonId, $relationId, $isReverse): void
{
$this->client->request(Request::METHOD_POST,
'/api/1.0/relations/relationship.json',
[],
[],
[],
\json_encode([
'type' => 'relationship',
'fromPerson' => ['id' => $fromPersonId, 'type' => 'person'],
'toPerson' => ['id' => $toPersonId, 'type' => 'person'],
'relation' => ['id' => $relationId, 'type' => 'relation'],
'reverse' => $isReverse
]));
$response = $this->client->getResponse();
$this->assertEquals(200, $response->getStatusCode());
}
public function relationProvider(): array
{
static::bootKernel();
$em = self::$container->get(EntityManagerInterface::class);
$countPersons = $em->createQueryBuilder()
->select('count(p)')
->from(Person::class, 'p')
->join('p.center', 'c')
->where('c.name LIKE :name')
->setParameter('name', 'Center A')
->getQuery()
->getSingleScalarResult()
;
$persons = $em->createQueryBuilder()
->select('p')
->from(Person::class, 'p')
->join('p.center', 'c')
->where('c.name LIKE :name')
->setParameter('name', 'Center A')
->getQuery()
->setMaxResults(2)
->setFirstResult(\random_int(0, $countPersons - 1))
->getResult()
;
return [
[$persons[0]->getId(), $persons[1]->getId(), $this->getRandomRelation($em)->getId(), true],
];
}
private function getRandomRelation(EntityManagerInterface $em): Relation
{
if (null === $this->relations) {
$this->relations = $em->getRepository(Relation::class)
->findAll();
}
return $this->relations[\array_rand($this->relations)];
}
public function personProvider(): array
{
static::bootKernel();
@@ -115,8 +56,7 @@ class RelationshipApiControllerTest extends WebTestCase
->where('c.name LIKE :name')
->setParameter('name', 'Center A')
->getQuery()
->getSingleScalarResult()
;
->getSingleScalarResult();
$person = $em->createQueryBuilder()
->select('p')
->from(Person::class, 'p')
@@ -125,12 +65,91 @@ class RelationshipApiControllerTest extends WebTestCase
->setParameter('name', 'Center A')
->getQuery()
->setMaxResults(1)
->setFirstResult(\random_int(0, $countPersons - 1))
->getSingleResult()
;
->setFirstResult(random_int(0, $countPersons - 1))
->getSingleResult();
return [
[$person->getId()],
];
}
public function relationProvider(): array
{
static::bootKernel();
$em = self::$container->get(EntityManagerInterface::class);
$countPersons = $em->createQueryBuilder()
->select('count(p)')
->from(Person::class, 'p')
->join('p.center', 'c')
->where('c.name LIKE :name')
->setParameter('name', 'Center A')
->getQuery()
->getSingleScalarResult();
$persons = $em->createQueryBuilder()
->select('p')
->from(Person::class, 'p')
->join('p.center', 'c')
->where('c.name LIKE :name')
->setParameter('name', 'Center A')
->getQuery()
->setMaxResults(2)
->setFirstResult(random_int(0, $countPersons - 1))
->getResult();
return [
[$persons[0]->getId(), $persons[1]->getId(), $this->getRandomRelation($em)->getId(), true],
];
}
/**
* @dataProvider personProvider
*
* @param mixed $personId
*/
public function testGetRelationshipByPerson($personId)
{
$this->client->request(Request::METHOD_GET, sprintf('/api/1.0/relations/relationship/by-person/%d.json', $personId));
$response = $this->client->getResponse();
$this->assertEquals(200, $response->getStatusCode(), 'Test to see that API response returns a status code 200');
}
/**
* @dataProvider relationProvider
*
* @param mixed $fromPersonId
* @param mixed $toPersonId
* @param mixed $relationId
* @param mixed $isReverse
*/
public function testPostRelationship($fromPersonId, $toPersonId, $relationId, $isReverse): void
{
$this->client->request(
Request::METHOD_POST,
'/api/1.0/relations/relationship.json',
[],
[],
[],
json_encode([
'type' => 'relationship',
'fromPerson' => ['id' => $fromPersonId, 'type' => 'person'],
'toPerson' => ['id' => $toPersonId, 'type' => 'person'],
'relation' => ['id' => $relationId, 'type' => 'relation'],
'reverse' => $isReverse,
])
);
$response = $this->client->getResponse();
$this->assertEquals(200, $response->getStatusCode());
}
private function getRandomRelation(EntityManagerInterface $em): Relation
{
if (null === $this->relations) {
$this->relations = $em->getRepository(Relation::class)
->findAll();
}
return $this->relations[array_rand($this->relations)];
}
}