Merge remote-tracking branch 'origin/rector/rules-symfony' into rector/rules-symfony

This commit is contained in:
2023-10-16 18:07:42 +02:00
116 changed files with 3454 additions and 1032 deletions

View File

@@ -0,0 +1,61 @@
<?php
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\MainBundle\Tests\Doctrine\DQL;
use Chill\MainBundle\Entity\Address;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\AbstractQuery;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
/**
* @internal
* @coversNothing
*/
class JsonBuildObjectTest extends KernelTestCase
{
private EntityManagerInterface $entityManager;
protected function setUp(): void
{
parent::setUp();
self::bootKernel();
$this->entityManager = self::$container->get(EntityManagerInterface::class);
}
/**
* @dataProvider provideQueries
*/
public function testQuery(string $sql, array $params, array $paramType): void
{
$query = $this->entityManager->createQuery($sql);
foreach ($params as $k => $v) {
$query->setParameter($k, $v, $paramType[$k]);
}
$query->setMaxResults(1);
$result = $query->getResult(AbstractQuery::HYDRATE_ARRAY);
self::assertIsArray($result);
}
public function provideQueries(): iterable
{
yield ["SELECT JSON_BUILD_OBJECT(1, 2, 3, 4) FROM " . Address::class . " a", [], []];
yield ["SELECT JSON_BUILD_OBJECT('st', a.street, 'sn', a.streetNumber) FROM " . Address::class . ' a', [], []];
// next query make the test fails. But we do not need it for now.
//yield ["SELECT JSON_BUILD_OBJECT(a.street, :param), LOWER(:param) FROM " . Address::class . " a", ['param' => 1], ['param' => Types::INTEGER]];
}
}

View File

@@ -0,0 +1,71 @@
<?php
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 Entity;
use Chill\MainBundle\Entity\Scope;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Entity\UserJob;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
/**
* @internal
* @coversNothing
*/
class UserTest extends TestCase
{
use ProphecyTrait;
public function testMainScopeHistory()
{
$user = new User();
$scopeA = new Scope();
$scopeB = new Scope();
$user->setMainScope($scopeA);
$user->setMainScope($scopeB);
// 1. check getMainScope get now scopeB, not scopeA
self::assertSame($scopeB, $user->getMainScope());
// 2. get scopeA history, check endDate is not null
self::assertNotNull(
$user
->getMainScopeHistories()
->filter(fn (User\UserScopeHistory $userScopeHistory) => $userScopeHistory->getScope() === $scopeA)
->first()->getEndDate()
);
}
public function testUserJobHistory()
{
$user = new User();
$jobA = new UserJob();
$jobB = new UserJob();
$user->setUserJob($jobA);
$user->setUserJob($jobB);
// 1. check getUserJob get now jobB, not jobA
self::assertSame($jobB, $user->getUserJob());
// 2. get jobA history, check endDate is not null
self::assertNotNull(
$user
->getUserJobHistories()
->filter(fn (User\UserJobHistory $userJobHistory) => $userJobHistory->getJob() === $jobA)
->first()->getEndDate()
);
}
}