apply more cs rules for php-cs

This commit is contained in:
2023-10-17 13:27:03 +02:00
parent 0b0cbed9db
commit bc2041cbdd
1485 changed files with 8169 additions and 9620 deletions

View File

@@ -13,17 +13,14 @@ namespace Chill\ReportBundle\Tests\Controller;
use Chill\CustomFieldsBundle\Entity\CustomFieldsGroup;
use Chill\PersonBundle\Entity\Person;
use DateTime;
use RuntimeException;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\BrowserKit\Client;
use function in_array;
/**
* This class is much well writtend than ReportControllerTest class, and will
* replace ReportControllerTest in the future.
*
* @internal
*
* @coversNothing
*/
final class ReportControllerNextTest extends WebTestCase
@@ -55,9 +52,7 @@ final class ReportControllerNextTest extends WebTestCase
);
if (null === $this->person) {
throw new RuntimeException('The expected person is not present in the database. '
. 'Did you run `php app/console doctrine:fixture:load` before launching tests ? '
. "(expecting person is 'Charline Depardieu'");
throw new \RuntimeException('The expected person is not present in the database. Did you run `php app/console doctrine:fixture:load` before launching tests ? '."(expecting person is 'Charline Depardieu'");
}
// get custom fields group from fixture
@@ -65,10 +60,10 @@ final class ReportControllerNextTest extends WebTestCase
->get('doctrine.orm.entity_manager')
->getRepository(\Chill\CustomFieldsBundle\Entity\CustomFieldsGroup::class)
->findBy(['entity' => \Chill\ReportBundle\Entity\Report::class]);
//filter customFieldsGroup to get only "situation de logement"
// filter customFieldsGroup to get only "situation de logement"
$filteredCustomFieldsGroupHouse = array_filter(
$customFieldsGroups,
static fn (CustomFieldsGroup $group) => in_array('Situation de logement', $group->getName(), true)
static fn (CustomFieldsGroup $group) => \in_array('Situation de logement', $group->getName(), true)
);
$this->group = $filteredCustomFieldsGroupHouse[0];
}
@@ -85,7 +80,7 @@ final class ReportControllerNextTest extends WebTestCase
403,
$client->getResponse()->getStatusCode(),
'assert that user for center b has a 403 status code when listing'
. 'reports on person from center a'
.'reports on person from center a'
);
}
@@ -107,7 +102,7 @@ final class ReportControllerNextTest extends WebTestCase
403,
$client->getResponse()->getStatusCode(),
'assert that user for center b has a 403 status code when '
. 'trying to watch a report from person from center a'
.'trying to watch a report from person from center a'
);
}
@@ -124,7 +119,7 @@ final class ReportControllerNextTest extends WebTestCase
403,
$clientCenterB->getResponse()->getStatusCode(),
'assert that user is denied on trying to show a form "new" for'
. ' a person on another center'
.' a person on another center'
);
}
@@ -142,7 +137,7 @@ final class ReportControllerNextTest extends WebTestCase
403,
$client->getResponse()->getStatusCode(),
'assert that user is denied on trying to show a form "new" for'
. ' a person on another center'
.' a person on another center'
);
}
@@ -152,7 +147,7 @@ final class ReportControllerNextTest extends WebTestCase
$form = $this->getReportForm($this->person, $this->group, $client);
$form->get('chill_reportbundle_report[date]')->setValue(
(new DateTime())->format('d-m-Y')
(new \DateTime())->format('d-m-Y')
);
$client->submit($form);

View File

