cs: Switch to a stricter way of coding - this might break in a lot of places.

This commit is contained in:
Pol Dellaiera
2021-11-30 13:33:18 +01:00
parent 28d2c42454
commit 47c5855a21
957 changed files with 9025 additions and 568 deletions

View File

@@ -7,6 +7,15 @@
* the LICENSE file that was distributed with this source code.
*/
declare(strict_types=1);
/**
* 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.
*/
namespace Chill\ReportBundle\Tests\Controller;
use Chill\CustomFieldsBundle\Entity\CustomFieldsGroup;
@@ -24,7 +33,7 @@ use function in_array;
* @internal
* @coversNothing
*/
class ReportControllerNextTest extends WebTestCase
final class ReportControllerNextTest extends WebTestCase
{
/**
* @var CustomFieldsGroup
@@ -38,9 +47,9 @@ class ReportControllerNextTest extends WebTestCase
public function setUp()
{
static::bootKernel();
self::bootKernel();
// get person from fixture
$em = static::$kernel->getContainer()
$em = self::$kernel->getContainer()
->get('doctrine.orm.entity_manager');
$this->person = $em
@@ -59,7 +68,7 @@ class ReportControllerNextTest extends WebTestCase
}
// get custom fields group from fixture
$customFieldsGroups = static::$kernel->getContainer()
$customFieldsGroups = self::$kernel->getContainer()
->get('doctrine.orm.entity_manager')
->getRepository('ChillCustomFieldsBundle:CustomFieldsGroup')
->findBy(['entity' => 'Chill\ReportBundle\Entity\Report']);
@@ -67,7 +76,7 @@ class ReportControllerNextTest extends WebTestCase
$filteredCustomFieldsGroupHouse = array_filter(
$customFieldsGroups,
static function (CustomFieldsGroup $group) {
return in_array('Situation de logement', $group->getName());
return in_array('Situation de logement', $group->getName(), true);
}
);
$this->group = $filteredCustomFieldsGroupHouse[0];
@@ -92,7 +101,7 @@ class ReportControllerNextTest extends WebTestCase
public function testUngrantedUserIsDeniedAccessOnReport()
{
$client = $this->getAuthenticatedClient('center b_social');
$reports = static::$kernel->getContainer()->get('doctrine.orm.entity_manager')
$reports = self::$kernel->getContainer()->get('doctrine.orm.entity_manager')
->getRepository('ChillReportBundle:Report')
->findBy(['person' => $this->person]);
$report = $reports[0];
@@ -165,7 +174,7 @@ class ReportControllerNextTest extends WebTestCase
protected function getAuthenticatedClient($username = 'center a_social')
{
return static::createClient([], [
return self::createClient([], [
'PHP_AUTH_USER' => $username,
'PHP_AUTH_PW' => 'password',
]);

View File

@@ -7,6 +7,15 @@
* the LICENSE file that was distributed with this source code.
*/
declare(strict_types=1);
/**
* 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.
*/
namespace Chill\ReportBundle\Tests\Controller;
use Chill\CustomFieldsBundle\Entity\CustomFieldsGroup;
@@ -27,7 +36,7 @@ use function in_array;
* @internal
* @coversNothing
*/
class ReportControllerTest extends WebTestCase
final class ReportControllerTest extends WebTestCase
{
public const REPORT_NAME_FIELD = 'cFGroup';
@@ -55,13 +64,13 @@ class ReportControllerTest extends WebTestCase
public static function setUpBeforeClass()
{
static::bootKernel();
self::bootKernel();
static::$em = static::$kernel->getContainer()
self::$em = self::$kernel->getContainer()
->get('doctrine.orm.entity_manager');
//get a random person
static::$person = static::$kernel->getContainer()
self::$person = self::$kernel->getContainer()
->get('doctrine.orm.entity_manager')
->getRepository('ChillPersonBundle:Person')
->findOneBy(
@@ -71,13 +80,13 @@ class ReportControllerTest extends WebTestCase
]
);
if (null === static::$person) {
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'");
}
$customFieldsGroups = static::$kernel->getContainer()
$customFieldsGroups = self::$kernel->getContainer()
->get('doctrine.orm.entity_manager')
->getRepository('ChillCustomFieldsBundle:CustomFieldsGroup')
->findBy(['entity' => 'Chill\ReportBundle\Entity\Report']);
@@ -85,12 +94,12 @@ class ReportControllerTest extends WebTestCase
$filteredCustomFieldsGroupHouse = array_filter(
$customFieldsGroups,
static function (CustomFieldsGroup $group) {
return in_array('Situation de logement', $group->getName());
return in_array('Situation de logement', $group->getName(), true);
}
);
static::$group = $filteredCustomFieldsGroupHouse[0];
self::$group = $filteredCustomFieldsGroupHouse[0];
static::$user = static::$kernel->getContainer()
self::$user = self::$kernel->getContainer()
->get('doctrine.orm.entity_manager')
->getRepository('ChillMainBundle:User')
->findOneBy(['username' => 'center a_social']);
@@ -98,7 +107,7 @@ class ReportControllerTest extends WebTestCase
public function setUp()
{
static::$client = static::createClient([], [
self::$client = self::createClient([], [
'PHP_AUTH_USER' => 'center a_social',
'PHP_AUTH_PW' => 'password',
]);
@@ -111,7 +120,7 @@ class ReportControllerTest extends WebTestCase
*/
public function getAuthenticatedClient($username = 'center a_social')
{
return static::createClient([], [
return self::createClient([], [
'PHP_AUTH_USER' => $username,
'PHP_AUTH_PW' => 'password',
]);
@@ -203,7 +212,7 @@ class ReportControllerTest extends WebTestCase
$client = $this->getAuthenticatedClient();
$crawler = $client->request('GET', sprintf(
'/fr/person/%s/report/list',
static::$person->getId()
self::$person->getId()
));
$this->assertTrue($client->getResponse()->isSuccessful());
@@ -212,7 +221,7 @@ class ReportControllerTest extends WebTestCase
$this->assertGreaterThan(0, count($linkSee));
$this->assertRegExp(sprintf(
'|/fr/person/%s/report/[0-9]*/view$|',
static::$person->getId(),
self::$person->getId(),
$reportId
), $linkSee[0]->getUri());
@@ -220,7 +229,7 @@ class ReportControllerTest extends WebTestCase
$this->assertGreaterThan(0, count($linkUpdate));
$this->assertRegExp(sprintf(
'|/fr/person/%s/report/[0-9]*/edit$|',
static::$person->getId(),
self::$person->getId(),
$reportId
), $linkUpdate[0]->getUri());
}
@@ -238,7 +247,7 @@ class ReportControllerTest extends WebTestCase
$client = $this->getAuthenticatedClient();
$crawlerPersonPage = $client->request('GET', sprintf(
'/fr/person/%d/general',
static::$person->getId()
self::$person->getId()
));
if (!$client->getResponse()->isSuccessful()) {
@@ -256,7 +265,7 @@ class ReportControllerTest extends WebTestCase
$this->assertContains(
sprintf(
'/fr/person/%d/report/select/type/for/creation',
static::$person->getId()
self::$person->getId()
),
$link->getUri(),
'There is a "add a report" link in menu'
@@ -293,8 +302,8 @@ class ReportControllerTest extends WebTestCase
{
$client = $this->getAuthenticatedClient();
$form = $this->getReportForm(
static::$person,
static::$group,
self::$person,
self::$group,
$client
);
//var_dump($form);
@@ -319,7 +328,7 @@ class ReportControllerTest extends WebTestCase
$client = $this->getAuthenticatedClient();
$crawler = $client->request(
'GET',
sprintf('/fr/person/%s/report/%s/edit', static::$person->getId(), $reportId)
sprintf('/fr/person/%s/report/%s/edit', self::$person->getId(), $reportId)
);
$this->assertTrue($client->getResponse()->isSuccessful());
@@ -337,12 +346,12 @@ class ReportControllerTest extends WebTestCase
$this->assertTrue($client->getResponse()->isRedirect(
sprintf(
'/fr/person/%s/report/%s/view',
static::$person->getId(),
self::$person->getId(),
$reportId
)
));
$this->assertEquals(new DateTime('yesterday'), static::$kernel->getContainer()
$this->assertEquals(new DateTime('yesterday'), self::$kernel->getContainer()
->get('doctrine.orm.entity_manager')
->getRepository('ChillReportBundle:Report')
->find($reportId)
@@ -371,7 +380,7 @@ class ReportControllerTest extends WebTestCase
$client->followRedirect();
$this->assertRegExp(
'|/fr/person/' . static::$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"
);
@@ -398,7 +407,7 @@ class ReportControllerTest extends WebTestCase
$client = $this->getAuthenticatedClient();
$client->request(
'GET',
sprintf('/fr/person/%s/report/%s/view', static::$person->getId(), $reportId)
sprintf('/fr/person/%s/report/%s/view', self::$person->getId(), $reportId)
);
$this->assertTrue(
@@ -474,7 +483,7 @@ class ReportControllerTest extends WebTestCase
$this->assertEquals(
'center a_social',
static::$user->getUsername(),
self::$user->getUsername(),
'the user field is the current user by default'
);
}