Resolve merge with master

This commit is contained in:
2024-12-11 10:46:06 +01:00
667 changed files with 37245 additions and 7119 deletions

View File

@@ -14,6 +14,7 @@ namespace Chill\ThirdPartyBundle\DataFixtures\ORM;
use Chill\MainBundle\DataFixtures\ORM\LoadCenters;
use Chill\MainBundle\DataFixtures\ORM\LoadPostalCodes;
use Chill\MainBundle\Entity\Address;
use Chill\MainBundle\Entity\Center;
use Chill\MainBundle\Entity\PostalCode;
use Chill\ThirdPartyBundle\Entity\ThirdParty;
use Doctrine\Bundle\FixturesBundle\Fixture;
@@ -32,7 +33,7 @@ class LoadThirdParty extends Fixture implements DependentFixtureInterface
$this->phoneNumberUtil = PhoneNumberUtil::getInstance();
}
public function getDependencies()
public function getDependencies(): array
{
return [
LoadCenters::class,
@@ -40,7 +41,7 @@ class LoadThirdParty extends Fixture implements DependentFixtureInterface
];
}
public function load(ObjectManager $manager)
public function load(ObjectManager $manager): void
{
$thirdParties = $this->getThirdParties()->getObjects();
@@ -70,10 +71,10 @@ class LoadThirdParty extends Fixture implements DependentFixtureInterface
$number = random_int(1, \count($references));
if (1 === $number) {
yield $this->getReference($references[array_rand($references)]);
yield $this->getReference($references[array_rand($references)], Center::class);
} else {
foreach (array_rand($references, $number) as $index) {
yield $this->getReference($references[$index]);
yield $this->getReference($references[$index], Center::class);
}
}
}
@@ -82,7 +83,7 @@ class LoadThirdParty extends Fixture implements DependentFixtureInterface
{
$ref = LoadPostalCodes::$refs[array_rand(LoadPostalCodes::$refs)];
return $this->getReference($ref);
return $this->getReference($ref, PostalCode::class);
}
private function getThirdParties(): ObjectSet

View File

@@ -26,7 +26,7 @@ class LoadThirdPartyCategory extends Fixture implements FixtureGroupInterface
return ['thirdparty_categories'];
}
public function load(ObjectManager $manager)
public function load(ObjectManager $manager): void
{
$categories = [
['name' => ['fr' => 'maison médicale']],

View File

@@ -26,7 +26,7 @@ class LoadThirdPartyProfession extends Fixture implements FixtureGroupInterface
return ['thirdparty_professions'];
}
public function load(ObjectManager $manager)
public function load(ObjectManager $manager): void
{
$professions = [
['name' => ['fr' => 'Directeur']],

View File

@@ -200,7 +200,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface, \Strin
* [fr] Qualité.
*/
#[Groups(['read', 'write', 'docgen:read', 'docgen:read:3party:parent'])]
#[ORM\Column(name: 'profession', type: \Doctrine\DBAL\Types\Types::TEXT, nullable: false)]
#[ORM\Column(name: 'profession', type: \Doctrine\DBAL\Types\Types::TEXT, nullable: false, options: ['default' => ''])]
#[Context(normalizationContext: ['groups' => 'docgen:read'], groups: ['docgen:read:3party:parent'])]
private string $profession = '';

View File

@@ -0,0 +1,63 @@
<?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 ChillThirdParty\Tests\Validator;
use Chill\ThirdPartyBundle\Entity\ThirdParty;
use Chill\ThirdPartyBundle\Templating\Entity\ThirdPartyRender;
use Chill\ThirdPartyBundle\Validator\ThirdPartyHasEmail;
use Chill\ThirdPartyBundle\Validator\ThirdPartyHasEmailValidator;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
/**
* @internal
*
* @coversNothing
*/
class ThirdPartyHasEmailValidatorTest extends \Symfony\Component\Validator\Test\ConstraintValidatorTestCase
{
use ProphecyTrait;
public function testThirdPartyWithEmail(): void
{
$thirdParty = new ThirdParty();
$thirdParty->setEmail('third@example.com');
$this->validator->validate($thirdParty, new ThirdPartyHasEmail());
$this->assertNoViolation();
}
public function testThirdPartyHasNoEmail(): void
{
$thirdParty = new ThirdParty();
$constraint = new ThirdPartyHasEmail();
$constraint->message = 'message';
$this->validator->validate($thirdParty, $constraint);
$this->buildViolation($constraint->message)
->setParameter('{{ thirdParty }}', '3party-string')
->setCode($constraint->code)
->assertRaised();
}
protected function createValidator(): ThirdPartyHasEmailValidator
{
$render = $this->prophesize(ThirdPartyRender::class);
$render->renderString(Argument::type(ThirdParty::class), [])
->willReturn('3party-string');
return new ThirdPartyHasEmailValidator($render->reveal());
}
}

View File

@@ -0,0 +1,31 @@
<?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\ThirdPartyBundle\Validator;
use Symfony\Component\Validator\Constraint;
/**
* Add a constraint to check that the thirdparty has an email address.
*/
class ThirdPartyHasEmail extends Constraint
{
public string $message = 'thirdParty.thirdParty_has_no_email';
public string $code = 'f2da71f8-818c-11ef-9f6a-3ba3597ab60b';
/**
* @return array<string>|string
*/
public function getTargets(): array|string
{
return [self::PROPERTY_CONSTRAINT];
}
}

View File

@@ -0,0 +1,45 @@
<?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\ThirdPartyBundle\Validator;
use Chill\ThirdPartyBundle\Entity\ThirdParty;
use Chill\ThirdPartyBundle\Templating\Entity\ThirdPartyRender;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
final class ThirdPartyHasEmailValidator extends ConstraintValidator
{
public function __construct(private readonly ThirdPartyRender $thirdPartyRender) {}
public function validate($value, Constraint $constraint): void
{
if (!$constraint instanceof ThirdPartyHasEmail) {
throw new UnexpectedTypeException($constraint, ThirdPartyHasEmail::class);
}
if (null === $value) {
return;
}
if (!$value instanceof ThirdParty) {
throw new UnexpectedTypeException($value, ThirdParty::class);
}
if (null === $value->getEmail() || '' === $value->getEmail()) {
$this->context->buildViolation($constraint->message)
->setParameter('{{ thirdParty }}', $this->thirdPartyRender->renderString($value, []))
->setCode($constraint->code)
->addViolation();
}
}
}

View File

@@ -11,3 +11,8 @@ services:
autoconfigure: true
resource: '../Export/'
Chill\ThirdPartyBundle\Validator\:
autoconfigure: true
autowire: true
resource: '../Validator/'

View File

@@ -0,0 +1,31 @@
<?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\Migrations\ThirdParty;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20240918152229 extends AbstractMigration
{
public function getDescription(): string
{
return 'Drop foreign key profession_id and set not null on firstname';
}
public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE chill_3party.third_party DROP profession_id');
$this->addSql('ALTER TABLE chill_3party.third_party ALTER firstname SET NOT NULL');
}
public function down(Schema $schema): void {}
}

View File

@@ -0,0 +1,2 @@
thirdParty:
thirdParty_has_no_email: Le tiers {{ thirdParty }} n'a pas d'adresse email configurée.