Skip to content

Commit

Permalink
cchanges based on cocmments #3582
Browse files Browse the repository at this point in the history
  • Loading branch information
hmeneuvrier committed Jan 28, 2025
1 parent 6428b3f commit 095db40
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 34 deletions.
4 changes: 2 additions & 2 deletions migrations/Version20250122140631.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public function getDescription(): string

public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE auto_affectation_rule CHANGE insee_to_include insee_to_include VARCHAR(255) DEFAULT NULL COMMENT \'Value possible null or an array of code insee\'');
$this->addSql("UPDATE auto_affectation_rule SET insee_to_include = null WHERE insee_to_include IN ('all','partner_list')");
$this->addSql('ALTER TABLE auto_affectation_rule CHANGE insee_to_include insee_to_include VARCHAR(255) NOT NULL COMMENT \'Value possible empty or an array of code insee\'');
$this->addSql("UPDATE auto_affectation_rule SET insee_to_include = '' WHERE insee_to_include IN ('all','partner_list')");
}

public function down(Schema $schema): void
Expand Down
18 changes: 9 additions & 9 deletions src/DataFixtures/Files/AutoAffectationRule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ auto_affectation_rules:
status: "ACTIVE"
profile_declarant: "all"
partner_type: "COMMUNE_SCHS"
insee_to_include: null
insee_to_include: ''
insee_to_exclude: null
parc: "all"
allocataire: "all"
Expand All @@ -13,7 +13,7 @@ auto_affectation_rules:
status: "ACTIVE"
profile_declarant: "all"
partner_type: "COMMUNE_SCHS"
insee_to_include: null
insee_to_include: ''
insee_to_exclude: null
parc: "prive"
allocataire: "all"
Expand All @@ -22,7 +22,7 @@ auto_affectation_rules:
status: "ACTIVE"
profile_declarant: "all"
partner_type: "CAF_MSA"
insee_to_include: null
insee_to_include: ''
insee_to_exclude: null
parc: "prive"
allocataire: "caf"
Expand All @@ -40,7 +40,7 @@ auto_affectation_rules:
status: "ACTIVE"
profile_declarant: "LOCATAIRE"
partner_type: "EPCI"
insee_to_include: null
insee_to_include: ''
insee_to_exclude:
- "34048"
parc: "prive"
Expand All @@ -50,7 +50,7 @@ auto_affectation_rules:
status: "ARCHIVED"
profile_declarant: "all"
partner_type: "EPCI"
insee_to_include: null
insee_to_include: ''
insee_to_exclude: null
parc: "all"
allocataire: "all"
Expand All @@ -59,7 +59,7 @@ auto_affectation_rules:
status: "ACTIVE"
profile_declarant: "all"
partner_type: "POLICE_GENDARMERIE"
insee_to_include: null
insee_to_include: ''
insee_to_exclude: null
parc: "all"
allocataire: "all"
Expand All @@ -70,7 +70,7 @@ auto_affectation_rules:
status: "ACTIVE"
profile_declarant: "all"
partner_type: "COMMUNE_SCHS"
insee_to_include: null
insee_to_include: ''
insee_to_exclude: null
parc: "all"
allocataire: "all"
Expand All @@ -79,7 +79,7 @@ auto_affectation_rules:
status: "ARCHIVED"
profile_declarant: "all"
partner_type: "EPCI"
insee_to_include: null
insee_to_include: ''
insee_to_exclude: null
parc: "all"
allocataire: "all"
Expand All @@ -88,7 +88,7 @@ auto_affectation_rules:
status: "ACTIVE"
profile_declarant: "all"
partner_type: "BAILLEUR_SOCIAL"
insee_to_include: null
insee_to_include: ''
insee_to_exclude: null
parc: "public"
allocataire: "all"
Expand Down
9 changes: 5 additions & 4 deletions src/Entity/AutoAffectationRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ enumType: PartnerType::class,
#[AppAssert\ValidProfileDeclarant()]
private string $profileDeclarant;

#[ORM\Column(nullable: true, length: 255, options: ['comment' => 'Value possible null or an array of code insee'])]
#[ORM\Column(length: 255, options: ['comment' => 'Value possible empty or an array of code insee'])]
#[Assert\Length(max: 255)]
#[AppAssert\InseeToInclude()]
private ?string $inseeToInclude;
private string $inseeToInclude;

