From 9a903551007932e2d2c282a032700660cb21ebae Mon Sep 17 00:00:00 2001 From: Emily Borgers Date: Mon, 22 Mar 2021 15:58:46 +0100 Subject: [PATCH 1/7] CATWEB-37: Added environments object and mapping --- src/Mapper/ArrayToEckRecordMapper.php | 1 + src/Mapper/ArrayToEnvironmentsMapper.php | 22 +++++++ src/Model/Entry.php | 16 +++-- src/Model/Environments.php | 64 ++++++++++++++++++ tests/Mapper/ArrayToEckRecordMapperTest.php | 5 ++ .../Mapper/ArrayToEnvironmentsMapperTest.php | 66 +++++++++++++++++++ tests/builder/EckRecordBuilder.php | 8 +++ tests/builder/EnvironmentsBuilder.php | 44 +++++++++++++ tests/data/eckResponse.xml | 5 ++ 9 files changed, 227 insertions(+), 4 deletions(-) create mode 100644 src/Mapper/ArrayToEnvironmentsMapper.php create mode 100644 src/Model/Environments.php create mode 100644 tests/Mapper/ArrayToEnvironmentsMapperTest.php create mode 100644 tests/builder/EnvironmentsBuilder.php diff --git a/src/Mapper/ArrayToEckRecordMapper.php b/src/Mapper/ArrayToEckRecordMapper.php index 76b15ab..dba7b35 100644 --- a/src/Mapper/ArrayToEckRecordMapper.php +++ b/src/Mapper/ArrayToEckRecordMapper.php @@ -12,6 +12,7 @@ public static function mapArrayToEckRecord(array $recordArray): EckRecord $eckRecord = new EckRecord($recordArray['RecordId'], $recordArray['Title']); $eckRecord->setLastModifiedDate(StringToDateMapper::mapStringToDate($recordArray['LastModifiedDate'] ?? null)); $eckRecord->setDescription($recordArray['Description'] ?? ''); + $eckRecord->setEnvironments(ArrayToEnvironmentsMapper::mapArrayToEnvironments($recordArray['Environments'] ?? null)); $eckRecord->setPublisher($recordArray['Publisher'] ?? null); $eckRecord->setAuthors(ArrayToStringArrayMapper::mapArrayToStringArray($recordArray['Authors'] ?? [])); $eckRecord->setInformationLocation($recordArray['InformationLocation'] ?? null); diff --git a/src/Mapper/ArrayToEnvironmentsMapper.php b/src/Mapper/ArrayToEnvironmentsMapper.php new file mode 100644 index 0000000..a457cb0 --- /dev/null +++ b/src/Mapper/ArrayToEnvironmentsMapper.php @@ -0,0 +1,22 @@ +setPlatform(ArrayToStringArrayMapper::mapValueToStringArray($environmentsArray['Platform'] ?? null)); + $environments->setDevice(ArrayToStringArrayMapper::mapValueToStringArray($environmentsArray['Device'] ?? null)); + $environments->setBrowser(ArrayToStringArrayMapper::mapValueToStringArray($environmentsArray['Browser'] ?? null)); + return $environments; + } +} \ No newline at end of file diff --git a/src/Model/Entry.php b/src/Model/Entry.php index 53aed21..97cd81d 100644 --- a/src/Model/Entry.php +++ b/src/Model/Entry.php @@ -39,10 +39,8 @@ class Entry /** @var string */ private $description = ''; - /** - * TODO: Add Environments - * Environments - */ + /** @var Environments|null */ + private $environments = null; /** @var string|null */ private $contentLocation = null; @@ -212,6 +210,16 @@ public function getDescription(): string return $this->description; } + public function getEnvironments(): ?Environments + { + return $this->environments; + } + + public function setEnvironments(?Environments $environments): void + { + $this->environments = $environments; + } + public function getPublisher(): string { return $this->publisher; diff --git a/src/Model/Environments.php b/src/Model/Environments.php new file mode 100644 index 0000000..fc2d89f --- /dev/null +++ b/src/Model/Environments.php @@ -0,0 +1,64 @@ +platform; + } + + /** + * @param string[] $platform + */ + public function setPlatform(array $platform): void + { + $this->platform = $platform; + } + + /** + * @return string[] + */ + public function getDevice(): array + { + return $this->device; + } + + /** + * @param string[] $device + */ + public function setDevice(array $device): void + { + $this->device = $device; + } + + /** + * @return string[] + */ + public function getBrowser(): array + { + return $this->browser; + } + + /** + * @param string[] $browser + */ + public function setBrowser(array $browser): void + { + $this->browser = $browser; + } +} diff --git a/tests/Mapper/ArrayToEckRecordMapperTest.php b/tests/Mapper/ArrayToEckRecordMapperTest.php index 94da57c..fe01d46 100644 --- a/tests/Mapper/ArrayToEckRecordMapperTest.php +++ b/tests/Mapper/ArrayToEckRecordMapperTest.php @@ -8,6 +8,7 @@ use Kennisnet\ECK\EckRecord; use Kennisnet\ECK\ResponseSerializer; use Kennisnet\ECK\Tests\builder\EckRecordBuilder; +use Kennisnet\ECK\Tests\builder\EnvironmentsBuilder; use Kennisnet\ECK\Tests\builder\PriceBuilder; use Kennisnet\ECK\Tests\builder\PricesBuilder; use PHPUnit\Framework\TestCase; @@ -35,6 +36,10 @@ private function expectedResult(): EckRecord ->withProductThumbnailLocation('https://www.kinheim.com/wp-content/uploads/2012/05/712-292-Mijn-Boek-deel-2.png') ->withAuthors(['kinheim']) ->withDescription('Het aanbod van puzzels in Mijn Boek deel 3 omvat: woordzoekers, speurpuzzels, woordpuzzels, legletters, zoek de verschillen, anagrammen en magische vierkanten.') + ->withEnvironments(((new EnvironmentsBuilder()) + ->withPlatform(['iOS', 'Windows']) + ->withDevice(['pc ready'])) + ->build()) ->withContentLocation('https://www.kinheim.com/leermiddelen/mijn-boek-3/?attribute_pa_aantal=los-exemplaar') ->withIntendedEndUserRole('Onderwijsvolger') ->withProductState('Leverbaar') diff --git a/tests/Mapper/ArrayToEnvironmentsMapperTest.php b/tests/Mapper/ArrayToEnvironmentsMapperTest.php new file mode 100644 index 0000000..6d13b99 --- /dev/null +++ b/tests/Mapper/ArrayToEnvironmentsMapperTest.php @@ -0,0 +1,66 @@ + ['iOS', 'Android'], + 'Device' => ['mobile ready', 'tablet'], + 'Browser' => ['Chrome', 'Safari'], + ], + (new EnvironmentsBuilder()) + ->withPlatform(['iOS', 'Android']) + ->withDevice(['mobile ready', 'tablet']) + ->withBrowser(['Chrome', 'Safari']) + ->build() + , + 'Creates an environments object with multiple platforms, devices and browsers.' + ]; + + yield [ + [], + (new EnvironmentsBuilder()) + ->build() + , + 'Creates an environments object without any platforms, devices or browsers' + ]; + + yield [ + [ + 'Platform' => 'iOS' + ], + (new EnvironmentsBuilder()) + ->withPlatform(['iOS']) + ->build() + , + 'Creates an environments object with only a single platform and no devices or browsers' + ]; + + yield [ + null, + null, + 'No environments data returns null.' + ]; + } + + +} \ No newline at end of file diff --git a/tests/builder/EckRecordBuilder.php b/tests/builder/EckRecordBuilder.php index 0667e5b..b265c01 100644 --- a/tests/builder/EckRecordBuilder.php +++ b/tests/builder/EckRecordBuilder.php @@ -5,6 +5,7 @@ use DateTimeImmutable; use Kennisnet\ECK\EckRecord; +use Kennisnet\ECK\Model\Environments; use Kennisnet\ECK\Model\Prices; final class EckRecordBuilder @@ -43,6 +44,13 @@ public function withDescription(string $description): self return $builder; } + public function withEnvironments(?Environments $environments): self + { + $builder = clone $this; + $builder->record->setEnvironments($environments); + return $builder; + } + public function withInformationLocation(string $informationLocation): self { $builder = clone $this; diff --git a/tests/builder/EnvironmentsBuilder.php b/tests/builder/EnvironmentsBuilder.php new file mode 100644 index 0000000..c49f09f --- /dev/null +++ b/tests/builder/EnvironmentsBuilder.php @@ -0,0 +1,44 @@ +environments = $environments ?? new Environments(); + } + + public function build(): Environments + { + return $this->environments; + } + + public function withPlatform(array $platform): self + { + $builder = clone $this; + $builder->environments->setPlatform($platform); + return $builder; + } + + public function withDevice(array $device): self + { + $builder = clone $this; + $builder->environments->setDevice($device); + return $builder; + } + + public function withBrowser(array $browser): self + { + $builder = clone $this; + $builder->environments->setBrowser($browser); + return $builder; + } + +} \ No newline at end of file diff --git a/tests/data/eckResponse.xml b/tests/data/eckResponse.xml index d4738f7..f904908 100644 --- a/tests/data/eckResponse.xml +++ b/tests/data/eckResponse.xml @@ -27,6 +27,11 @@ Het aanbod van puzzels in Mijn Boek deel 3 omvat: woordzoekers, speurpuzzels, woordpuzzels, legletters, zoek de verschillen, anagrammen en magische vierkanten. + + iOS + Windows + pc ready + https://www.kinheim.com/leermiddelen/mijn-boek-3/?attribute_pa_aantal=los-exemplaar From a15e8072337a94136c195052b1fbd22f51224246 Mon Sep 17 00:00:00 2001 From: Emily Borgers Date: Mon, 22 Mar 2021 16:04:09 +0100 Subject: [PATCH 2/7] CATWEB-37: Added environments object and mapping --- src/Mapper/ArrayToStringArrayMapper.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Mapper/ArrayToStringArrayMapper.php b/src/Mapper/ArrayToStringArrayMapper.php index bbdf88a..6708242 100644 --- a/src/Mapper/ArrayToStringArrayMapper.php +++ b/src/Mapper/ArrayToStringArrayMapper.php @@ -12,9 +12,18 @@ public static function mapArrayToStringArray(array $arrayWithValues): array { $valueArray = array_values($arrayWithValues); $propertyValue = array_shift($valueArray); - if (is_array($propertyValue)){ - return $propertyValue; + return self::mapValueToStringArray($propertyValue); + } + + /** + * @param string[]|string|null $value + * @return string[] + */ + public static function mapValueToStringArray($value): array + { + if (is_array($value)) { + return $value; } - return null !== $propertyValue ? [$propertyValue] : []; + return null !== $value ? [$value] : []; } } From b8f07cce84026b9170ac3f249b6d44faa1abc66b Mon Sep 17 00:00:00 2001 From: Emily Borgers Date: Mon, 22 Mar 2021 18:49:28 +0100 Subject: [PATCH 3/7] CATWEB-37: Added activation before and additional license options objects/parameters --- src/Mapper/ArrayToActivationBeforeMapper.php | 24 ++++++++ .../ArrayToAdditionalLicenseOptionsMapper.php | 22 ++++++++ src/Mapper/ArrayToEckRecordMapper.php | 2 + src/Model/ActivationBefore.php | 47 ++++++++++++++++ src/Model/AdditionalLicenseOptions.php | 26 +++++++++ src/Model/Entry.php | 32 ++++++++--- .../ArrayToActivationBeforeMapperTest.php | 55 +++++++++++++++++++ ...ayToAdditionalLicenseOptionsMapperTest.php | 52 ++++++++++++++++++ tests/Mapper/ArrayToEckRecordMapperTest.php | 21 ++++++- .../Mapper/ArrayToEnvironmentsMapperTest.php | 2 - tests/builder/ActivationBeforeBuilder.php | 36 ++++++++++++ .../AdditionalLicenseOptionsBuilder.php | 29 ++++++++++ tests/builder/EckRecordBuilder.php | 16 ++++++ tests/builder/EnvironmentsBuilder.php | 1 - tests/data/eckResponse.xml | 8 +++ 15 files changed, 359 insertions(+), 14 deletions(-) create mode 100644 src/Mapper/ArrayToActivationBeforeMapper.php create mode 100644 src/Mapper/ArrayToAdditionalLicenseOptionsMapper.php create mode 100644 src/Model/ActivationBefore.php create mode 100644 src/Model/AdditionalLicenseOptions.php create mode 100644 tests/Mapper/ArrayToActivationBeforeMapperTest.php create mode 100644 tests/Mapper/ArrayToAdditionalLicenseOptionsMapperTest.php create mode 100644 tests/builder/ActivationBeforeBuilder.php create mode 100644 tests/builder/AdditionalLicenseOptionsBuilder.php diff --git a/src/Mapper/ArrayToActivationBeforeMapper.php b/src/Mapper/ArrayToActivationBeforeMapper.php new file mode 100644 index 0000000..d0e5ec4 --- /dev/null +++ b/src/Mapper/ArrayToActivationBeforeMapper.php @@ -0,0 +1,24 @@ +setActivationBeforeDays(StringToIntMapper::mapStringToNullableInt($activationBeforeArray['ActivationBeforeDays'] ?? null)); + $activationBefore->setActivationBeforeDate(StringToDateMapper::mapStringToDate($activationBeforeArray['ActivationBeforeDate'] ?? null)); + + return $activationBefore; + } + +} \ No newline at end of file diff --git a/src/Mapper/ArrayToAdditionalLicenseOptionsMapper.php b/src/Mapper/ArrayToAdditionalLicenseOptionsMapper.php new file mode 100644 index 0000000..ad453b3 --- /dev/null +++ b/src/Mapper/ArrayToAdditionalLicenseOptionsMapper.php @@ -0,0 +1,22 @@ +setAdditionalLicenseOption(ArrayToStringArrayMapper::mapValueToStringArray($additionalLicenseOptionsArray['AdditionalLicenseOption'] ?? null)); + return $additionalLicenseOptions; + + } + +} \ No newline at end of file diff --git a/src/Mapper/ArrayToEckRecordMapper.php b/src/Mapper/ArrayToEckRecordMapper.php index dba7b35..276ef47 100644 --- a/src/Mapper/ArrayToEckRecordMapper.php +++ b/src/Mapper/ArrayToEckRecordMapper.php @@ -48,11 +48,13 @@ public static function mapArrayToEckRecord(array $recordArray): EckRecord $eckRecord->setPrices(ArrayToPricesMapper::mapArrayToPrices($recordArray['Prices'] ?? [])); $eckRecord->setPriceIsIndicative(StringToBoolMapper::mapStringToBool($recordArray['PriceIsIndicative'] ?? null)); $eckRecord->setIsLicensed(StringToBoolMapper::mapStringToBool($recordArray['IsLicensed'] ?? null)); + $eckRecord->setActivationBefore(ArrayToActivationBeforeMapper::mapArrayToActivationBefore($recordArray['ActivationBefore'] ?? null)); $eckRecord->setLicenseAvailabilityOptions($recordArray['LicenseAvailabilityOptions'] ?? null); $eckRecord->setLicenseStartDate(StringToDateMapper::mapStringToDate($recordArray['LicenseStartDate'] ?? null)); $eckRecord->setLicenseEndDate(StringToDateMapper::mapStringToDate($recordArray['LicenseEndDate'] ?? null)); $eckRecord->setLicenseDuration($recordArray['LicenseDuration'] ?? null); $eckRecord->setLicenseCount(StringToIntMapper::mapStringToInt($recordArray['LicenseCount'] ?? null)); + $eckRecord->setAdditionalLicenseOptions(ArrayToAdditionalLicenseOptionsMapper::mapArrayToAdditionalLicenseOptions($recordArray['AdditionalLicenseOptions'])); $eckRecord->setIsCatalogItem(StringToBoolMapper::mapStringToBool($recordArray['IsCatalogItem'] ?? null)); $eckRecord->setCopyright($recordArray['Copyright'] ?? null); return $eckRecord; diff --git a/src/Model/ActivationBefore.php b/src/Model/ActivationBefore.php new file mode 100644 index 0000000..083854b --- /dev/null +++ b/src/Model/ActivationBefore.php @@ -0,0 +1,47 @@ +activationBeforeDays; + } + + /** + * @param int|null $activationBeforeDays + */ + public function setActivationBeforeDays(?int $activationBeforeDays): void + { + $this->activationBeforeDays = $activationBeforeDays; + } + + /** + * @return DateTimeImmutable|null + */ + public function getActivationBeforeDate(): ?DateTimeImmutable + { + return $this->activationBeforeDate; + } + + /** + * @param DateTimeImmutable|null $activationBeforeDate + */ + public function setActivationBeforeDate(?DateTimeImmutable $activationBeforeDate): void + { + $this->activationBeforeDate = $activationBeforeDate; + } +} \ No newline at end of file diff --git a/src/Model/AdditionalLicenseOptions.php b/src/Model/AdditionalLicenseOptions.php new file mode 100644 index 0000000..c2f220d --- /dev/null +++ b/src/Model/AdditionalLicenseOptions.php @@ -0,0 +1,26 @@ +additionalLicenseOption; + } + + /** + * @param string[] $additionalLicenseOption + */ + public function setAdditionalLicenseOption(array $additionalLicenseOption): void + { + $this->additionalLicenseOption = $additionalLicenseOption; + } +} \ No newline at end of file diff --git a/src/Model/Entry.php b/src/Model/Entry.php index 97cd81d..52d893c 100644 --- a/src/Model/Entry.php +++ b/src/Model/Entry.php @@ -139,10 +139,8 @@ class Entry /** @var bool */ private $isLicensed = false; - /** - * @Todo: Add ActivationBefore complex object - * ActivationBefore - **/ + /** @var ActivationBefore|null */ + private $activationBefore = null; /** @var string|null */ private $licenseAvailabilityOptions = null; @@ -159,10 +157,8 @@ class Entry /** @var int */ private $licenseCount = 0; - /** - * @Todo: Add AdditionalLicenseOptions complex object - * AdditionalLicenseOptions - **/ + /** @var AdditionalLicenseOptions */ + private $additionalLicenseOptions = null; /** @var bool */ private $isCatalogItem = false; @@ -583,6 +579,16 @@ public function setIsLicensed(bool $isLicensed): void $this->isLicensed = $isLicensed; } + public function getActivationBefore(): ?ActivationBefore + { + return $this->activationBefore; + } + + public function setActivationBefore(?ActivationBefore $activationBefore): void + { + $this->activationBefore = $activationBefore; + } + public function getLicenseAvailabilityOptions(): ?string { return $this->licenseAvailabilityOptions; @@ -633,6 +639,16 @@ public function setLicenseCount(int $licenseCount): void $this->licenseCount = $licenseCount; } + public function getAdditionalLicenseOptions(): ?AdditionalLicenseOptions + { + return $this->additionalLicenseOptions; + } + + public function setAdditionalLicenseOptions(?AdditionalLicenseOptions $additionalLicenseOptions): void + { + $this->additionalLicenseOptions = $additionalLicenseOptions; + } + public function isCatalogItem(): bool { return $this->isCatalogItem; diff --git a/tests/Mapper/ArrayToActivationBeforeMapperTest.php b/tests/Mapper/ArrayToActivationBeforeMapperTest.php new file mode 100644 index 0000000..99fc6e0 --- /dev/null +++ b/tests/Mapper/ArrayToActivationBeforeMapperTest.php @@ -0,0 +1,55 @@ + '30' + ], + (new ActivationBeforeBuilder()) + ->withActivationBeforeDays(30) + ->build() + , + 'Creates an activation before object with ActivationBeforeDays set to 30 and date not there.' + ]; + + yield [ + [ + 'ActivationBeforeDate' => '2021-07-16T23:59:59+01:00' + ], + (new ActivationBeforeBuilder()) + ->withActivationBeforeDate(new DateTimeImmutable('2021-07-16T23:59:59+01:00')) + ->build() + , + 'Creates an activation before object with ActivationBeforeDate set to july 16th 2021 and no activation before days.' + ]; + + yield [ + null, + null, + 'No activation before data returns null' + ]; + } +} \ No newline at end of file diff --git a/tests/Mapper/ArrayToAdditionalLicenseOptionsMapperTest.php b/tests/Mapper/ArrayToAdditionalLicenseOptionsMapperTest.php new file mode 100644 index 0000000..818179a --- /dev/null +++ b/tests/Mapper/ArrayToAdditionalLicenseOptionsMapperTest.php @@ -0,0 +1,52 @@ + ['Inkijkexemplaar', 'Demo-exemplaar'] + ], + (new AdditionalLicenseOptionsBuilder()) + ->withAdditionalLicenseOption(['Inkijkexemplaar', 'Demo-exemplaar']) + ->build() + , + 'Creates an additional license options object with multiple additional license options' + ]; + + yield [ + [ + 'AdditionalLicenseOption' => 'Inkijkexemplaar' + ], + (new AdditionalLicenseOptionsBuilder()) + ->withAdditionalLicenseOption(['Inkijkexemplaar']) + ->build() + , + 'Creates an additional license options object with a single additional license option' + ]; + + yield [ + null, + null, + 'No additional license options should return null' + ]; + } +} \ No newline at end of file diff --git a/tests/Mapper/ArrayToEckRecordMapperTest.php b/tests/Mapper/ArrayToEckRecordMapperTest.php index fe01d46..10ff41d 100644 --- a/tests/Mapper/ArrayToEckRecordMapperTest.php +++ b/tests/Mapper/ArrayToEckRecordMapperTest.php @@ -6,7 +6,10 @@ use DateTimeImmutable; use Kennisnet\ECK\Mapper\ArrayToEckRecordMapper; use Kennisnet\ECK\EckRecord; +use Kennisnet\ECK\Model\AdditionalLicenseOptions; use Kennisnet\ECK\ResponseSerializer; +use Kennisnet\ECK\Tests\builder\ActivationBeforeBuilder; +use Kennisnet\ECK\Tests\builder\AdditionalLicenseOptionsBuilder; use Kennisnet\ECK\Tests\builder\EckRecordBuilder; use Kennisnet\ECK\Tests\builder\EnvironmentsBuilder; use Kennisnet\ECK\Tests\builder\PriceBuilder; @@ -52,11 +55,23 @@ private function expectedResult(): EckRecord ->withLevels(['PO']) ->withYears(['jaar 3']) ->withSaleUnitSize(1) - ->withPrices((new PricesBuilder())->withCurrency('EUR')->withPrice([ - (new PriceBuilder())->withVat(9)->withAmount(913)->build() - ])->build()) + ->withPrices((new PricesBuilder()) + ->withCurrency('EUR') + ->withPrice([(new PriceBuilder()) + ->withVat(9) + ->withAmount(913) + ->build() + ]) + ->build()) ->withIsLicensed(false) + ->withActivationBefore((new ActivationBeforeBuilder()) + ->withActivationBeforeDays(30) + ->withActivationBeforeDate(new DateTimeImmutable('2021-07-16T23:59:59+01:00')) + ->build()) ->withIsCatalogItem(true) + ->withAdditionalLicenseOptions((new AdditionalLicenseOptionsBuilder()) + ->withAdditionalLicenseOption(['Inkijkexemplaar', 'Demo-exemplaar']) + ->build()) ->withCopyright('yes') ->withLastModifiedDate(new DateTimeImmutable('2020-01-02T21:14:42+01:00')) ->build(); diff --git a/tests/Mapper/ArrayToEnvironmentsMapperTest.php b/tests/Mapper/ArrayToEnvironmentsMapperTest.php index 6d13b99..9707cc8 100644 --- a/tests/Mapper/ArrayToEnvironmentsMapperTest.php +++ b/tests/Mapper/ArrayToEnvironmentsMapperTest.php @@ -61,6 +61,4 @@ public function environmentsArrayDataProvider(): \Generator 'No environments data returns null.' ]; } - - } \ No newline at end of file diff --git a/tests/builder/ActivationBeforeBuilder.php b/tests/builder/ActivationBeforeBuilder.php new file mode 100644 index 0000000..588e441 --- /dev/null +++ b/tests/builder/ActivationBeforeBuilder.php @@ -0,0 +1,36 @@ +activationBefore = $activationBefore ?? new ActivationBefore(); + } + + public function build(): ActivationBefore + { + return $this->activationBefore; + } + + public function withActivationBeforeDays(int $activationBeforeDays): self + { + $builder = clone $this; + $builder->activationBefore->setActivationBeforeDays($activationBeforeDays); + return $builder; + } + + public function withActivationBeforeDate(\DateTimeImmutable $activationBeforeDate): self + { + $builder = clone $this; + $builder->activationBefore->setActivationBeforeDate($activationBeforeDate); + return $builder; + } +} \ No newline at end of file diff --git a/tests/builder/AdditionalLicenseOptionsBuilder.php b/tests/builder/AdditionalLicenseOptionsBuilder.php new file mode 100644 index 0000000..806a442 --- /dev/null +++ b/tests/builder/AdditionalLicenseOptionsBuilder.php @@ -0,0 +1,29 @@ +additionalLicenseOptions = $additionalLicenseOptions ?? new AdditionalLicenseOptions(); + } + + public function build(): AdditionalLicenseOptions + { + return $this->additionalLicenseOptions; + } + + public function withAdditionalLicenseOption(array $additionalLicenseOption): self + { + $builder = clone $this; + $builder->additionalLicenseOptions->setAdditionalLicenseOption($additionalLicenseOption); + return $builder; + } +} \ No newline at end of file diff --git a/tests/builder/EckRecordBuilder.php b/tests/builder/EckRecordBuilder.php index b265c01..36e2b51 100644 --- a/tests/builder/EckRecordBuilder.php +++ b/tests/builder/EckRecordBuilder.php @@ -5,6 +5,8 @@ use DateTimeImmutable; use Kennisnet\ECK\EckRecord; +use Kennisnet\ECK\Model\ActivationBefore; +use Kennisnet\ECK\Model\AdditionalLicenseOptions; use Kennisnet\ECK\Model\Environments; use Kennisnet\ECK\Model\Prices; @@ -292,6 +294,13 @@ public function withIsLicensed(bool $isLicensed): self return $builder; } + public function withActivationBefore(ActivationBefore $activationBefore): self + { + $builder = clone $this; + $builder->record->setActivationBefore($activationBefore); + return $builder; + } + public function withLicenseAvailabilityOptions(array $licenseAvailabilityOptions): self { $builder = clone $this; @@ -327,6 +336,13 @@ public function withLicenseCount(int $licenseCount): self return $builder; } + public function withAdditionalLicenseOptions(AdditionalLicenseOptions $additionalLicenseOptions): self + { + $builder = clone $this; + $builder->record->setAdditionalLicenseOptions($additionalLicenseOptions); + return $builder; + } + public function withIsCatalogItem(bool $isCatalogItem): self { $builder = clone $this; diff --git a/tests/builder/EnvironmentsBuilder.php b/tests/builder/EnvironmentsBuilder.php index c49f09f..d1e2fd4 100644 --- a/tests/builder/EnvironmentsBuilder.php +++ b/tests/builder/EnvironmentsBuilder.php @@ -40,5 +40,4 @@ public function withBrowser(array $browser): self $builder->environments->setBrowser($browser); return $builder; } - } \ No newline at end of file diff --git a/tests/data/eckResponse.xml b/tests/data/eckResponse.xml index f904908..662fc72 100644 --- a/tests/data/eckResponse.xml +++ b/tests/data/eckResponse.xml @@ -67,7 +67,15 @@ false false + + 30 + 2021-07-16T23:59:59+01:00 + true + + Inkijkexemplaar + Demo-exemplaar + yes 2020-01-02T21:14:42+01:00 From f883a2bab2a3ddd3f185d36fc173406fe560c803 Mon Sep 17 00:00:00 2001 From: Emily Borgers Date: Mon, 22 Mar 2021 19:00:28 +0100 Subject: [PATCH 4/7] CATWEB-37: Allowed additional license options to be null --- src/Mapper/ArrayToEckRecordMapper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mapper/ArrayToEckRecordMapper.php b/src/Mapper/ArrayToEckRecordMapper.php index 276ef47..698c90f 100644 --- a/src/Mapper/ArrayToEckRecordMapper.php +++ b/src/Mapper/ArrayToEckRecordMapper.php @@ -54,7 +54,7 @@ public static function mapArrayToEckRecord(array $recordArray): EckRecord $eckRecord->setLicenseEndDate(StringToDateMapper::mapStringToDate($recordArray['LicenseEndDate'] ?? null)); $eckRecord->setLicenseDuration($recordArray['LicenseDuration'] ?? null); $eckRecord->setLicenseCount(StringToIntMapper::mapStringToInt($recordArray['LicenseCount'] ?? null)); - $eckRecord->setAdditionalLicenseOptions(ArrayToAdditionalLicenseOptionsMapper::mapArrayToAdditionalLicenseOptions($recordArray['AdditionalLicenseOptions'])); + $eckRecord->setAdditionalLicenseOptions(ArrayToAdditionalLicenseOptionsMapper::mapArrayToAdditionalLicenseOptions($recordArray['AdditionalLicenseOptions'] ?? null)); $eckRecord->setIsCatalogItem(StringToBoolMapper::mapStringToBool($recordArray['IsCatalogItem'] ?? null)); $eckRecord->setCopyright($recordArray['Copyright'] ?? null); return $eckRecord; From 218f5da223eed44655ed8381182e1d62773b896e Mon Sep 17 00:00:00 2001 From: Emily Borgers Date: Tue, 23 Mar 2021 15:59:03 +0100 Subject: [PATCH 5/7] Added trailing new lines where missing. --- src/Mapper/ArrayToAdditionalLicenseOptionsMapper.php | 3 +-- src/Mapper/ArrayToEnvironmentsMapper.php | 2 +- src/Model/ActivationBefore.php | 2 +- src/Model/AdditionalLicenseOptions.php | 2 +- tests/Mapper/ArrayToActivationBeforeMapperTest.php | 2 +- tests/Mapper/ArrayToAdditionalLicenseOptionsMapperTest.php | 2 +- tests/Mapper/ArrayToEnvironmentsMapperTest.php | 2 +- tests/builder/ActivationBeforeBuilder.php | 2 +- tests/builder/AdditionalLicenseOptionsBuilder.php | 2 +- tests/builder/EnvironmentsBuilder.php | 2 +- 10 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/Mapper/ArrayToAdditionalLicenseOptionsMapper.php b/src/Mapper/ArrayToAdditionalLicenseOptionsMapper.php index ad453b3..2d5f9ec 100644 --- a/src/Mapper/ArrayToAdditionalLicenseOptionsMapper.php +++ b/src/Mapper/ArrayToAdditionalLicenseOptionsMapper.php @@ -18,5 +18,4 @@ public static function mapArrayToAdditionalLicenseOptions(?array $additionalLice return $additionalLicenseOptions; } - -} \ No newline at end of file +} diff --git a/src/Mapper/ArrayToEnvironmentsMapper.php b/src/Mapper/ArrayToEnvironmentsMapper.php index a457cb0..16fd17b 100644 --- a/src/Mapper/ArrayToEnvironmentsMapper.php +++ b/src/Mapper/ArrayToEnvironmentsMapper.php @@ -19,4 +19,4 @@ public static function mapArrayToEnvironments(?array $environmentsArray): ?Envir $environments->setBrowser(ArrayToStringArrayMapper::mapValueToStringArray($environmentsArray['Browser'] ?? null)); return $environments; } -} \ No newline at end of file +} diff --git a/src/Model/ActivationBefore.php b/src/Model/ActivationBefore.php index 083854b..fea323b 100644 --- a/src/Model/ActivationBefore.php +++ b/src/Model/ActivationBefore.php @@ -44,4 +44,4 @@ public function setActivationBeforeDate(?DateTimeImmutable $activationBeforeDate { $this->activationBeforeDate = $activationBeforeDate; } -} \ No newline at end of file +} diff --git a/src/Model/AdditionalLicenseOptions.php b/src/Model/AdditionalLicenseOptions.php index c2f220d..c34ebb5 100644 --- a/src/Model/AdditionalLicenseOptions.php +++ b/src/Model/AdditionalLicenseOptions.php @@ -23,4 +23,4 @@ public function setAdditionalLicenseOption(array $additionalLicenseOption): void { $this->additionalLicenseOption = $additionalLicenseOption; } -} \ No newline at end of file +} diff --git a/tests/Mapper/ArrayToActivationBeforeMapperTest.php b/tests/Mapper/ArrayToActivationBeforeMapperTest.php index 99fc6e0..b2c5ecb 100644 --- a/tests/Mapper/ArrayToActivationBeforeMapperTest.php +++ b/tests/Mapper/ArrayToActivationBeforeMapperTest.php @@ -52,4 +52,4 @@ public function activationBeforeDataProvider(): \Generator 'No activation before data returns null' ]; } -} \ No newline at end of file +} diff --git a/tests/Mapper/ArrayToAdditionalLicenseOptionsMapperTest.php b/tests/Mapper/ArrayToAdditionalLicenseOptionsMapperTest.php index 818179a..863b320 100644 --- a/tests/Mapper/ArrayToAdditionalLicenseOptionsMapperTest.php +++ b/tests/Mapper/ArrayToAdditionalLicenseOptionsMapperTest.php @@ -49,4 +49,4 @@ public function additionalLicenseOptionsArrayDataProvider(): \Generator 'No additional license options should return null' ]; } -} \ No newline at end of file +} diff --git a/tests/Mapper/ArrayToEnvironmentsMapperTest.php b/tests/Mapper/ArrayToEnvironmentsMapperTest.php index 9707cc8..1be466c 100644 --- a/tests/Mapper/ArrayToEnvironmentsMapperTest.php +++ b/tests/Mapper/ArrayToEnvironmentsMapperTest.php @@ -61,4 +61,4 @@ public function environmentsArrayDataProvider(): \Generator 'No environments data returns null.' ]; } -} \ No newline at end of file +} diff --git a/tests/builder/ActivationBeforeBuilder.php b/tests/builder/ActivationBeforeBuilder.php index 588e441..fe3572f 100644 --- a/tests/builder/ActivationBeforeBuilder.php +++ b/tests/builder/ActivationBeforeBuilder.php @@ -33,4 +33,4 @@ public function withActivationBeforeDate(\DateTimeImmutable $activationBeforeDat $builder->activationBefore->setActivationBeforeDate($activationBeforeDate); return $builder; } -} \ No newline at end of file +} diff --git a/tests/builder/AdditionalLicenseOptionsBuilder.php b/tests/builder/AdditionalLicenseOptionsBuilder.php index 806a442..04d5491 100644 --- a/tests/builder/AdditionalLicenseOptionsBuilder.php +++ b/tests/builder/AdditionalLicenseOptionsBuilder.php @@ -26,4 +26,4 @@ public function withAdditionalLicenseOption(array $additionalLicenseOption): sel $builder->additionalLicenseOptions->setAdditionalLicenseOption($additionalLicenseOption); return $builder; } -} \ No newline at end of file +} diff --git a/tests/builder/EnvironmentsBuilder.php b/tests/builder/EnvironmentsBuilder.php index d1e2fd4..a5e9f86 100644 --- a/tests/builder/EnvironmentsBuilder.php +++ b/tests/builder/EnvironmentsBuilder.php @@ -40,4 +40,4 @@ public function withBrowser(array $browser): self $builder->environments->setBrowser($browser); return $builder; } -} \ No newline at end of file +} From c07cf3a1f9da041eaefee1fa6c658dfbc83ffe00 Mon Sep 17 00:00:00 2001 From: Emily Borgers Date: Wed, 24 Mar 2021 10:19:29 +0100 Subject: [PATCH 6/7] Changed AdditionalLicenseOptions mapper to use MapArrayToStringArray instead of MapValueToStringArray as that is possible and cleaner (at least, debatable, but its in line with others) --- src/Mapper/ArrayToAdditionalLicenseOptionsMapper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mapper/ArrayToAdditionalLicenseOptionsMapper.php b/src/Mapper/ArrayToAdditionalLicenseOptionsMapper.php index 2d5f9ec..d28138f 100644 --- a/src/Mapper/ArrayToAdditionalLicenseOptionsMapper.php +++ b/src/Mapper/ArrayToAdditionalLicenseOptionsMapper.php @@ -14,7 +14,7 @@ public static function mapArrayToAdditionalLicenseOptions(?array $additionalLice } $additionalLicenseOptions = new AdditionalLicenseOptions(); - $additionalLicenseOptions->setAdditionalLicenseOption(ArrayToStringArrayMapper::mapValueToStringArray($additionalLicenseOptionsArray['AdditionalLicenseOption'] ?? null)); + $additionalLicenseOptions->setAdditionalLicenseOption(ArrayToStringArrayMapper::mapArrayToStringArray($additionalLicenseOptionsArray ?? [])); return $additionalLicenseOptions; } From 573376b1722e814fbe6b5059314c41159013fc24 Mon Sep 17 00:00:00 2001 From: Emily Borgers Date: Wed, 24 Mar 2021 10:49:19 +0100 Subject: [PATCH 7/7] Fixed new line in ArrayToActivationBeforeMapper.php --- src/Mapper/ArrayToActivationBeforeMapper.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Mapper/ArrayToActivationBeforeMapper.php b/src/Mapper/ArrayToActivationBeforeMapper.php index d0e5ec4..0d89521 100644 --- a/src/Mapper/ArrayToActivationBeforeMapper.php +++ b/src/Mapper/ArrayToActivationBeforeMapper.php @@ -20,5 +20,4 @@ public static function mapArrayToActivationBefore(?array $activationBeforeArray) return $activationBefore; } - -} \ No newline at end of file +}