From a850ce2558b4b1f2dc2473ab17d08d40cffbe2e5 Mon Sep 17 00:00:00 2001 From: Luc Wollants Date: Mon, 18 Nov 2024 13:23:15 +0100 Subject: [PATCH 01/10] Added `TranslatedTariffName` normalizer and denormalizer --- .../Price/TranslatedTariffNameNormalizer.php | 16 +++++++++++ .../TranslatedValueObjectNormalizer.php | 27 +++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 src/Model/Serializer/ValueObject/Price/TranslatedTariffNameNormalizer.php create mode 100644 src/Model/Serializer/ValueObject/Translation/TranslatedValueObjectNormalizer.php diff --git a/src/Model/Serializer/ValueObject/Price/TranslatedTariffNameNormalizer.php b/src/Model/Serializer/ValueObject/Price/TranslatedTariffNameNormalizer.php new file mode 100644 index 0000000000..9888a19204 --- /dev/null +++ b/src/Model/Serializer/ValueObject/Price/TranslatedTariffNameNormalizer.php @@ -0,0 +1,16 @@ +getLanguages() as $language) { + $data[$language->toString()] = $object->getTranslation($language)->toString(); + } + + return $data; + } +} From df94b9cd6a38090875c5e1e15a47c79bb31f5b0d Mon Sep 17 00:00:00 2001 From: Luc Wollants Date: Mon, 18 Nov 2024 13:23:43 +0100 Subject: [PATCH 02/10] Refactor `Tariff` to use `TranslatedTariffName` instead of `MultilingualString` --- src/Cdb/CdbXmlPriceInfoParser.php | 7 +++--- .../JSONLD/CdbXMLItemBaseImporter.php | 3 ++- .../ReadModel/JSONLD/OfferLDProjector.php | 7 ++++-- src/PriceInfo/Tariff.php | 22 +++++++++++++------ 4 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/Cdb/CdbXmlPriceInfoParser.php b/src/Cdb/CdbXmlPriceInfoParser.php index 350f509a0f..f02fdb367d 100644 --- a/src/Cdb/CdbXmlPriceInfoParser.php +++ b/src/Cdb/CdbXmlPriceInfoParser.php @@ -6,12 +6,13 @@ use CultureFeed_Cdb_Data_Detail; use CultureFeed_Cdb_Data_Price; +use CultuurNet\UDB3\Model\ValueObject\Price\TariffName; +use CultuurNet\UDB3\Model\ValueObject\Price\TranslatedTariffName; use CultuurNet\UDB3\Model\ValueObject\Translation\Language; use CultuurNet\UDB3\MoneyFactory; use CultuurNet\UDB3\PriceInfo\BasePrice; use CultuurNet\UDB3\PriceInfo\PriceInfo; use CultuurNet\UDB3\PriceInfo\Tariff; -use CultuurNet\UDB3\ValueObject\MultilingualString; use Money\Currency; final class CdbXmlPriceInfoParser @@ -100,13 +101,13 @@ function (\CultureFeed_Cdb_Data_Detail $detail) use ($mainLanguage) { foreach ($translatedTariffs as $tariffName => $tariffPrice) { if (!isset($tariffs[$tariffIndex])) { $tariff = new Tariff( - new MultilingualString(new Language($language), (string) $tariffName), + new TranslatedTariffName(new Language($language), new TariffName((string) $tariffName)), MoneyFactory::create($tariffPrice, new Currency('EUR')) ); } else { $tariff = $tariffs[$tariffIndex]; $name = $tariff->getName(); - $name = $name->withTranslation(new Language($language), (string) $tariffName); + $name = $name->withTranslation(new Language($language), new TariffName($tariffName)); $tariff = new Tariff( $name, $tariff->getPrice() diff --git a/src/Offer/ReadModel/JSONLD/CdbXMLItemBaseImporter.php b/src/Offer/ReadModel/JSONLD/CdbXMLItemBaseImporter.php index 600a22dcd6..2cf24d7dc1 100644 --- a/src/Offer/ReadModel/JSONLD/CdbXMLItemBaseImporter.php +++ b/src/Offer/ReadModel/JSONLD/CdbXMLItemBaseImporter.php @@ -7,6 +7,7 @@ use CultureFeed_Cdb_Item_Base; use CultuurNet\UDB3\Cdb\CdbXmlPriceInfoParser; use CultuurNet\UDB3\DateTimeFactory; +use CultuurNet\UDB3\Model\Serializer\ValueObject\Price\TranslatedTariffNameNormalizer; use CultuurNet\UDB3\Model\ValueObject\Moderation\WorkflowStatus; use CultuurNet\UDB3\ReadModel\MultilingualJsonLDProjectorTrait; @@ -140,7 +141,7 @@ public function importPriceInfo( foreach ($priceInfo->getTariffs() as $tariff) { $jsonLD->priceInfo[] = [ 'category' => 'tariff', - 'name' => $tariff->getName()->serialize(), + 'name' => (new TranslatedTariffNameNormalizer())->normalize($tariff->getName()), 'price' => $tariff->getPrice()->getAmount() / 100, 'priceCurrency' => $tariff->getCurrency()->getName(), ]; diff --git a/src/Offer/ReadModel/JSONLD/OfferLDProjector.php b/src/Offer/ReadModel/JSONLD/OfferLDProjector.php index c23579c866..409f88fdd0 100644 --- a/src/Offer/ReadModel/JSONLD/OfferLDProjector.php +++ b/src/Offer/ReadModel/JSONLD/OfferLDProjector.php @@ -18,6 +18,7 @@ use CultuurNet\UDB3\Media\Serialization\MediaObjectSerializer; use CultuurNet\UDB3\Model\Serializer\ValueObject\Contact\ContactPointNormalizer; use CultuurNet\UDB3\Model\Serializer\ValueObject\MediaObject\VideoNormalizer; +use CultuurNet\UDB3\Model\Serializer\ValueObject\Price\TranslatedTariffNameNormalizer; use CultuurNet\UDB3\Model\ValueObject\Identity\UUID; use CultuurNet\UDB3\Model\ValueObject\Moderation\WorkflowStatus; use CultuurNet\UDB3\Offer\AvailableTo; @@ -668,10 +669,12 @@ protected function applyPriceInfoUpdated(AbstractPriceInfoUpdated $priceInfoUpda 'priceCurrency' => $basePrice->getCurrency()->getName(), ]; + $translatedTariffNameNormalizer = new TranslatedTariffNameNormalizer(); + foreach ($priceInfoUpdated->getPriceInfo()->getTariffs() as $tariff) { $offerLd->priceInfo[] = [ 'category' => 'tariff', - 'name' => $tariff->getName()->serialize(), + 'name' => $translatedTariffNameNormalizer->normalize($tariff->getName()), 'price' => $tariff->getPrice()->getAmount() / 100, 'priceCurrency' => $tariff->getCurrency()->getName(), ]; @@ -680,7 +683,7 @@ protected function applyPriceInfoUpdated(AbstractPriceInfoUpdated $priceInfoUpda foreach ($priceInfoUpdated->getPriceInfo()->getUiTPASTariffs() as $tariff) { $offerLd->priceInfo[] = [ 'category' => 'uitpas', - 'name' => $tariff->getName()->serialize(), + 'name' => $translatedTariffNameNormalizer->normalize($tariff->getName()), 'price' => $tariff->getPrice()->getAmount() / 100, 'priceCurrency' => $tariff->getCurrency()->getName(), ]; diff --git a/src/PriceInfo/Tariff.php b/src/PriceInfo/Tariff.php index 3bf2dab771..c542fc6e92 100644 --- a/src/PriceInfo/Tariff.php +++ b/src/PriceInfo/Tariff.php @@ -5,9 +5,11 @@ namespace CultuurNet\UDB3\PriceInfo; use Broadway\Serializer\Serializable; +use CultuurNet\UDB3\Model\Serializer\ValueObject\Price\TranslatedTariffNameDenormalizer; +use CultuurNet\UDB3\Model\Serializer\ValueObject\Price\TranslatedTariffNameNormalizer; use CultuurNet\UDB3\Model\ValueObject\Price\Tariff as Udb3ModelTariff; +use CultuurNet\UDB3\Model\ValueObject\Price\TranslatedTariffName; use CultuurNet\UDB3\MoneyFactory; -use CultuurNet\UDB3\ValueObject\MultilingualString; use Money\Currency; use Money\Money; @@ -17,19 +19,19 @@ */ class Tariff implements Serializable { - private MultilingualString $name; + private TranslatedTariffName $name; private Money $money; public function __construct( - MultilingualString $name, + TranslatedTariffName $name, Money $money ) { $this->name = $name; $this->money = $money; } - public function getName(): MultilingualString + public function getName(): TranslatedTariffName { return $this->name; } @@ -47,7 +49,7 @@ public function getCurrency(): Currency public function serialize(): array { return [ - 'name' => $this->name->serialize(), + 'name' => (new TranslatedTariffNameNormalizer())->normalize($this->getName()), 'price' => $this->getPrice()->getAmount(), 'currency' => $this->getCurrency()->getName(), ]; @@ -55,8 +57,14 @@ public function serialize(): array public static function deserialize(array $data): Tariff { + /** @var TranslatedTariffName $tariffName */ + $tariffName = (new TranslatedTariffNameDenormalizer())->denormalize( + $data['name'], + TranslatedTariffName::class + ); + return new Tariff( - MultilingualString::deserialize($data['name']), + $tariffName, MoneyFactory::createFromCents($data['price'], new Currency($data['currency'])) ); } @@ -64,7 +72,7 @@ public static function deserialize(array $data): Tariff public static function fromUdb3ModelTariff(Udb3ModelTariff $udb3ModelTariff): Tariff { return new Tariff( - MultilingualString::fromUdb3ModelTranslatedValueObject($udb3ModelTariff->getName()), + $udb3ModelTariff->getName(), $udb3ModelTariff->getPrice() ); } From ee0c2f0df1ce6bd5edd01208b65931bd5483f732 Mon Sep 17 00:00:00 2001 From: Luc Wollants Date: Mon, 18 Nov 2024 13:23:50 +0100 Subject: [PATCH 03/10] Fix tests --- ...CompatiblePayloadSerializerFactoryTest.php | 10 +- tests/Event/EventTest.php | 91 ++++++++++--------- .../Udb3ModelToLegacyOfferAdapterTest.php | 5 +- .../ReadModel/JSONLD/OfferLDProjectorTest.php | 10 +- tests/PriceInfo/PriceInfoTest.php | 15 ++- 5 files changed, 68 insertions(+), 63 deletions(-) diff --git a/tests/BackwardsCompatiblePayloadSerializerFactoryTest.php b/tests/BackwardsCompatiblePayloadSerializerFactoryTest.php index 43de2fe3b9..f7340f0470 100644 --- a/tests/BackwardsCompatiblePayloadSerializerFactoryTest.php +++ b/tests/BackwardsCompatiblePayloadSerializerFactoryTest.php @@ -26,6 +26,8 @@ use CultuurNet\UDB3\Model\ValueObject\Contact\TelephoneNumbers; use CultuurNet\UDB3\Model\ValueObject\Identity\UUID; use CultuurNet\UDB3\Model\ValueObject\Text\Description; +use CultuurNet\UDB3\Model\ValueObject\Price\TariffName; +use CultuurNet\UDB3\Model\ValueObject\Price\TranslatedTariffName; use CultuurNet\UDB3\Model\ValueObject\Web\EmailAddress; use CultuurNet\UDB3\Model\ValueObject\Web\EmailAddresses; use CultuurNet\UDB3\Model\ValueObject\Web\Url; @@ -627,18 +629,18 @@ public function it_should_replace_string_names_with_translatable_objects_in_pric $expectedPriceInfo = $expectedPriceInfo ->withExtraTariff( new Tariff( - new MultilingualString( + new TranslatedTariffName( new Language('nl'), - 'Senioren' + new TariffName('Senioren') ), new Money(1000, new Currency('EUR')) ) ) ->withExtraTariff( new Tariff( - new MultilingualString( + new TranslatedTariffName( new Language('nl'), - 'Studenten' + new TariffName('Studenten') ), new Money(750, new Currency('EUR')) ) diff --git a/tests/Event/EventTest.php b/tests/Event/EventTest.php index f51f44949e..f44bd6cd46 100644 --- a/tests/Event/EventTest.php +++ b/tests/Event/EventTest.php @@ -61,6 +61,7 @@ use CultuurNet\UDB3\Offer\AgeRange; use CultuurNet\UDB3\PriceInfo\BasePrice; use CultuurNet\UDB3\PriceInfo\PriceInfo; +use CultuurNet\UDB3\PriceInfo\Tariff as LegacyTariff; use CultuurNet\UDB3\SampleFiles; use CultuurNet\UDB3\Theme; use CultuurNet\UDB3\Model\ValueObject\Text\Title; @@ -657,10 +658,10 @@ public function it_keeps_existing_uitpas_prices_on_price_info_update(): void 'd2b41f1d-598c-46af-a3a5-10e373faa6fe', (new PriceInfo(new BasePrice(new Money(100, new Currency('EUR'))))) ->withUiTPASTariffs([ - new \CultuurNet\UDB3\PriceInfo\Tariff( - new MultilingualString( + new LegacyTariff( + new TranslatedTariffName( new Language('nl'), - 'Tariff 1' + new TariffName('Tariff 1') ), new Money( 199, @@ -687,10 +688,10 @@ public function it_keeps_existing_uitpas_prices_on_price_info_update(): void 'd2b41f1d-598c-46af-a3a5-10e373faa6fe', (new PriceInfo(new BasePrice(new Money(90, new Currency('EUR'))))) ->withUiTPASTariffs([ - new \CultuurNet\UDB3\PriceInfo\Tariff( - new MultilingualString( + new LegacyTariff( + new TranslatedTariffName( new Language('nl'), - 'Tariff 1' + new TariffName('Tariff 1') ), new Money( 199, @@ -725,10 +726,10 @@ public function it_ignores_an_update_of_uitpas_prices(): void 'd2b41f1d-598c-46af-a3a5-10e373faa6fe', (new PriceInfo(new BasePrice(new Money(100, new Currency('EUR'))))) ->withUiTPASTariffs([ - new \CultuurNet\UDB3\PriceInfo\Tariff( - new MultilingualString( + new LegacyTariff( + new TranslatedTariffName( new Language('nl'), - 'Tariff 1' + new TariffName('Tariff 1') ), new Money( 199, @@ -748,10 +749,10 @@ public function it_ignores_an_update_of_uitpas_prices(): void ) ) ))->withUiTPASTariffs([ - new \CultuurNet\UDB3\PriceInfo\Tariff( - new MultilingualString( + new LegacyTariff( + new TranslatedTariffName( new Language('nl'), - 'Tariff 1' + new TariffName('Tariff 1') ), new Money( 80, @@ -766,10 +767,10 @@ public function it_ignores_an_update_of_uitpas_prices(): void 'd2b41f1d-598c-46af-a3a5-10e373faa6fe', (new PriceInfo(new BasePrice(new Money(90, new Currency('EUR'))))) ->withUiTPASTariffs([ - new \CultuurNet\UDB3\PriceInfo\Tariff( - new MultilingualString( + new LegacyTariff( + new TranslatedTariffName( new Language('nl'), - 'Tariff 1' + new TariffName('Tariff 1') ), new Money( 199, @@ -804,10 +805,10 @@ public function it_ignores_an_update_with_equal_prices_without_uitpas(): void 'd2b41f1d-598c-46af-a3a5-10e373faa6fe', (new PriceInfo(new BasePrice(new Money(100, new Currency('EUR'))))) ->withUiTPASTariffs([ - new \CultuurNet\UDB3\PriceInfo\Tariff( - new MultilingualString( + new LegacyTariff( + new TranslatedTariffName( new Language('nl'), - 'Tariff 1' + new TariffName('Tariff 1') ), new Money( 199, @@ -855,10 +856,10 @@ public function it_ignores_an_update_with_only_different_uitpas_prices(): void 'd2b41f1d-598c-46af-a3a5-10e373faa6fe', (new PriceInfo(new BasePrice(new Money(100, new Currency('EUR'))))) ->withUiTPASTariffs([ - new \CultuurNet\UDB3\PriceInfo\Tariff( - new MultilingualString( + new LegacyTariff( + new TranslatedTariffName( new Language('nl'), - 'Tariff 1' + new TariffName('Tariff 1') ), new Money( 199, @@ -879,10 +880,10 @@ public function it_ignores_an_update_with_only_different_uitpas_prices(): void ) ) )->withUiTPASTariffs([ - new \CultuurNet\UDB3\PriceInfo\Tariff( - new MultilingualString( + new LegacyTariff( + new TranslatedTariffName( new Language('nl'), - 'Tariff 1' + new TariffName('Tariff 1') ), new Money( 80, @@ -947,10 +948,10 @@ public function it_handles_update_price_info_from_udb2_update(): void fn (Event $event) => $event->updatePriceInfo( (new PriceInfo((new BasePrice(new Money(1250, new Currency('EUR')))))) ->withTariffs([ - new \CultuurNet\UDB3\PriceInfo\Tariff( - new MultilingualString( + new LegacyTariff( + new TranslatedTariffName( new Language('nl'), - 'Met kinderen' + new TariffName('Met kinderen') ), new Money(2000, new Currency('EUR')) ), @@ -961,10 +962,10 @@ public function it_handles_update_price_info_from_udb2_update(): void fn (Event $event) => $event->updatePriceInfo( (new PriceInfo((new BasePrice(new Money(1250, new Currency('EUR')))))) ->withTariffs([ - new \CultuurNet\UDB3\PriceInfo\Tariff( - new MultilingualString( + new LegacyTariff( + new TranslatedTariffName( new Language('nl'), - 'Met kinderen' + new TariffName('Met kinderen') ), new Money(1499, new Currency('EUR')) ), @@ -976,10 +977,10 @@ public function it_handles_update_price_info_from_udb2_update(): void $eventId, (new PriceInfo(new BasePrice(new Money(1250, new Currency('EUR'))))) ->withTariffs([ - new \CultuurNet\UDB3\PriceInfo\Tariff( - new MultilingualString( + new LegacyTariff( + new TranslatedTariffName( new Language('nl'), - 'Met kinderen' + new TariffName('Met kinderen') ), new Money(1499, new Currency('EUR')) ), @@ -1922,20 +1923,20 @@ public function it_ignores_equal_uitpas_prices(): void 'd2b41f1d-598c-46af-a3a5-10e373faa6fe', (new PriceInfo(new BasePrice(new Money(100, new Currency('EUR'))))) ->withUiTPASTariffs([ - new \CultuurNet\UDB3\PriceInfo\Tariff( - new MultilingualString( + new LegacyTariff( + new TranslatedTariffName( new Language('nl'), - 'Tariff 1' + new TariffName('Tariff 1') ), new Money( 199, new Currency('EUR') ) ), - new \CultuurNet\UDB3\PriceInfo\Tariff( - new MultilingualString( + new LegacyTariff( + new TranslatedTariffName( new Language('nl'), - 'Tariff 2' + new TariffName('Tariff 2') ), new Money( 299, @@ -2023,20 +2024,20 @@ function (Event $event): void { 'd2b41f1d-598c-46af-a3a5-10e373faa6fe', (new PriceInfo(new BasePrice(new Money(100, new Currency('EUR'))))) ->withUiTPASTariffs([ - new \CultuurNet\UDB3\PriceInfo\Tariff( - new MultilingualString( + new LegacyTariff( + new TranslatedTariffName( new Language('nl'), - 'Tariff 1' + new TariffName('Tariff 1') ), new Money( 199, new Currency('EUR') ) ), - new \CultuurNet\UDB3\PriceInfo\Tariff( - new MultilingualString( + new LegacyTariff( + new TranslatedTariffName( new Language('nl'), - 'Tariff 2' + new TariffName('Tariff 2') ), new Money( 299, diff --git a/tests/Model/Import/Offer/Udb3ModelToLegacyOfferAdapterTest.php b/tests/Model/Import/Offer/Udb3ModelToLegacyOfferAdapterTest.php index de11f930ec..4b743f7bb7 100644 --- a/tests/Model/Import/Offer/Udb3ModelToLegacyOfferAdapterTest.php +++ b/tests/Model/Import/Offer/Udb3ModelToLegacyOfferAdapterTest.php @@ -45,6 +45,7 @@ use CultuurNet\UDB3\Model\ValueObject\Web\WebsiteLabel; use CultuurNet\UDB3\Model\ValueObject\Web\WebsiteLink; use CultuurNet\UDB3\PriceInfo\BasePrice; +use CultuurNet\UDB3\PriceInfo\Tariff as LegacyTariff; use CultuurNet\UDB3\Theme; use CultuurNet\UDB3\ValueObject\MultilingualString; use DateTimeImmutable; @@ -299,8 +300,8 @@ public function it_should_return_price_info_if_there_is_any(): void ) ); $expected = $expected->withExtraTariff( - new \CultuurNet\UDB3\PriceInfo\Tariff( - new MultilingualString(new Language('nl'), 'Senioren'), + new LegacyTariff( + new TranslatedTariffName(new Language('nl'), new TariffName('Senioren')), new Money(1050, new Currency('EUR')) ) ); diff --git a/tests/Offer/ReadModel/JSONLD/OfferLDProjectorTest.php b/tests/Offer/ReadModel/JSONLD/OfferLDProjectorTest.php index f6fde5f3e9..77256c68d9 100644 --- a/tests/Offer/ReadModel/JSONLD/OfferLDProjectorTest.php +++ b/tests/Offer/ReadModel/JSONLD/OfferLDProjectorTest.php @@ -24,6 +24,8 @@ use CultuurNet\UDB3\Model\ValueObject\Identity\UUID; use CultuurNet\UDB3\Model\ValueObject\MediaObject\CopyrightHolder; use CultuurNet\UDB3\Model\ValueObject\MediaObject\Video; +use CultuurNet\UDB3\Model\ValueObject\Price\TariffName; +use CultuurNet\UDB3\Model\ValueObject\Price\TranslatedTariffName; use CultuurNet\UDB3\Model\ValueObject\Text\Description; use CultuurNet\UDB3\Model\ValueObject\Translation\Language; use CultuurNet\UDB3\Model\ValueObject\Web\Url; @@ -761,9 +763,9 @@ public function it_projects_the_updated_price_info(): void $priceInfo = $priceInfo->withExtraTariff( new Tariff( - new MultilingualString( + new TranslatedTariffName( new Language('nl'), - 'Tarief inwoners' + new TariffName('Tarief inwoners') ), new Money(950, new Currency('EUR')) ) @@ -771,9 +773,9 @@ public function it_projects_the_updated_price_info(): void $priceInfo = $priceInfo->withExtraUiTPASTariff( new Tariff( - new MultilingualString( + new TranslatedTariffName( new Language('nl'), - 'UiTPAS tarief' + new TariffName('UiTPAS tarief') ), new Money(650, new Currency('EUR')) ) diff --git a/tests/PriceInfo/PriceInfoTest.php b/tests/PriceInfo/PriceInfoTest.php index c61c1e9531..de6cfcd782 100644 --- a/tests/PriceInfo/PriceInfoTest.php +++ b/tests/PriceInfo/PriceInfoTest.php @@ -8,7 +8,6 @@ use CultuurNet\UDB3\Model\ValueObject\Price\Tariffs; use CultuurNet\UDB3\Model\ValueObject\Price\TranslatedTariffName; use CultuurNet\UDB3\Model\ValueObject\Translation\Language; -use CultuurNet\UDB3\ValueObject\MultilingualString; use Money\Currency; use Money\Money; use PHPUnit\Framework\TestCase; @@ -37,9 +36,9 @@ public function setUp(): void $this->tariffs = [ new Tariff( - new MultilingualString( + new TranslatedTariffName( new Language('nl'), - 'Tarief inwoners' + new TariffName('Inwoners') ), new Money(950, new Currency('EUR')) ), @@ -47,9 +46,9 @@ public function setUp(): void $this->uitpasTariffs = [ new Tariff( - new MultilingualString( + new TranslatedTariffName( new Language('nl'), - 'UiTPAS tarief' + new TariffName('UiTPAS tarief') ), new Money(650, new Currency('EUR')) ), @@ -103,7 +102,7 @@ public function it_should_be_creatable_from_an_udb3_model_price_info_without_tar $udb3ModelPriceInfo = new \CultuurNet\UDB3\Model\ValueObject\Price\PriceInfo( new \CultuurNet\UDB3\Model\ValueObject\Price\Tariff( new TranslatedTariffName( - new \CultuurNet\UDB3\Model\ValueObject\Translation\Language('nl'), + new Language('nl'), new TariffName('Basistarief') ), new Money(1000, new Currency('EUR')) @@ -154,9 +153,9 @@ public function it_should_be_creatable_from_an_udb3_model_price_info_with_tariff $expected = $expected ->withExtraTariff( new Tariff( - new MultilingualString( + new TranslatedTariffName( new Language('nl'), - 'Senioren' + new TariffName('Senioren') ), new Money(500, new Currency('EUR')) ) From 3acfaa9ec667f0454e5f5e3e224ec07164da5d98 Mon Sep 17 00:00:00 2001 From: Luc Wollants Date: Tue, 19 Nov 2024 08:10:39 +0100 Subject: [PATCH 04/10] Add simple normalizer and denormalizer for `Tariff` --- .../ValueObject/Price/TariffDenormalizer.php | 33 +++++++++++++++++++ .../ValueObject/Price/TariffNormalizer.php | 28 ++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 src/Model/Serializer/ValueObject/Price/TariffDenormalizer.php create mode 100644 src/Model/Serializer/ValueObject/Price/TariffNormalizer.php diff --git a/src/Model/Serializer/ValueObject/Price/TariffDenormalizer.php b/src/Model/Serializer/ValueObject/Price/TariffDenormalizer.php new file mode 100644 index 0000000000..ac6eeb9c44 --- /dev/null +++ b/src/Model/Serializer/ValueObject/Price/TariffDenormalizer.php @@ -0,0 +1,33 @@ +denormalize( + $data['name'], + TranslatedTariffName::class + ); + + return new Tariff( + $tariffName, + MoneyFactory::createFromCents($data['price'], new Currency($data['currency'])) + ); + } + + public function supportsDenormalization($data, $type, $format = null): bool + { + return $type === Tariff::class; + } +} diff --git a/src/Model/Serializer/ValueObject/Price/TariffNormalizer.php b/src/Model/Serializer/ValueObject/Price/TariffNormalizer.php new file mode 100644 index 0000000000..ad8517d828 --- /dev/null +++ b/src/Model/Serializer/ValueObject/Price/TariffNormalizer.php @@ -0,0 +1,28 @@ + (new TranslatedTariffNameNormalizer())->normalize($tariff->getName()), + 'price' => $tariff->getPrice()->getAmount(), + 'currency' => $tariff->getPrice()->getCurrency()->getName(), + ]; + } + + public function supportsNormalization($data, $format = null): bool + { + return $data === Tariff::class; + } +} From 22a2ea6bb22baa0795eefe7b37b5611bb414a0b0 Mon Sep 17 00:00:00 2001 From: Luc Wollants Date: Tue, 19 Nov 2024 08:11:21 +0100 Subject: [PATCH 05/10] Fix typo, should have been `$type` instead of `$data` --- .../ValueObject/Audience/AudienceTypeDenormalizer.php | 2 +- .../Serializer/ValueObject/Calendar/OpeningHourDenormalizer.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Model/Serializer/ValueObject/Audience/AudienceTypeDenormalizer.php b/src/Model/Serializer/ValueObject/Audience/AudienceTypeDenormalizer.php index 836bda686b..18ec829503 100644 --- a/src/Model/Serializer/ValueObject/Audience/AudienceTypeDenormalizer.php +++ b/src/Model/Serializer/ValueObject/Audience/AudienceTypeDenormalizer.php @@ -16,6 +16,6 @@ public function denormalize($data, $class, $format = null, array $context = []): public function supportsDenormalization($data, $type, $format = null) { - return $data === AudienceType::class; + return $type === AudienceType::class; } } diff --git a/src/Model/Serializer/ValueObject/Calendar/OpeningHourDenormalizer.php b/src/Model/Serializer/ValueObject/Calendar/OpeningHourDenormalizer.php index d9d0239599..719b8f91fb 100644 --- a/src/Model/Serializer/ValueObject/Calendar/OpeningHourDenormalizer.php +++ b/src/Model/Serializer/ValueObject/Calendar/OpeningHourDenormalizer.php @@ -22,6 +22,6 @@ public function denormalize($data, $class, $format = null, array $context = []): public function supportsDenormalization($data, $type, $format = null): bool { - return $data === OpeningHour::class; + return $type === OpeningHour::class; } } From 85b89e3977cb4971f49cba52e995908f64f8eb97 Mon Sep 17 00:00:00 2001 From: Luc Wollants Date: Tue, 19 Nov 2024 08:11:46 +0100 Subject: [PATCH 06/10] Refactor legacy `Tariff` in src --- src/Cdb/CdbXmlPriceInfoParser.php | 2 +- src/Event/Event.php | 3 +-- .../JSONLD/CdbXMLItemBaseImporter.php | 2 +- .../ReadModel/JSONLD/OfferLDProjector.php | 4 ++-- src/PriceInfo/PriceInfo.php | 18 ++++++++++++------ 5 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/Cdb/CdbXmlPriceInfoParser.php b/src/Cdb/CdbXmlPriceInfoParser.php index f02fdb367d..c9025622d9 100644 --- a/src/Cdb/CdbXmlPriceInfoParser.php +++ b/src/Cdb/CdbXmlPriceInfoParser.php @@ -6,13 +6,13 @@ use CultureFeed_Cdb_Data_Detail; use CultureFeed_Cdb_Data_Price; +use CultuurNet\UDB3\Model\ValueObject\Price\Tariff; use CultuurNet\UDB3\Model\ValueObject\Price\TariffName; use CultuurNet\UDB3\Model\ValueObject\Price\TranslatedTariffName; use CultuurNet\UDB3\Model\ValueObject\Translation\Language; use CultuurNet\UDB3\MoneyFactory; use CultuurNet\UDB3\PriceInfo\BasePrice; use CultuurNet\UDB3\PriceInfo\PriceInfo; -use CultuurNet\UDB3\PriceInfo\Tariff; use Money\Currency; final class CdbXmlPriceInfoParser diff --git a/src/Event/Event.php b/src/Event/Event.php index 60616bf712..0406baef8d 100644 --- a/src/Event/Event.php +++ b/src/Event/Event.php @@ -91,7 +91,6 @@ use CultuurNet\UDB3\Offer\Offer; use CultuurNet\UDB3\Offer\OfferType; use CultuurNet\UDB3\PriceInfo\PriceInfo; -use CultuurNet\UDB3\PriceInfo\Tariff; use CultuurNet\UDB3\Theme; use CultuurNet\UDB3\Model\ValueObject\Text\Title; use DateTimeImmutable; @@ -506,7 +505,7 @@ public function updateUiTPASPrices(Tariffs $tariffs): void $legacyUiTPASTariffs = []; foreach ($tariffs as $tariff) { - $legacyUiTPASTariffs[] = Tariff::fromUdb3ModelTariff($tariff); + $legacyUiTPASTariffs[] = $tariff; } $newPriceInfo = $this->priceInfo->withUiTPASTariffs($legacyUiTPASTariffs); diff --git a/src/Offer/ReadModel/JSONLD/CdbXMLItemBaseImporter.php b/src/Offer/ReadModel/JSONLD/CdbXMLItemBaseImporter.php index 2cf24d7dc1..af9a1d9738 100644 --- a/src/Offer/ReadModel/JSONLD/CdbXMLItemBaseImporter.php +++ b/src/Offer/ReadModel/JSONLD/CdbXMLItemBaseImporter.php @@ -143,7 +143,7 @@ public function importPriceInfo( 'category' => 'tariff', 'name' => (new TranslatedTariffNameNormalizer())->normalize($tariff->getName()), 'price' => $tariff->getPrice()->getAmount() / 100, - 'priceCurrency' => $tariff->getCurrency()->getName(), + 'priceCurrency' => $tariff->getPrice()->getCurrency()->getName(), ]; } } diff --git a/src/Offer/ReadModel/JSONLD/OfferLDProjector.php b/src/Offer/ReadModel/JSONLD/OfferLDProjector.php index 409f88fdd0..0da8489ce4 100644 --- a/src/Offer/ReadModel/JSONLD/OfferLDProjector.php +++ b/src/Offer/ReadModel/JSONLD/OfferLDProjector.php @@ -676,7 +676,7 @@ protected function applyPriceInfoUpdated(AbstractPriceInfoUpdated $priceInfoUpda 'category' => 'tariff', 'name' => $translatedTariffNameNormalizer->normalize($tariff->getName()), 'price' => $tariff->getPrice()->getAmount() / 100, - 'priceCurrency' => $tariff->getCurrency()->getName(), + 'priceCurrency' => $tariff->getPrice()->getCurrency()->getName(), ]; } @@ -685,7 +685,7 @@ protected function applyPriceInfoUpdated(AbstractPriceInfoUpdated $priceInfoUpda 'category' => 'uitpas', 'name' => $translatedTariffNameNormalizer->normalize($tariff->getName()), 'price' => $tariff->getPrice()->getAmount() / 100, - 'priceCurrency' => $tariff->getCurrency()->getName(), + 'priceCurrency' => $tariff->getPrice()->getCurrency()->getName(), ]; } diff --git a/src/PriceInfo/PriceInfo.php b/src/PriceInfo/PriceInfo.php index 498dfb6974..ed82747045 100644 --- a/src/PriceInfo/PriceInfo.php +++ b/src/PriceInfo/PriceInfo.php @@ -5,7 +5,10 @@ namespace CultuurNet\UDB3\PriceInfo; use Broadway\Serializer\Serializable; +use CultuurNet\UDB3\Model\Serializer\ValueObject\Price\TariffDenormalizer; +use CultuurNet\UDB3\Model\Serializer\ValueObject\Price\TariffNormalizer; use CultuurNet\UDB3\Model\ValueObject\Price\PriceInfo as Udb3ModelPriceInfo; +use CultuurNet\UDB3\Model\ValueObject\Price\Tariff; /** * @deprecated @@ -86,12 +89,14 @@ public function serialize(): array 'uitpas_tariffs' => [], ]; + $tariffNormalizer = new TariffNormalizer(); + foreach ($this->tariffs as $tariff) { - $serialized['tariffs'][] = $tariff->serialize(); + $serialized['tariffs'][] = $tariffNormalizer->normalize($tariff); } foreach ($this->uitpasTariffs as $uitpasTariff) { - $serialized['uitpas_tariffs'][] = $uitpasTariff->serialize(); + $serialized['uitpas_tariffs'][] = $tariffNormalizer->normalize($uitpasTariff); } return $serialized; @@ -103,16 +108,18 @@ public static function deserialize(array $data): PriceInfo $priceInfo = new PriceInfo($basePriceInfo); + $tariffDenormalizer = new TariffDenormalizer(); + foreach ($data['tariffs'] as $tariffData) { $priceInfo = $priceInfo->withExtraTariff( - Tariff::deserialize($tariffData) + $tariffDenormalizer->denormalize($tariffData, Tariff::class) ); } if (isset($data['uitpas_tariffs'])) { foreach ($data['uitpas_tariffs'] as $uitpasTariffData) { $priceInfo = $priceInfo->withExtraUiTPASTariff( - Tariff::deserialize($uitpasTariffData) + $tariffDenormalizer->denormalize($uitpasTariffData, Tariff::class) ); } } @@ -126,8 +133,7 @@ public static function fromUdb3ModelPriceInfo(Udb3ModelPriceInfo $udb3ModelPrice $priceInfo = new PriceInfo($basePrice); foreach ($udb3ModelPriceInfo->getTariffs() as $udb3ModelTariff) { - $tariff = Tariff::fromUdb3ModelTariff($udb3ModelTariff); - $priceInfo = $priceInfo->withExtraTariff($tariff); + $priceInfo = $priceInfo->withExtraTariff($udb3ModelTariff); } return $priceInfo; From f5674d77bf2dc0b0da2ad67d58df3cb3d886f0b1 Mon Sep 17 00:00:00 2001 From: Luc Wollants Date: Tue, 19 Nov 2024 08:11:57 +0100 Subject: [PATCH 07/10] Refactor legacy `Tariff` in tests --- ...CompatiblePayloadSerializerFactoryTest.php | 2 +- tests/Event/EventTest.php | 31 +++++++++---------- .../Udb3ModelToLegacyOfferAdapterTest.php | 3 +- .../ReadModel/JSONLD/OfferLDProjectorTest.php | 2 +- tests/PriceInfo/PriceInfoTest.php | 11 ++++--- 5 files changed, 24 insertions(+), 25 deletions(-) diff --git a/tests/BackwardsCompatiblePayloadSerializerFactoryTest.php b/tests/BackwardsCompatiblePayloadSerializerFactoryTest.php index f7340f0470..e90802a83b 100644 --- a/tests/BackwardsCompatiblePayloadSerializerFactoryTest.php +++ b/tests/BackwardsCompatiblePayloadSerializerFactoryTest.php @@ -25,6 +25,7 @@ use CultuurNet\UDB3\Model\ValueObject\Contact\TelephoneNumber; use CultuurNet\UDB3\Model\ValueObject\Contact\TelephoneNumbers; use CultuurNet\UDB3\Model\ValueObject\Identity\UUID; +use CultuurNet\UDB3\Model\ValueObject\Price\Tariff; use CultuurNet\UDB3\Model\ValueObject\Text\Description; use CultuurNet\UDB3\Model\ValueObject\Price\TariffName; use CultuurNet\UDB3\Model\ValueObject\Price\TranslatedTariffName; @@ -38,7 +39,6 @@ use CultuurNet\UDB3\Place\Events\PlaceCreated; use CultuurNet\UDB3\PriceInfo\BasePrice; use CultuurNet\UDB3\PriceInfo\PriceInfo; -use CultuurNet\UDB3\PriceInfo\Tariff; use CultuurNet\UDB3\Role\Events\ConstraintAdded; use CultuurNet\UDB3\ValueObject\MultilingualString; use CultuurNet\UDB3\Model\ValueObject\Translation\Language; diff --git a/tests/Event/EventTest.php b/tests/Event/EventTest.php index f44bd6cd46..6a82a5afb8 100644 --- a/tests/Event/EventTest.php +++ b/tests/Event/EventTest.php @@ -61,7 +61,6 @@ use CultuurNet\UDB3\Offer\AgeRange; use CultuurNet\UDB3\PriceInfo\BasePrice; use CultuurNet\UDB3\PriceInfo\PriceInfo; -use CultuurNet\UDB3\PriceInfo\Tariff as LegacyTariff; use CultuurNet\UDB3\SampleFiles; use CultuurNet\UDB3\Theme; use CultuurNet\UDB3\Model\ValueObject\Text\Title; @@ -658,7 +657,7 @@ public function it_keeps_existing_uitpas_prices_on_price_info_update(): void 'd2b41f1d-598c-46af-a3a5-10e373faa6fe', (new PriceInfo(new BasePrice(new Money(100, new Currency('EUR'))))) ->withUiTPASTariffs([ - new LegacyTariff( + new Tariff( new TranslatedTariffName( new Language('nl'), new TariffName('Tariff 1') @@ -688,7 +687,7 @@ public function it_keeps_existing_uitpas_prices_on_price_info_update(): void 'd2b41f1d-598c-46af-a3a5-10e373faa6fe', (new PriceInfo(new BasePrice(new Money(90, new Currency('EUR'))))) ->withUiTPASTariffs([ - new LegacyTariff( + new Tariff( new TranslatedTariffName( new Language('nl'), new TariffName('Tariff 1') @@ -726,7 +725,7 @@ public function it_ignores_an_update_of_uitpas_prices(): void 'd2b41f1d-598c-46af-a3a5-10e373faa6fe', (new PriceInfo(new BasePrice(new Money(100, new Currency('EUR'))))) ->withUiTPASTariffs([ - new LegacyTariff( + new Tariff( new TranslatedTariffName( new Language('nl'), new TariffName('Tariff 1') @@ -749,7 +748,7 @@ public function it_ignores_an_update_of_uitpas_prices(): void ) ) ))->withUiTPASTariffs([ - new LegacyTariff( + new Tariff( new TranslatedTariffName( new Language('nl'), new TariffName('Tariff 1') @@ -767,7 +766,7 @@ public function it_ignores_an_update_of_uitpas_prices(): void 'd2b41f1d-598c-46af-a3a5-10e373faa6fe', (new PriceInfo(new BasePrice(new Money(90, new Currency('EUR'))))) ->withUiTPASTariffs([ - new LegacyTariff( + new Tariff( new TranslatedTariffName( new Language('nl'), new TariffName('Tariff 1') @@ -805,7 +804,7 @@ public function it_ignores_an_update_with_equal_prices_without_uitpas(): void 'd2b41f1d-598c-46af-a3a5-10e373faa6fe', (new PriceInfo(new BasePrice(new Money(100, new Currency('EUR'))))) ->withUiTPASTariffs([ - new LegacyTariff( + new Tariff( new TranslatedTariffName( new Language('nl'), new TariffName('Tariff 1') @@ -856,7 +855,7 @@ public function it_ignores_an_update_with_only_different_uitpas_prices(): void 'd2b41f1d-598c-46af-a3a5-10e373faa6fe', (new PriceInfo(new BasePrice(new Money(100, new Currency('EUR'))))) ->withUiTPASTariffs([ - new LegacyTariff( + new Tariff( new TranslatedTariffName( new Language('nl'), new TariffName('Tariff 1') @@ -880,7 +879,7 @@ public function it_ignores_an_update_with_only_different_uitpas_prices(): void ) ) )->withUiTPASTariffs([ - new LegacyTariff( + new Tariff( new TranslatedTariffName( new Language('nl'), new TariffName('Tariff 1') @@ -948,7 +947,7 @@ public function it_handles_update_price_info_from_udb2_update(): void fn (Event $event) => $event->updatePriceInfo( (new PriceInfo((new BasePrice(new Money(1250, new Currency('EUR')))))) ->withTariffs([ - new LegacyTariff( + new Tariff( new TranslatedTariffName( new Language('nl'), new TariffName('Met kinderen') @@ -962,7 +961,7 @@ public function it_handles_update_price_info_from_udb2_update(): void fn (Event $event) => $event->updatePriceInfo( (new PriceInfo((new BasePrice(new Money(1250, new Currency('EUR')))))) ->withTariffs([ - new LegacyTariff( + new Tariff( new TranslatedTariffName( new Language('nl'), new TariffName('Met kinderen') @@ -977,7 +976,7 @@ public function it_handles_update_price_info_from_udb2_update(): void $eventId, (new PriceInfo(new BasePrice(new Money(1250, new Currency('EUR'))))) ->withTariffs([ - new LegacyTariff( + new Tariff( new TranslatedTariffName( new Language('nl'), new TariffName('Met kinderen') @@ -1923,7 +1922,7 @@ public function it_ignores_equal_uitpas_prices(): void 'd2b41f1d-598c-46af-a3a5-10e373faa6fe', (new PriceInfo(new BasePrice(new Money(100, new Currency('EUR'))))) ->withUiTPASTariffs([ - new LegacyTariff( + new Tariff( new TranslatedTariffName( new Language('nl'), new TariffName('Tariff 1') @@ -1933,7 +1932,7 @@ public function it_ignores_equal_uitpas_prices(): void new Currency('EUR') ) ), - new LegacyTariff( + new Tariff( new TranslatedTariffName( new Language('nl'), new TariffName('Tariff 2') @@ -2024,7 +2023,7 @@ function (Event $event): void { 'd2b41f1d-598c-46af-a3a5-10e373faa6fe', (new PriceInfo(new BasePrice(new Money(100, new Currency('EUR'))))) ->withUiTPASTariffs([ - new LegacyTariff( + new Tariff( new TranslatedTariffName( new Language('nl'), new TariffName('Tariff 1') @@ -2034,7 +2033,7 @@ function (Event $event): void { new Currency('EUR') ) ), - new LegacyTariff( + new Tariff( new TranslatedTariffName( new Language('nl'), new TariffName('Tariff 2') diff --git a/tests/Model/Import/Offer/Udb3ModelToLegacyOfferAdapterTest.php b/tests/Model/Import/Offer/Udb3ModelToLegacyOfferAdapterTest.php index 4b743f7bb7..4e9138605f 100644 --- a/tests/Model/Import/Offer/Udb3ModelToLegacyOfferAdapterTest.php +++ b/tests/Model/Import/Offer/Udb3ModelToLegacyOfferAdapterTest.php @@ -45,7 +45,6 @@ use CultuurNet\UDB3\Model\ValueObject\Web\WebsiteLabel; use CultuurNet\UDB3\Model\ValueObject\Web\WebsiteLink; use CultuurNet\UDB3\PriceInfo\BasePrice; -use CultuurNet\UDB3\PriceInfo\Tariff as LegacyTariff; use CultuurNet\UDB3\Theme; use CultuurNet\UDB3\ValueObject\MultilingualString; use DateTimeImmutable; @@ -300,7 +299,7 @@ public function it_should_return_price_info_if_there_is_any(): void ) ); $expected = $expected->withExtraTariff( - new LegacyTariff( + new Tariff( new TranslatedTariffName(new Language('nl'), new TariffName('Senioren')), new Money(1050, new Currency('EUR')) ) diff --git a/tests/Offer/ReadModel/JSONLD/OfferLDProjectorTest.php b/tests/Offer/ReadModel/JSONLD/OfferLDProjectorTest.php index 77256c68d9..8d78e73fed 100644 --- a/tests/Offer/ReadModel/JSONLD/OfferLDProjectorTest.php +++ b/tests/Offer/ReadModel/JSONLD/OfferLDProjectorTest.php @@ -24,6 +24,7 @@ use CultuurNet\UDB3\Model\ValueObject\Identity\UUID; use CultuurNet\UDB3\Model\ValueObject\MediaObject\CopyrightHolder; use CultuurNet\UDB3\Model\ValueObject\MediaObject\Video; +use CultuurNet\UDB3\Model\ValueObject\Price\Tariff; use CultuurNet\UDB3\Model\ValueObject\Price\TariffName; use CultuurNet\UDB3\Model\ValueObject\Price\TranslatedTariffName; use CultuurNet\UDB3\Model\ValueObject\Text\Description; @@ -60,7 +61,6 @@ use CultuurNet\UDB3\Offer\Item\ReadModel\JSONLD\ItemLDProjector; use CultuurNet\UDB3\PriceInfo\BasePrice; use CultuurNet\UDB3\PriceInfo\PriceInfo; -use CultuurNet\UDB3\PriceInfo\Tariff; use CultuurNet\UDB3\ReadModel\DocumentDoesNotExist; use CultuurNet\UDB3\ReadModel\DocumentRepository; use CultuurNet\UDB3\ReadModel\InMemoryDocumentRepository; diff --git a/tests/PriceInfo/PriceInfoTest.php b/tests/PriceInfo/PriceInfoTest.php index de6cfcd782..ad4a1c8c97 100644 --- a/tests/PriceInfo/PriceInfoTest.php +++ b/tests/PriceInfo/PriceInfoTest.php @@ -4,6 +4,7 @@ namespace CultuurNet\UDB3\PriceInfo; +use CultuurNet\UDB3\Model\ValueObject\Price\Tariff; use CultuurNet\UDB3\Model\ValueObject\Price\TariffName; use CultuurNet\UDB3\Model\ValueObject\Price\Tariffs; use CultuurNet\UDB3\Model\ValueObject\Price\TranslatedTariffName; @@ -100,7 +101,7 @@ public function it_can_be_serialized_and_deserialized(): void public function it_should_be_creatable_from_an_udb3_model_price_info_without_tariffs(): void { $udb3ModelPriceInfo = new \CultuurNet\UDB3\Model\ValueObject\Price\PriceInfo( - new \CultuurNet\UDB3\Model\ValueObject\Price\Tariff( + new Tariff( new TranslatedTariffName( new Language('nl'), new TariffName('Basistarief') @@ -127,17 +128,17 @@ public function it_should_be_creatable_from_an_udb3_model_price_info_without_tar public function it_should_be_creatable_from_an_udb3_model_price_info_with_tariffs(): void { $udb3ModelPriceInfo = new \CultuurNet\UDB3\Model\ValueObject\Price\PriceInfo( - new \CultuurNet\UDB3\Model\ValueObject\Price\Tariff( + new Tariff( new TranslatedTariffName( - new \CultuurNet\UDB3\Model\ValueObject\Translation\Language('nl'), + new Language('nl'), new TariffName('Basistarief') ), new Money(1000, new Currency('EUR')) ), new Tariffs( - new \CultuurNet\UDB3\Model\ValueObject\Price\Tariff( + new Tariff( new TranslatedTariffName( - new \CultuurNet\UDB3\Model\ValueObject\Translation\Language('nl'), + new Language('nl'), new TariffName('Senioren') ), new Money(500, new Currency('EUR')) From 95eebbabfd1235cdb331492c4ba2348c9eaff13a Mon Sep 17 00:00:00 2001 From: Luc Wollants Date: Tue, 19 Nov 2024 08:13:06 +0100 Subject: [PATCH 08/10] Remove legacy `Tariff` --- src/PriceInfo/Tariff.php | 79 ---------------------------------------- 1 file changed, 79 deletions(-) delete mode 100644 src/PriceInfo/Tariff.php diff --git a/src/PriceInfo/Tariff.php b/src/PriceInfo/Tariff.php deleted file mode 100644 index c542fc6e92..0000000000 --- a/src/PriceInfo/Tariff.php +++ /dev/null @@ -1,79 +0,0 @@ -name = $name; - $this->money = $money; - } - - public function getName(): TranslatedTariffName - { - return $this->name; - } - - public function getPrice(): Money - { - return $this->money; - } - - public function getCurrency(): Currency - { - return $this->money->getCurrency(); - } - - public function serialize(): array - { - return [ - 'name' => (new TranslatedTariffNameNormalizer())->normalize($this->getName()), - 'price' => $this->getPrice()->getAmount(), - 'currency' => $this->getCurrency()->getName(), - ]; - } - - public static function deserialize(array $data): Tariff - { - /** @var TranslatedTariffName $tariffName */ - $tariffName = (new TranslatedTariffNameDenormalizer())->denormalize( - $data['name'], - TranslatedTariffName::class - ); - - return new Tariff( - $tariffName, - MoneyFactory::createFromCents($data['price'], new Currency($data['currency'])) - ); - } - - public static function fromUdb3ModelTariff(Udb3ModelTariff $udb3ModelTariff): Tariff - { - return new Tariff( - $udb3ModelTariff->getName(), - $udb3ModelTariff->getPrice() - ); - } -} From 21827d05b97494d8ee01c82739eed07331ab4ddd Mon Sep 17 00:00:00 2001 From: JonasVHG <4658984+JonasVHG@users.noreply.github.com> Date: Tue, 19 Nov 2024 14:07:01 +0100 Subject: [PATCH 09/10] Add acceptance test for metadata --- features/history/metadata.feature | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 features/history/metadata.feature diff --git a/features/history/metadata.feature b/features/history/metadata.feature new file mode 100644 index 0000000000..d073445dc4 --- /dev/null +++ b/features/history/metadata.feature @@ -0,0 +1,29 @@ +Feature: Test the metadata in the history API + + Background: + Given I am using the UDB3 base URL + And I am authorized with an Auth0 client access token for "test_client" + And I create a minimal place and save the "url" as "placeUrl" + And I wait for the place with url "%{placeUrl}" to be indexed + And I create a minimal permanent event and save the "url" as "eventUrl" + And I wait for the event with url "%{eventUrl}" to be indexed + + Scenario: test metaData place + Given I am using an UiTID v1 API key of consumer "uitdatabank" + And I am authorized as JWT provider v1 user "centraal_beheerder" + And I send and accept "application/json" + And I send a GET request to "%{placeUrl}/history" + And the JSON response should include: + """ + "auth0ClientName":"UiTdatabank Acceptance Tests" + """ + + Scenario: test metaData event + Given I am using an UiTID v1 API key of consumer "uitdatabank" + And I am authorized as JWT provider v1 user "centraal_beheerder" + And I send and accept "application/json" + And I send a GET request to "%{eventUrl}/history" + And the JSON response should include: + """ + "auth0ClientName":"UiTdatabank Acceptance Tests" + """ From 899cf5ea08b1c04ec99b7fe3d7e76ac4c123e8da Mon Sep 17 00:00:00 2001 From: JonasVHG <4658984+JonasVHG@users.noreply.github.com> Date: Tue, 19 Nov 2024 14:22:29 +0100 Subject: [PATCH 10/10] cleanup code --- features/history/metadata.feature | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/features/history/metadata.feature b/features/history/metadata.feature index d073445dc4..768520fab1 100644 --- a/features/history/metadata.feature +++ b/features/history/metadata.feature @@ -13,17 +13,17 @@ Feature: Test the metadata in the history API And I am authorized as JWT provider v1 user "centraal_beheerder" And I send and accept "application/json" And I send a GET request to "%{placeUrl}/history" - And the JSON response should include: - """ - "auth0ClientName":"UiTdatabank Acceptance Tests" - """ + And the JSON response at "0/author" should be "pjeOqgEYI0Y4gmr8DWMpUrpTMXrvjgpc@clients" + And the JSON response at "0/auth0ClientId" should be "pjeOqgEYI0Y4gmr8DWMpUrpTMXrvjgpc" + And the JSON response at "0/auth0ClientName" should be "UiTdatabank Acceptance Tests" + And the JSON response at "0/api" should be "JSON-LD API" Scenario: test metaData event Given I am using an UiTID v1 API key of consumer "uitdatabank" And I am authorized as JWT provider v1 user "centraal_beheerder" And I send and accept "application/json" And I send a GET request to "%{eventUrl}/history" - And the JSON response should include: - """ - "auth0ClientName":"UiTdatabank Acceptance Tests" - """ + And the JSON response at "0/author" should be "pjeOqgEYI0Y4gmr8DWMpUrpTMXrvjgpc@clients" + And the JSON response at "0/auth0ClientId" should be "pjeOqgEYI0Y4gmr8DWMpUrpTMXrvjgpc" + And the JSON response at "0/auth0ClientName" should be "UiTdatabank Acceptance Tests" + And the JSON response at "0/api" should be "JSON-LD API"