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

@@ -18,6 +18,7 @@ use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
/**
* @internal
*
* @coversNothing
*/
class FetchQueryToSqlBuilderTest extends KernelTestCase
@@ -35,21 +36,21 @@ class FetchQueryToSqlBuilderTest extends KernelTestCase
$query->addJoinClause('LEFT JOIN other d ON a.id = d.foreign_id', ['bar_baz'], [Types::STRING]);
$query->removeJoinClause($index);
$query->addWhereClause('b.item = ?', ['baz'], [Types::STRING]);
$index = $query->addWhereClause('b.cancel', [ 'foz'], [Types::STRING]);
$index = $query->addWhereClause('b.cancel', ['foz'], [Types::STRING]);
$query->removeWhereClause($index);
['sql' => $sql, 'params' => $params, 'types' => $types] = (new FetchQueryToSqlBuilder())->toSql($query);
$filteredSql =
implode(" ", array_filter(
explode(" ", str_replace("\n", "", $sql)),
fn (string $tok) => $tok !== ""
implode(' ', array_filter(
explode(' ', str_replace("\n", '', $sql)),
fn (string $tok) => '' !== $tok
))
;
self::assertEquals(
"SELECT 'test' AS key, jsonb_build_object('id', a.column) AS identifiers, ".
"a.datecolumn::date AS doc_date FROM my_table a LEFT JOIN other b ON a.id = b.foreign_id LEFT JOIN other d ON a.id = d.foreign_id WHERE b.item = ?",
'a.datecolumn::date AS doc_date FROM my_table a LEFT JOIN other b ON a.id = b.foreign_id LEFT JOIN other d ON a.id = d.foreign_id WHERE b.item = ?',
$filteredSql
);
self::assertEquals(['foo', 'bar_baz', 'baz'], $params);
@@ -68,15 +69,15 @@ class FetchQueryToSqlBuilderTest extends KernelTestCase
['sql' => $sql, 'params' => $params, 'types' => $types] = (new FetchQueryToSqlBuilder())->toSql($query);
$filteredSql =
implode(" ", array_filter(
explode(" ", str_replace("\n", "", $sql)),
fn (string $tok) => $tok !== ""
implode(' ', array_filter(
explode(' ', str_replace("\n", '', $sql)),
fn (string $tok) => '' !== $tok
))
;
self::assertEquals(
"SELECT 'test' AS key, jsonb_build_object('id', a.column) AS identifiers, ".
"a.datecolumn::date AS doc_date FROM my_table a",
'a.datecolumn::date AS doc_date FROM my_table a',
$filteredSql
);
self::assertEquals([], $params);

View File

@@ -19,7 +19,6 @@ use Chill\DocStoreBundle\GenericDoc\Manager;
use Chill\DocStoreBundle\GenericDoc\GenericDocForAccompanyingPeriodProviderInterface;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Entity\Person;
use DateTimeImmutable;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\EntityManagerInterface;
@@ -28,6 +27,7 @@ use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
/**
* @internal
*
* @coversNothing
*/
class ManagerTest extends KernelTestCase
@@ -52,7 +52,7 @@ class ManagerTest extends KernelTestCase
->getSingleResult();
if (null === $period) {
throw new \UnexpectedValueException("period not found");
throw new \UnexpectedValueException('period not found');
}
$manager = new Manager(
@@ -73,7 +73,7 @@ class ManagerTest extends KernelTestCase
->getSingleResult();
if (null === $person) {
throw new \UnexpectedValueException("person found");
throw new \UnexpectedValueException('person found');
}
$manager = new Manager(
@@ -94,7 +94,7 @@ class ManagerTest extends KernelTestCase
->getSingleResult();
if (null === $period) {
throw new \UnexpectedValueException("period not found");
throw new \UnexpectedValueException('period not found');
}
$manager = new Manager(
@@ -115,7 +115,7 @@ class ManagerTest extends KernelTestCase
->getSingleResult();
if (null === $person) {
throw new \UnexpectedValueException("person not found");
throw new \UnexpectedValueException('person not found');
}
$manager = new Manager(
@@ -136,7 +136,7 @@ class ManagerTest extends KernelTestCase
->getSingleResult();
if (null === $person) {
throw new \UnexpectedValueException("person not found");
throw new \UnexpectedValueException('person not found');
}
$manager = new Manager(
@@ -157,7 +157,7 @@ class ManagerTest extends KernelTestCase
->getSingleResult();
if (null === $period) {
throw new \UnexpectedValueException("period not found");
throw new \UnexpectedValueException('period not found');
}
$manager = new Manager(
@@ -174,7 +174,7 @@ class ManagerTest extends KernelTestCase
final readonly class SimpleGenericDocAccompanyingPeriodProvider implements GenericDocForAccompanyingPeriodProviderInterface
{
public function buildFetchQueryForAccompanyingPeriod(AccompanyingPeriod $accompanyingPeriod, ?\DateTimeImmutable $startDate = null, ?\DateTimeImmutable $endDate = null, ?string $content = null, ?string $origin = null): FetchQueryInterface
public function buildFetchQueryForAccompanyingPeriod(AccompanyingPeriod $accompanyingPeriod, \DateTimeImmutable $startDate = null, \DateTimeImmutable $endDate = null, string $content = null, string $origin = null): FetchQueryInterface
{
$query = new FetchQuery(
'accompanying_course_document_dummy',
@@ -196,7 +196,7 @@ final readonly class SimpleGenericDocAccompanyingPeriodProvider implements Gener
final readonly class SimpleGenericDocPersonProvider implements GenericDocForPersonProviderInterface
{
public function buildFetchQueryForPerson(Person $person, ?DateTimeImmutable $startDate = null, ?DateTimeImmutable $endDate = null, ?string $content = null, ?string $origin = null): FetchQueryInterface
public function buildFetchQueryForPerson(Person $person, \DateTimeImmutable $startDate = null, \DateTimeImmutable $endDate = null, string $content = null, string $origin = null): FetchQueryInterface
{
$query = new FetchQuery(
'dummy_person_doc',

View File

@@ -15,7 +15,6 @@ use Chill\DocStoreBundle\GenericDoc\FetchQueryToSqlBuilder;
use Chill\DocStoreBundle\GenericDoc\Providers\AccompanyingCourseDocumentGenericDocProvider;
use Chill\DocStoreBundle\Security\Authorization\AccompanyingCourseDocumentVoter;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\EntityManagerInterface;
use Prophecy\PhpUnit\ProphecyTrait;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
@@ -23,6 +22,7 @@ use Symfony\Component\Security\Core\Security;
/**
* @internal
*
* @coversNothing
*/
class AccompanyingCourseDocumentGenericDocProviderTest extends KernelTestCase
@@ -40,14 +40,14 @@ class AccompanyingCourseDocumentGenericDocProviderTest extends KernelTestCase
/**
* @dataProvider provideSearchArguments
*/
public function testWithoutAnyArgument(?\DateTimeImmutable $startDate, ?\DateTimeImmutable $endDate, ?string $content = null): void
public function testWithoutAnyArgument(?\DateTimeImmutable $startDate, ?\DateTimeImmutable $endDate, string $content = null): void
{
$period = $this->entityManager->createQuery('SELECT a FROM '.AccompanyingPeriod::class.' a')
->setMaxResults(1)
->getSingleResult();
if (null === $period) {
throw new \UnexpectedValueException("period not found");
throw new \UnexpectedValueException('period not found');
}
$security = $this->prophesize(Security::class);

View File

@@ -15,7 +15,6 @@ use Chill\DocStoreBundle\GenericDoc\FetchQueryToSqlBuilder;
use Chill\DocStoreBundle\GenericDoc\Providers\PersonDocumentGenericDocProvider;
use Chill\DocStoreBundle\Repository\PersonDocumentACLAwareRepositoryInterface;
use Chill\PersonBundle\Entity\Person;
use DateTimeImmutable;
use Doctrine\ORM\EntityManagerInterface;
use Prophecy\PhpUnit\ProphecyTrait;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
@@ -23,6 +22,7 @@ use Symfony\Component\Security\Core\Security;
/**
* @internal
*
* @coversNothing
*/
class PersonDocumentGenericDocProviderTest extends KernelTestCase
@@ -42,11 +42,12 @@ class PersonDocumentGenericDocProviderTest extends KernelTestCase
/**
* @dataProvider provideDataBuildFetchQueryForPerson
*
* @throws \Doctrine\DBAL\Exception
* @throws \Doctrine\ORM\NoResultException
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public function testBuildFetchQueryForPerson(?DateTimeImmutable $startDate, ?DateTimeImmutable $endDate, ?string $content): void
public function testBuildFetchQueryForPerson(?\DateTimeImmutable $startDate, ?\DateTimeImmutable $endDate, ?string $content): void
{
$security = $this->prophesize(Security::class);
$person = $this->entityManager->createQuery('SELECT a FROM '.Person::class.' a')
@@ -54,7 +55,7 @@ class PersonDocumentGenericDocProviderTest extends KernelTestCase
->getSingleResult();
if (null === $person) {
throw new \UnexpectedValueException("person found");
throw new \UnexpectedValueException('person found');
}
$provider = new PersonDocumentGenericDocProvider(
@@ -69,16 +70,16 @@ class PersonDocumentGenericDocProviderTest extends KernelTestCase
$nb = $this->entityManager->getConnection()
->fetchOne("SELECT COUNT(*) AS nb FROM ({$sql}) AS sq", $params, $types);
self::assertIsInt($nb, "Test that the query is syntactically correct");
self::assertIsInt($nb, 'Test that the query is syntactically correct');
}
public function provideDataBuildFetchQueryForPerson(): iterable
{
yield [null, null, null];
yield [new DateTimeImmutable('1 year ago'), null, null];
yield [null, new DateTimeImmutable('1 year ago'), null];
yield [new DateTimeImmutable('2 years ago'), new DateTimeImmutable('1 year ago'), null];
yield [new \DateTimeImmutable('1 year ago'), null, null];
yield [null, new \DateTimeImmutable('1 year ago'), null];
yield [new \DateTimeImmutable('2 years ago'), new \DateTimeImmutable('1 year ago'), null];
yield [null, null, 'test'];
yield [new DateTimeImmutable('2 years ago'), new DateTimeImmutable('1 year ago'), 'test'];
yield [new \DateTimeImmutable('2 years ago'), new \DateTimeImmutable('1 year ago'), 'test'];
}
}

View File

@@ -17,13 +17,9 @@ use Chill\DocStoreBundle\Security\Authorization\PersonDocumentVoter;
use Chill\MainBundle\Entity\Center;
use Chill\MainBundle\Repository\ScopeRepositoryInterface;
use Chill\MainBundle\Security\Authorization\AuthorizationHelperForCurrentUserInterface;
use Chill\MainBundle\Security\Authorization\AuthorizationHelperInterface;
use Chill\MainBundle\Security\Resolver\CenterResolverDispatcher;
use Chill\MainBundle\Security\Resolver\CenterResolverDispatcherInterface;
use Chill\MainBundle\Security\Resolver\CenterResolverManagerInterface;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Entity\Person;
use DateTimeImmutable;
use Doctrine\ORM\EntityManagerInterface;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
@@ -32,6 +28,7 @@ use Symfony\Component\Security\Core\Security;
/**
* @internal
*
* @coversNothing
*/
class PersonDocumentACLAwareRepositoryTest extends KernelTestCase
@@ -51,11 +48,12 @@ class PersonDocumentACLAwareRepositoryTest extends KernelTestCase
/**
* @dataProvider provideDataBuildFetchQueryForPerson
*
* @throws \Doctrine\DBAL\Exception
* @throws \Doctrine\ORM\NoResultException
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public function testBuildFetchQueryForPerson(?DateTimeImmutable $startDate = null, ?DateTimeImmutable $endDate = null, ?string $content = null): void
public function testBuildFetchQueryForPerson(\DateTimeImmutable $startDate = null, \DateTimeImmutable $endDate = null, string $content = null): void
{
$centerManager = $this->prophesize(CenterResolverManagerInterface::class);
$centerManager->resolveCenters(Argument::type(Person::class))
@@ -72,12 +70,12 @@ class PersonDocumentACLAwareRepositoryTest extends KernelTestCase
$this->prophesize(Security::class)->reveal()
);
$person = $this->entityManager->createQuery("SELECT p FROM " . Person::class . " p")
$person = $this->entityManager->createQuery('SELECT p FROM '.Person::class.' p')
->setMaxResults(1)
->getSingleResult();
if (null === $person) {
throw new \RuntimeException("person not exists in database");
throw new \RuntimeException('person not exists in database');
}
$query = $repository->buildFetchQueryForPerson($person, $startDate, $endDate, $content);
@@ -86,7 +84,7 @@ class PersonDocumentACLAwareRepositoryTest extends KernelTestCase
$nb = $this->entityManager->getConnection()
->fetchOne("SELECT COUNT(*) FROM ({$sql}) AS sq", $params, $types);
self::assertIsInt($nb, "test that the query could be executed");
self::assertIsInt($nb, 'test that the query could be executed');
}
/**
@@ -94,9 +92,9 @@ class PersonDocumentACLAwareRepositoryTest extends KernelTestCase
*/
public function testBuildFetchQueryForAccompanyingPeriod(
AccompanyingPeriod $period,
?\DateTimeImmutable $startDate = null,
?\DateTimeImmutable $endDate = null,
?string $content = null
\DateTimeImmutable $startDate = null,
\DateTimeImmutable $endDate = null,
string $content = null
): void {
$centerManager = $this->prophesize(CenterResolverManagerInterface::class);
$centerManager->resolveCenters(Argument::type(Person::class))
@@ -122,7 +120,7 @@ class PersonDocumentACLAwareRepositoryTest extends KernelTestCase
$nb = $this->entityManager->getConnection()
->fetchOne("SELECT COUNT(*) FROM ({$sql}) AS sq", $params, $types);
self::assertIsInt($nb, "test that the query could be executed");
self::assertIsInt($nb, 'test that the query could be executed');
}
public function provideDateForFetchQueryForAccompanyingPeriod(): iterable
@@ -130,27 +128,27 @@ class PersonDocumentACLAwareRepositoryTest extends KernelTestCase
$this->setUp();
if (null === $period = $this->entityManager->createQuery(
"SELECT p FROM " . AccompanyingPeriod::class . " p WHERE SIZE(p.participations) > 0"
'SELECT p FROM '.AccompanyingPeriod::class.' p WHERE SIZE(p.participations) > 0'
)
->setMaxResults(1)->getSingleResult()) {
throw new \RuntimeException("no course found");
throw new \RuntimeException('no course found');
}
yield [$period, null, null, null];
yield [$period, new DateTimeImmutable('1 year ago'), null, null];
yield [$period, null, new DateTimeImmutable('1 year ago'), null];
yield [$period, new DateTimeImmutable('2 years ago'), new DateTimeImmutable('1 year ago'), null];
yield [$period, new \DateTimeImmutable('1 year ago'), null, null];
yield [$period, null, new \DateTimeImmutable('1 year ago'), null];
yield [$period, new \DateTimeImmutable('2 years ago'), new \DateTimeImmutable('1 year ago'), null];
yield [$period, null, null, 'test'];
yield [$period, new DateTimeImmutable('2 years ago'), new DateTimeImmutable('1 year ago'), 'test'];
yield [$period, new \DateTimeImmutable('2 years ago'), new \DateTimeImmutable('1 year ago'), 'test'];
}
public function provideDataBuildFetchQueryForPerson(): iterable
{
yield [null, null, null];
yield [new DateTimeImmutable('1 year ago'), null, null];
yield [null, new DateTimeImmutable('1 year ago'), null];
yield [new DateTimeImmutable('2 years ago'), new DateTimeImmutable('1 year ago'), null];
yield [new \DateTimeImmutable('1 year ago'), null, null];
yield [null, new \DateTimeImmutable('1 year ago'), null];
yield [new \DateTimeImmutable('2 years ago'), new \DateTimeImmutable('1 year ago'), null];
yield [null, null, 'test'];
yield [new DateTimeImmutable('2 years ago'), new DateTimeImmutable('1 year ago'), 'test'];
yield [new \DateTimeImmutable('2 years ago'), new \DateTimeImmutable('1 year ago'), 'test'];
}
}

View File

@@ -16,9 +16,7 @@ use Chill\DocStoreBundle\Entity\StoredObject;
use Chill\DocStoreBundle\Exception\StoredObjectManagerException;
use Chill\DocStoreBundle\Service\StoredObjectManager;
use Chill\DocStoreBundle\Service\StoredObjectManagerInterface;
use Generator;
use PHPUnit\Framework\TestCase;
use stdClass;
use Symfony\Component\HttpClient\Exception\TransportException;
use Symfony\Component\HttpClient\MockHttpClient;
use Symfony\Component\HttpClient\Response\MockResponse;
@@ -32,7 +30,7 @@ use Symfony\Contracts\HttpClient\HttpClientInterface;
*/
final class StoredObjectManagerTest extends TestCase
{
public function getDataProvider(): Generator
public function getDataProvider(): \Generator
{
/* HAPPY SCENARIO */
@@ -92,7 +90,7 @@ final class StoredObjectManagerTest extends TestCase
/**
* @dataProvider getDataProvider
*/
public function testRead(StoredObject $storedObject, string $encodedContent, string $clearContent, ?string $exceptionClass = null)
public function testRead(StoredObject $storedObject, string $encodedContent, string $clearContent, string $exceptionClass = null)
{
if (null !== $exceptionClass) {
$this->expectException($exceptionClass);
@@ -106,7 +104,7 @@ final class StoredObjectManagerTest extends TestCase
/**
* @dataProvider getDataProvider
*/
public function testWrite(StoredObject $storedObject, string $encodedContent, string $clearContent, ?string $exceptionClass = null)
public function testWrite(StoredObject $storedObject, string $encodedContent, string $clearContent, string $exceptionClass = null)
{
if (null !== $exceptionClass) {
$this->expectException($exceptionClass);
@@ -144,7 +142,6 @@ final class StoredObjectManagerTest extends TestCase
case 'https://example.com/error_during_http_request.txt':
throw new TransportException('error_during_http_request.txt');
case 'https://example.com/invalid_statuscode.txt':
return new MockResponse($encodedContent, ['http_code' => 404]);
}
@@ -166,7 +163,7 @@ final class StoredObjectManagerTest extends TestCase
private function getTempUrlGenerator(StoredObject $storedObject): TempUrlGeneratorInterface
{
$response = new stdClass();
$response = new \stdClass();
$response->url = $storedObject->getFilename();
$tempUrlGenerator = $this->createMock(TempUrlGeneratorInterface::class);