diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/ReferrerAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/ReferrerAggregator.php index de0dceec3..c2ccbed8a 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/ReferrerAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/ReferrerAggregator.php @@ -70,11 +70,19 @@ final readonly class ReferrerAggregator implements AggregatorInterface public function normalizeFormData(array $formData): array { + if (!array_key_exists('referrer_at', $formData)) { + return ['referrer_at' => (new RollingDate(RollingDate::T_TODAY))->normalize()]; + } + return ['referrer_at' => $formData['referrer_at']->normalize()]; } public function denormalizeFormData(array $formData, int $fromVersion): array { + if (!array_key_exists('referrer_at', $formData)) { + return ['referrer_at' => new RollingDate(RollingDate::T_TODAY)]; + } + return ['referrer_at' => RollingDate::fromNormalized($formData['referrer_at'])]; } diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Aggregator/SocialWorkAggregators/ReferrerAggregatorTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Aggregator/SocialWorkAggregators/ReferrerAggregatorTest.php index fd1f0ffc5..96ba94f62 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Aggregator/SocialWorkAggregators/ReferrerAggregatorTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Aggregator/SocialWorkAggregators/ReferrerAggregatorTest.php @@ -60,4 +60,29 @@ final class ReferrerAggregatorTest extends AbstractAggregatorTest ->from(AccompanyingPeriodWork::class, 'acpw'), ]; } + + /** + * A list of data to normalize. + * + * @return iterable{array} + */ + public static function dataProviderFormDataToNormalize(): iterable + { + foreach (self::getFormData() as $data) { + yield [$data, 1, []]; + } + } + + /** + * @dataProvider dataProviderFormDataToNormalize + */ + public function testDataNormalization(array $data, int $version, array $customAssert): void + { + $aggregator = $this->getAggregator(); + + $normalized = $aggregator->normalizeFormData($data); + $actual = $aggregator->denormalizeFormData($normalized, $version); + + self::assertIsArray($actual); + } }