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,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(