@@ -13,20 +13,17 @@ namespace Chill\ReportBundle\Tests\Controller;
use Chill\CustomFieldsBundle\Entity\CustomFieldsGroup;
use Chill\PersonBundle\Entity\Person;
use DateTime;
use RuntimeException;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\DomCrawler\Crawler;
use Symfony\Component\DomCrawler\Form;
use Symfony\Component\DomCrawler\Link;
use function count;
use function in_array;
/**
* Test the life cycles of controllers, according to
* https://redmine.champs-libres.coop/projects/report/wiki/Test_plan_for_report_lifecycle.
*
* @internal
*
* @coversNothing
*/
final class ReportControllerTest extends WebTestCase
@@ -59,7 +56,7 @@ final class ReportControllerTest extends WebTestCase
self::$em = self::$kernel->getContainer()
->get('doctrine.orm.entity_manager');
//get a random person
// get a random person
self::$person = self::$kernel->getContainer()
->get('doctrine.orm.entity_manager')
->getRepository(\Chill\PersonBundle\Entity\Person::class)
@@ -71,19 +68,17 @@ final class ReportControllerTest extends WebTestCase
);
if (null === self::$person) {
throw new RuntimeException('The expected person is not present in the database. '
. 'Did you run `php app/console doctrine:fixture:load` before launching tests ? '
. "(expecting person is 'Charline Depardieu'");
throw new \RuntimeException('The expected person is not present in the database. Did you run `php app/console doctrine:fixture:load` before launching tests ? '."(expecting person is 'Charline Depardieu'");
}
$customFieldsGroups = self::$kernel->getContainer()
->get('doctrine.orm.entity_manager')
->getRepository(\Chill\CustomFieldsBundle\Entity\CustomFieldsGroup::class)
->findBy(['entity' => \Chill\ReportBundle\Entity\Report::class]);
//filter customFieldsGroup to get only "situation de logement"
// filter customFieldsGroup to get only "situation de logement"
$filteredCustomFieldsGroupHouse = array_filter(
$customFieldsGroups,
static fn (CustomFieldsGroup $group) => in_array('Situation de logement', $group->getName(), true)
static fn (CustomFieldsGroup $group) => \in_array('Situation de logement', $group->getName(), true)
);
self::$group = $filteredCustomFieldsGroupHouse[0];
@@ -116,6 +111,7 @@ final class ReportControllerTest extends WebTestCase
/**
* @return type
*
* @depends testMenu
*/
public function testChooseReportModelPage(Link $link)
@@ -134,7 +130,7 @@ final class ReportControllerTest extends WebTestCase
$this->assertGreaterThan(
1,
count($form->get(self::REPORT_NAME_FIELD)
\count($form->get(self::REPORT_NAME_FIELD)
->availableOptionValues()),
'I can choose between report models'
);
@@ -161,7 +157,7 @@ final class ReportControllerTest extends WebTestCase
{
$client = $this->getAuthenticatedClient();
$this->markTestSkipped('This test raise an error since symfony 2.7. '
. 'The user is not correctly reloaded from database.');
.'The user is not correctly reloaded from database.');
$filledForm = $this->fillCorrectForm($form);
$filledForm->get('chill_reportbundle_report[date]')->setValue('invalid date value');
@@ -206,7 +202,7 @@ final class ReportControllerTest extends WebTestCase
$this->assertTrue($client->getResponse()->isSuccessful());
$linkSee = $crawler->filter('.bt-view')->links();
$this->assertGreaterThan(0, count($linkSee));
$this->assertGreaterThan(0, \count($linkSee));
$this->assertMatchesRegularExpression(sprintf(
'|/fr/person/%s/report/[0-9]*/view$|',
self::$person->getId(),
@@ -214,7 +210,7 @@ final class ReportControllerTest extends WebTestCase
), $linkSee[0]->getUri());
$linkUpdate = $crawler->filter('.bt-update')->links();
$this->assertGreaterThan(0, count($linkUpdate));
$this->assertGreaterThan(0, \count($linkUpdate));
$this->assertMatchesRegularExpression(sprintf(
'|/fr/person/%s/report/[0-9]*/edit$|',
self::$person->getId(),
@@ -241,7 +237,7 @@ final class ReportControllerTest extends WebTestCase
if (!$client->getResponse()->isSuccessful()) {
var_dump($crawlerPersonPage->html());
throw new RuntimeException('the request at person page failed');
throw new \RuntimeException('the request at person page failed');
}
$link = $crawlerPersonPage->selectLink("AJOUT D'UN RAPPORT")->link();
@@ -264,6 +260,7 @@ final class ReportControllerTest extends WebTestCase
/**
* @return type
*
* @depends testChooseReportModelPage
*/
public function testNewReportPage(Crawler $crawlerNewReportPage)
@@ -294,10 +291,10 @@ final class ReportControllerTest extends WebTestCase
self::$group,
$client
);
//var_dump($form);
// var_dump($form);
$filledForm = $this->fillCorrectForm($form);
$filledForm->get('chill_reportbundle_report[date]')->setValue('');
//$this->markTestSkipped();
// $this->markTestSkipped();
$crawler = $this->getAuthenticatedClient('center a_administrative')->submit($filledForm);
$this->assertFalse($client->getResponse()->isRedirect());
@@ -326,7 +323,7 @@ final class ReportControllerTest extends WebTestCase
->form();
$form->get('chill_reportbundle_report[date]')->setValue(
(new DateTime('yesterday'))->format('d-m-Y')
(new \DateTime('yesterday'))->format('d-m-Y')
);
$client->submit($form);
@@ -339,7 +336,7 @@ final class ReportControllerTest extends WebTestCase
)
));
$this->assertEquals(new DateTime('yesterday'), self::$kernel->getContainer()
$this->assertEquals(new \DateTime('yesterday'), self::$kernel->getContainer()
->get('doctrine.orm.entity_manager')
->getRepository('ChillReportBundle:Report')
->find($reportId)
@@ -355,7 +352,7 @@ final class ReportControllerTest extends WebTestCase
public function testValidCreate()
{
$client = $this->getAuthenticatedClient();
//$this->markTestSkipped("This test raise an error since symfony 2.7. "
// $this->markTestSkipped("This test raise an error since symfony 2.7. "
// . "The user is not correctly reloaded from database.");
$addForm = $this->getReportForm(self::$person, self::$group, $client);
$filledForm = $this->fillCorrectForm($addForm);
@@ -368,7 +365,7 @@ final class ReportControllerTest extends WebTestCase
$client->followRedirect();
$this->assertMatchesRegularExpression(
'|/fr/person/' . self::$person->getId() . '/report/[0-9]*/view$|',
'|/fr/person/'.self::$person->getId().'/report/[0-9]*/view$|',
$client->getHistory()->current()->getUri(),
"The next page is a redirection to the new report's view page"
);
@@ -433,7 +430,7 @@ final class ReportControllerTest extends WebTestCase
private function fillCorrectForm(Form $form)
{
$form->get('chill_reportbundle_report[date]')->setValue(
(new DateTime())->format('d-m-Y')
(new \DateTime())->format('d-m-Y')
);
return $form;
@@ -459,14 +456,14 @@ final class ReportControllerTest extends WebTestCase
->getType(), 'the user field is a select input');
if ($isDefault) {
$date = new DateTime('now');
$date = new \DateTime('now');
$this->assertEquals(
$date->format('d-m-Y'),
$form->get('chill_reportbundle_report[date]')->getValue(),
'the date field contains the current date by default'
);
//resolve the user
// resolve the user
$userId = $form->get('chill_reportbundle_report[user]')->getValue();
$this->assertEquals(

View File

@@ -11,11 +11,11 @@ declare(strict_types=1);
namespace Chill\ReportBundle\Tests\DependencyInjection;
use Exception;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
/**
* @internal
*
* @coversNothing
*/
final class ChillReportExtensionTest extends KernelTestCase
@@ -41,7 +41,7 @@ final class ChillReportExtensionTest extends KernelTestCase
}
if (!$reportFounded) {
throw new Exception('Class Chill\\ReportBundle\\Entity\\Report not found in chill_custom_fields.customizables_entities', 1);
throw new \Exception('Class Chill\\ReportBundle\\Entity\\Report not found in chill_custom_fields.customizables_entities', 1);
}
}
}

View File

@@ -15,11 +15,11 @@ use Chill\MainBundle\Service\RollingDate\RollingDate;
use Chill\MainBundle\Test\Export\AbstractFilterTest;
use Chill\ReportBundle\Entity\Report;
use Chill\ReportBundle\Export\Filter\ReportDateFilter;
use DateTime;
use Doctrine\ORM\EntityManagerInterface;
/**
* @internal
*
* @coversNothing
*/
final class ReportDateFilterTest extends AbstractFilterTest

View File

@@ -11,13 +11,13 @@ declare(strict_types=1);
namespace Chill\ReportBundle\Tests\Search;
use DateTime;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
/**
* Test for report search.
*
* @internal
*
* @coversNothing
*/
final class ReportSearchTest extends WebTestCase
@@ -27,7 +27,7 @@ final class ReportSearchTest extends WebTestCase
$client = $this->getAuthenticatedClient();
$crawler = $client->request('GET', '/fr/search', [
'q' => '@report ' . (new DateTime('tomorrow'))->format('Y-m-d'), //there should be any result for future. And future is tomorrow
'q' => '@report '.(new \DateTime('tomorrow'))->format('Y-m-d'), // there should be any result for future. And future is tomorrow
'name' => 'report',
]);

View File

@@ -23,6 +23,7 @@ use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
/**
* @internal
*
* @coversNothing
*/
final class ReportVoterTest extends KernelTestCase
@@ -123,7 +124,6 @@ final class ReportVoterTest extends KernelTestCase
* @dataProvider dataProvider
*
* @param type $expectedResult
* @param User $user
* @param type $action
* @param type $message
*/
@@ -132,7 +132,7 @@ final class ReportVoterTest extends KernelTestCase
Report $report,
$action,
$message,
?User $user = null
User $user = null
) {
$token = $this->prepareToken($user);
$result = $this->voter->vote($token, $report, [$action]);
@@ -157,15 +157,13 @@ final class ReportVoterTest extends KernelTestCase
*
* if $permissions = null, user will be null (no user associated with token
*
* @param User $user
*
* @return \Symfony\Component\Security\Core\Authentication\Token\TokenInterface
*/
protected function prepareToken(?User $user = null)
protected function prepareToken(User $user = null)
{
$token = $this->prophet->prophesize();
$token
->willImplement('\\' . \Symfony\Component\Security\Core\Authentication\Token\TokenInterface::class);
->willImplement('\\'.\Symfony\Component\Security\Core\Authentication\Token\TokenInterface::class);
if (null === $user) {
$token->getUser()->willReturn(null);

View File

@@ -15,14 +15,13 @@ use Chill\MainBundle\Entity\Scope;
use Chill\MainBundle\Tests\TestHelper as MainTestHelper;
use Chill\PersonBundle\Entity\Person;
use Chill\ReportBundle\Entity\Report;
use DateTime;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use function count;
/**
* Test a report is shown into timeline.
*
* @internal
*
* @coversNothing
*/
final class TimelineProviderTest extends WebTestCase
@@ -49,7 +48,7 @@ final class TimelineProviderTest extends WebTestCase
$center = self::$em->getRepository(\Chill\MainBundle\Entity\Center::class)
->findOneBy(['name' => 'Center A']);
$person = (new Person(new DateTime('2015-05-01')))
$person = (new Person(new \DateTime('2015-05-01')))
->setGender(Person::FEMALE_GENDER)
->setFirstName('Nelson')
->setLastName('Mandela')
@@ -61,13 +60,13 @@ final class TimelineProviderTest extends WebTestCase
self::$em
->getRepository(\Chill\MainBundle\Entity\Scope::class)
->findAll(),
static fn (Scope $scope) => $scope->getName()['en'] === 'social'
static fn (Scope $scope) => 'social' === $scope->getName()['en']
);
$report = (new Report())
->setUser(self::$em->getRepository(\Chill\MainBundle\Entity\User::class)
->findOneByUsername('center a_social'))
->setDate(new DateTime('2015-05-02'))
->setDate(new \DateTime('2015-05-02'))
->setPerson($this->person)
->setCFGroup($this->getHousingCustomFieldsGroup())
->setCFData(['has_logement' => 'own_house',
@@ -82,10 +81,10 @@ final class TimelineProviderTest extends WebTestCase
protected function tearDown(): void
{
//static::$em->refresh($this->person);
//static::$em->refresh($this->report);
// static::$em->refresh($this->person);
// static::$em->refresh($this->report);
// static::$em->remove($this->person);
//static::$em->remove($this->report);
// static::$em->remove($this->report);
}
public function testReportIsNotVisibleToUngrantedUsers()
@@ -95,8 +94,8 @@ final class TimelineProviderTest extends WebTestCase
MainTestHelper::getAuthenticatedClientOptions('center a_administrative')
);
$crawler = $client->request('GET', '/fr/person/' . $this->person->getId()
. '/timeline');
$crawler = $client->request('GET', '/fr/person/'.$this->person->getId()
.'/timeline');
$this->assertEquals(
0,
@@ -116,8 +115,8 @@ final class TimelineProviderTest extends WebTestCase
MainTestHelper::getAuthenticatedClientOptions()
);
$crawler = $client->request('GET', '/fr/person/' . $this->person->getId()
. '/timeline');
$crawler = $client->request('GET', '/fr/person/'.$this->person->getId()
.'/timeline');
$this->assertTrue(
$client->getResponse()->isSuccessful(),
@@ -132,16 +131,16 @@ final class TimelineProviderTest extends WebTestCase
public function testTimelineReportWithSummaryField()
{
//load the page
// load the page
$client = self::createClient(
[],
MainTestHelper::getAuthenticatedClientOptions()
);
$crawler = $client->request('GET', '/fr/person/' . $this->person->getId()
. '/timeline');
$crawler = $client->request('GET', '/fr/person/'.$this->person->getId()
.'/timeline');
//performs tests
// performs tests
$this->assertTrue(
$client->getResponse()->isSuccessful(),
'The page timeline is loaded successfully'
@@ -168,11 +167,11 @@ final class TimelineProviderTest extends WebTestCase
->findAll();
foreach ($groups as $group) {
if ($group->getName()['fr'] === 'Situation de logement') {
if ('Situation de logement' === $group->getName()['fr']) {
return $group;
}
}
return $groups[random_int(0, count($groups) - 1)];
return $groups[random_int(0, \count($groups) - 1)];
}
}