#[ORM\Column(nullable: true, options: ['comment' => 'Value possible null or an array of code insee'])]
#[AppAssert\InseeToExclude()]
Expand Down Expand Up @@ -143,12 +143,12 @@ public function setProfileDeclarant(string $profileDeclarant): self
return $this;
}

public function getInseeToInclude(): ?string
public function getInseeToInclude(): string
{
return $this->inseeToInclude;
}

public function setInseeToInclude(?string $inseeToInclude): self
public function setInseeToInclude(string $inseeToInclude): self
{
$this->inseeToInclude = $inseeToInclude;

Expand Down Expand Up @@ -292,6 +292,7 @@ public function getDescription(bool $isShort = true): string
$description .= ' Elle s\'applique ';
switch ($this->getInseeToInclude()) {
case null:
case '':
$description .= 'aux logements situés dans le périmètre géographique du partenaire (codes insee et/ou zones)';
break;
default:
Expand Down
6 changes: 3 additions & 3 deletions src/Specification/Affectation/CodeInseeSpecification.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

class CodeInseeSpecification implements SpecificationInterface
{
public function __construct(private string|array|null $inseeToInclude, private ?array $inseeToExclude)
public function __construct(private string|array $inseeToInclude, private ?array $inseeToExclude)
{
if (null !== $inseeToInclude) {
if ('' !== $inseeToInclude) {
$this->inseeToInclude = explode(',', $inseeToInclude);
} else {
$this->inseeToInclude = $inseeToInclude;
Expand Down Expand Up @@ -40,7 +40,7 @@ public function isSatisfiedBy(SpecificationContextInterface $context): bool
}

return match ($this->inseeToInclude) {
null => true,
'' => true,
default => $this->isInseeIncluded($signalement->getInseeOccupant()),
};
}
Expand Down
10 changes: 9 additions & 1 deletion src/Validator/InseeToIncludeValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ public function validate($value, Constraint $constraint): void
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\InseeToInclude');
}
/* @var InseeToInclude $constraint */
if (null === $value || '' === $value) {
if ('' === $value) {
return;
}

if (null === $value) {
$this->context->buildViolation($constraint->message)
->setParameter('{{ value }}', 'null')
->addViolation();

return;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/FixturesHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ public function getAutoAffectationRule(
->setProfileDeclarant('all')
->setParc('prive')
->setAllocataire('oui')
->setInseeToInclude(null)
->setInseeToInclude('')
->setInseeToExclude(null)
->setPartnerToExclude([])
->setStatus(AutoAffectationRule::STATUS_ACTIVE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function testAutoAffectationRuleFormSubmit(): void
'auto_affectation_rule[profileDeclarant]' => 'occupant',
'auto_affectation_rule[parc]' => 'all',
'auto_affectation_rule[allocataire]' => 'oui',
'auto_affectation_rule[inseeToInclude]' => null,
'auto_affectation_rule[inseeToInclude]' => '',
'auto_affectation_rule[inseeToExclude]' => '',
'auto_affectation_rule[partnerToExclude]' => '',
]
Expand All @@ -77,7 +77,7 @@ public function testAutoAffectationRuleEditFormSubmit(): void
'auto_affectation_rule[profileDeclarant]' => 'occupant',
'auto_affectation_rule[parc]' => 'all',
'auto_affectation_rule[allocataire]' => 'oui',
'auto_affectation_rule[inseeToInclude]' => null,
'auto_affectation_rule[inseeToInclude]' => '',
'auto_affectation_rule[inseeToExclude]' => '',
'auto_affectation_rule[partnerToExclude]' => '',
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ public function testIsSatisfiedBy(

public function provideRulesAndSignalement(): \Generator
{
yield 'null - same insee as partner - no exclude' => [self::INSEE_STMARS, [self::INSEE_STMARS], null, null, true];
yield 'null - same insee as partner - but excluded' => [self::INSEE_STMARS, [self::INSEE_STMARS], null, [self::INSEE_STMARS], false];
yield 'null - same insee as partner - another excluded' => [self::INSEE_STMARS, [self::INSEE_STMARS], null, [self::INSEE_CELLIER], true];
yield 'null - different insee than partner - no exclude' => [self::INSEE_STMARS, [self::INSEE_CELLIER], null, null, true];
yield 'null - different insee than partner - but excluded' => [self::INSEE_STMARS, [self::INSEE_CELLIER], null, [self::INSEE_STMARS], false];
yield 'null - different insee than partner - another excluded' => [self::INSEE_STMARS, [self::INSEE_CELLIER], null, [self::INSEE_CELLIER], true];
yield 'null - partner without insee - no exclude' => [self::INSEE_STMARS, [], null, null, true];
yield 'null - partner without insee - but excluded' => [self::INSEE_STMARS, [], null, [self::INSEE_STMARS], false];
yield 'null - partner without insee - another excluded' => [self::INSEE_STMARS, [], null, [self::INSEE_CELLIER], true];
yield 'empty - same insee as partner - no exclude' => [self::INSEE_STMARS, [self::INSEE_STMARS], '', null, true];
yield 'empty - same insee as partner - but excluded' => [self::INSEE_STMARS, [self::INSEE_STMARS], '', [self::INSEE_STMARS], false];
yield 'empty - same insee as partner - another excluded' => [self::INSEE_STMARS, [self::INSEE_STMARS], '', [self::INSEE_CELLIER], true];
yield 'empty - different insee than partner - no exclude' => [self::INSEE_STMARS, [self::INSEE_CELLIER], '', null, true];
yield 'empty - different insee than partner - but excluded' => [self::INSEE_STMARS, [self::INSEE_CELLIER], '', [self::INSEE_STMARS], false];
yield 'empty - different insee than partner - another excluded' => [self::INSEE_STMARS, [self::INSEE_CELLIER], '', [self::INSEE_CELLIER], true];
yield 'empty - partner without insee - no exclude' => [self::INSEE_STMARS, [], '', null, true];
yield 'empty - partner without insee - but excluded' => [self::INSEE_STMARS, [], '', [self::INSEE_STMARS], false];
yield 'empty - partner without insee - another excluded' => [self::INSEE_STMARS, [], '', [self::INSEE_CELLIER], true];

yield 'array of insee with this one - same insee as partner - no exclusion' => [self::INSEE_STMARS, [self::INSEE_STMARS], self::INSEE_STMARS, null, true];
yield 'array of insee with this one - same insee as partner - but excluded' => [self::INSEE_STMARS, [self::INSEE_STMARS], self::INSEE_STMARS, [self::INSEE_STMARS], false];
Expand All @@ -73,7 +73,7 @@ public function provideRulesAndSignalement(): \Generator
yield 'array of insee without this one - partner without insee - another excluded' => [self::INSEE_STMARS, [], self::INSEE_CELLIER, [self::INSEE_CELLIER], false];

// tous les cas ne sont pas testés en cas d'absence d'insee sur le signalement, car ça renvoie toujours false
yield 'null - no insee signalement' => [null, [self::INSEE_CELLIER], null, [self::INSEE_CELLIER], false];
yield 'empty - no insee signalement' => [null, [self::INSEE_CELLIER], '', [self::INSEE_CELLIER], false];
yield 'array of insee - no insee signalement - another excluded' => [null, [], self::INSEE_STMARS, [self::INSEE_CELLIER], false];
}
}
2 changes: 1 addition & 1 deletion tests/Unit/Entity/AutoAffectationRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function testDescriptionLong(): void
$this->assertEquals('prive', $autoAffectationRule->getParc());
$this->assertEquals('all', $autoAffectationRule->getProfileDeclarant());
$this->assertEquals('oui', $autoAffectationRule->getAllocataire());
$this->assertNull($autoAffectationRule->getInseeToInclude());
$this->assertEmpty($autoAffectationRule->getInseeToInclude());
$this->assertNull($autoAffectationRule->getInseeToExclude());
$this->assertEmpty($autoAffectationRule->getPartnerToExclude());
$this->assertEquals(AutoAffectationRule::STATUS_ACTIVE, $autoAffectationRule->getStatus());
Expand Down
6 changes: 5 additions & 1 deletion tests/Unit/Validator/InseeToIncludeValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public function testValues(?string $insee, bool $isValid, ?string $message = nul
if ($isValid) {
$this->assertNoViolation();
} else {
if (null === $insee) {
$insee = 'null';
}
$this->buildViolation($message)
->setParameter('{{ value }}', $insee)
->assertRaised();
Expand All @@ -34,7 +37,8 @@ public function testValues(?string $insee, bool $isValid, ?string $message = nul

public function provideValues(): \Generator
{
yield 'null' => [null, true];
yield 'null' => [null, false, self::ERROR];
yield 'empty' => ['', true];
yield 'all' => ['all', false, self::ERROR];
yield 'partner_list' => ['partner_list', false, self::ERROR];
yield '44058' => ['44058', true];
Expand Down

0 comments on commit 095db40

Please sign in to comment.