From c932d77ae5a667de6fc4fdb2e77d77a3c3c01bc6 Mon Sep 17 00:00:00 2001 From: Jens Schulze Date: Tue, 30 Aug 2022 13:22:33 +0200 Subject: [PATCH 1/5] update dependencies add message collection test --- .github/workflows/ci.yml | 4 +-- composer.json | 2 +- psalm-baseline.xml | 18 +++++++++++ psalm.xml | 5 ++- test/unit/MessagesTest.php | 21 +++++++++++++ test/unit/messages.json | 62 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 108 insertions(+), 4 deletions(-) create mode 100644 psalm-baseline.xml create mode 100644 test/unit/MessagesTest.php create mode 100644 test/unit/messages.json diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 42c58d528ab..8d715168935 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,7 +20,7 @@ jobs: strategy: matrix: php-version: - - "7.4" + - "8.1" dependencies: - highest @@ -57,7 +57,7 @@ jobs: strategy: matrix: php-version: - - "7.4" + - "8.1" dependencies: - highest diff --git a/composer.json b/composer.json index 26f28710715..e24b875d416 100644 --- a/composer.json +++ b/composer.json @@ -67,7 +67,7 @@ "symfony/cache": "^3.0 || ^4.0 || ^5.0 || ^6.0" }, "require-dev": { - "vimeo/psalm": "^3.10", + "vimeo/psalm": "^4.26", "monolog/monolog": "^1.3", "phpunit/phpunit": "^9.0 | 8.5.22", "cache/array-adapter": "^1.0", diff --git a/psalm-baseline.xml b/psalm-baseline.xml new file mode 100644 index 00000000000..cfb9e7667f8 --- /dev/null +++ b/psalm-baseline.xml @@ -0,0 +1,18 @@ + + + + + (object)$data + + + + + $headers + + + + + FilesystemCache + + + diff --git a/psalm.xml b/psalm.xml index 76587c69933..54cd5f9b610 100644 --- a/psalm.xml +++ b/psalm.xml @@ -1,16 +1,19 @@ + + + diff --git a/test/unit/MessagesTest.php b/test/unit/MessagesTest.php new file mode 100644 index 00000000000..44aeb5841c1 --- /dev/null +++ b/test/unit/MessagesTest.php @@ -0,0 +1,21 @@ +getResults()->current(); + $messageType = $message->getType(); + $this->assertNotNull($messageType); + $this->assertSame("CategoryCreated", $messageType); + } +} diff --git a/test/unit/messages.json b/test/unit/messages.json new file mode 100644 index 00000000000..2c4db6efceb --- /dev/null +++ b/test/unit/messages.json @@ -0,0 +1,62 @@ +{ + "limit": 20, + "offset": 0, + "count": 1, + "total": 1, + "results": [ + { + "id": "d33a637f-7f93-410f-9c8c-b84e7fb71ef9", + "version": 1, + "versionModifiedAt": "2022-08-24T12:10:46.504Z", + "sequenceNumber": 1, + "resource": { + "typeId": "category", + "id": "44adba4b-6b67-4764-9177-49bf92bcb7e6" + }, + "resourceVersion": 1, + "resourceUserProvidedIdentifiers": { + "key": "ValidateMemoryLogging-M4BUENEOYX", + "slug": { + "en": "Slug822022833" + } + }, + "type": "CategoryCreated", + "category": { + "id": "44adba4b-6b67-4764-9177-49bf92bcb7e6", + "version": 1, + "versionModifiedAt": "2022-08-24T12:10:46.504Z", + "lastMessageSequenceNumber": 1, + "createdAt": "2022-08-24T12:10:46.504Z", + "lastModifiedAt": "2022-08-24T12:10:46.504Z", + "lastModifiedBy": { + "clientId": "h-QvaF3NpsjPBWeXa6TUOnq0", + "isPlatformClient": false + }, + "createdBy": { + "clientId": "h-QvaF3NpsjPBWeXa6TUOnq0", + "isPlatformClient": false + }, + "key": "ValidateMemoryLogging-M4BUENEOYX", + "name": { + "en": "Name822022833" + }, + "slug": { + "en": "Slug822022833" + }, + "ancestors": [], + "orderHint": "0.18452355685", + "assets": [] + }, + "createdAt": "2022-08-24T12:10:46.504Z", + "lastModifiedAt": "2022-08-24T12:10:46.504Z", + "lastModifiedBy": { + "clientId": "h-QvaF3NpsjPBWeXa6TUOnq0", + "isPlatformClient": false + }, + "createdBy": { + "clientId": "h-QvaF3NpsjPBWeXa6TUOnq0", + "isPlatformClient": false + } + } + ] +} From 1e65c11f5772b9b10c76e7149db3558098ff06fe Mon Sep 17 00:00:00 2001 From: Jens Schulze Date: Tue, 30 Aug 2022 13:24:38 +0200 Subject: [PATCH 2/5] no fail fast --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8d715168935..f3a2759848b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -92,6 +92,7 @@ jobs: runs-on: ubuntu-latest strategy: + fail-fast: false matrix: php-version: - "7.4" From c7693c38cc5aa9aad6704d553a3840c1bc10b183 Mon Sep 17 00:00:00 2001 From: Jens Schulze Date: Tue, 30 Aug 2022 14:20:46 +0200 Subject: [PATCH 3/5] fix ECS version --- composer.json | 2 +- ecs.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index e24b875d416..3f2b480b305 100644 --- a/composer.json +++ b/composer.json @@ -71,7 +71,7 @@ "monolog/monolog": "^1.3", "phpunit/phpunit": "^9.0 | 8.5.22", "cache/array-adapter": "^1.0", - "symplify/easy-coding-standard": "dev-main#3723f5bad743e7cdff8c933ed6b29a2a936e9fbb" + "symplify/easy-coding-standard": "11.1.5" }, "config": { "allow-plugins": { diff --git a/ecs.php b/ecs.php index 544ddef676d..d7ee9b2a285 100644 --- a/ecs.php +++ b/ecs.php @@ -4,7 +4,7 @@ ini_set("memory_limit", "-1"); use Commercetools\Tools\SummaryOnlyOutputFormatter; -use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; +use ECSPrefix202208\Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; use Symplify\EasyCodingStandard\ValueObject\Set\SetList; use Symplify\EasyCodingStandard\ValueObject\Option; From 191e697eb94053ed2f71969cd7e3ceea76f09bf1 Mon Sep 17 00:00:00 2001 From: Jens Schulze Date: Wed, 31 Aug 2022 09:14:48 +0200 Subject: [PATCH 4/5] fix messageModel for retrieving type value --- lib/commercetools-api/src/Models/Message/MessageModel.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/commercetools-api/src/Models/Message/MessageModel.php b/lib/commercetools-api/src/Models/Message/MessageModel.php index 1cf8834fc12..0b3ca3c89b1 100644 --- a/lib/commercetools-api/src/Models/Message/MessageModel.php +++ b/lib/commercetools-api/src/Models/Message/MessageModel.php @@ -210,7 +210,8 @@ public function __construct( ?int $sequenceNumber = null, ?Reference $resource = null, ?int $resourceVersion = null, - ?UserProvidedIdentifiers $resourceUserProvidedIdentifiers = null + ?UserProvidedIdentifiers $resourceUserProvidedIdentifiers = null, + ?string $type = null ) { $this->id = $id; $this->version = $version; @@ -222,7 +223,7 @@ public function __construct( $this->resource = $resource; $this->resourceVersion = $resourceVersion; $this->resourceUserProvidedIdentifiers = $resourceUserProvidedIdentifiers; - $this->type = static::DISCRIMINATOR_VALUE; + $this->type = $type; } /** From 620c7473c9c8eb066fed34b268f28a04d210e72f Mon Sep 17 00:00:00 2001 From: Jens Schulze Date: Wed, 31 Aug 2022 09:36:13 +0200 Subject: [PATCH 5/5] remove non existing classes from class resolvers --- .../src/Models/Message/OrderMessageModel.php | 27 +++++++++++++++++-- .../Message/OrderMessagePayloadModel.php | 5 +++- .../Payment/PaymentUpdateActionModel.php | 9 +++---- .../ProductTypeUpdateActionModel.php | 6 +++-- .../Project/ProjectUpdateActionModel.php | 6 +++-- .../src/Models/Type/TypeUpdateActionModel.php | 6 +++-- .../src/Base/JsonObjectModel.php | 6 ++--- test/unit/ProductProjectionsTest.php | 15 +++++++---- 8 files changed, 58 insertions(+), 22 deletions(-) diff --git a/lib/commercetools-api/src/Models/Message/OrderMessageModel.php b/lib/commercetools-api/src/Models/Message/OrderMessageModel.php index 1df69427b73..72e4bc312c0 100644 --- a/lib/commercetools-api/src/Models/Message/OrderMessageModel.php +++ b/lib/commercetools-api/src/Models/Message/OrderMessageModel.php @@ -27,56 +27,67 @@ final class OrderMessageModel extends JsonObjectModel implements OrderMessage { /** + * * @var ?string */ protected $id; /** + * * @var ?int */ protected $version; /** + * * @var ?DateTimeImmutable */ protected $createdAt; /** + * * @var ?DateTimeImmutable */ protected $lastModifiedAt; /** + * * @var ?LastModifiedBy */ protected $lastModifiedBy; /** + * * @var ?CreatedBy */ protected $createdBy; /** + * * @var ?int */ protected $sequenceNumber; /** + * * @var ?Reference */ protected $resource; /** + * * @var ?int */ protected $resourceVersion; /** + * * @var ?string */ protected $type; /** + * * @var ?UserProvidedIdentifiers */ protected $resourceUserProvidedIdentifiers; @@ -95,7 +106,8 @@ public function __construct( ?int $sequenceNumber = null, ?Reference $resource = null, ?int $resourceVersion = null, - ?UserProvidedIdentifiers $resourceUserProvidedIdentifiers = null + ?UserProvidedIdentifiers $resourceUserProvidedIdentifiers = null, + ?string $type = null ) { $this->id = $id; $this->version = $version; @@ -107,12 +119,13 @@ public function __construct( $this->resource = $resource; $this->resourceVersion = $resourceVersion; $this->resourceUserProvidedIdentifiers = $resourceUserProvidedIdentifiers; - $this->type = static::DISCRIMINATOR_VALUE; + $this->type = $type; } /** *

Unique identifier of the Message.

* + * * @return null|string */ public function getId() @@ -130,6 +143,7 @@ public function getId() } /** + * * @return null|int */ public function getVersion() @@ -147,6 +161,7 @@ public function getVersion() } /** + * * @return null|DateTimeImmutable */ public function getCreatedAt() @@ -168,6 +183,7 @@ public function getCreatedAt() } /** + * * @return null|DateTimeImmutable */ public function getLastModifiedAt() @@ -191,6 +207,7 @@ public function getLastModifiedAt() /** *

Present on resources created after 1 February 2019 except for events not tracked.

* + * * @return null|LastModifiedBy */ public function getLastModifiedBy() @@ -211,6 +228,7 @@ public function getLastModifiedBy() /** *

Present on resources created after 1 February 2019 except for events not tracked.

* + * * @return null|CreatedBy */ public function getCreatedBy() @@ -229,6 +247,7 @@ public function getCreatedBy() } /** + * * @return null|int */ public function getSequenceNumber() @@ -248,6 +267,7 @@ public function getSequenceNumber() /** *

A Reference represents a loose reference to another resource in the same Project identified by its id. The typeId indicates the type of the referenced resource. Each resource type has its corresponding Reference type, like ChannelReference. A referenced resource can be embedded through Reference Expansion. The expanded reference is the value of an additional obj field then.

* + * * @return null|Reference */ public function getResource() @@ -266,6 +286,7 @@ public function getResource() } /** + * * @return null|int */ public function getResourceVersion() @@ -283,6 +304,7 @@ public function getResourceVersion() } /** + * * @return null|string */ public function getType() @@ -300,6 +322,7 @@ public function getType() } /** + * * @return null|UserProvidedIdentifiers */ public function getResourceUserProvidedIdentifiers() diff --git a/lib/commercetools-api/src/Models/Message/OrderMessagePayloadModel.php b/lib/commercetools-api/src/Models/Message/OrderMessagePayloadModel.php index 22768636a42..14bf5d21e25 100644 --- a/lib/commercetools-api/src/Models/Message/OrderMessagePayloadModel.php +++ b/lib/commercetools-api/src/Models/Message/OrderMessagePayloadModel.php @@ -20,6 +20,7 @@ final class OrderMessagePayloadModel extends JsonObjectModel implements OrderMessagePayload { /** + * * @var ?string */ protected $type; @@ -29,11 +30,13 @@ final class OrderMessagePayloadModel extends JsonObjectModel implements OrderMes * @psalm-suppress MissingParamType */ public function __construct( + ?string $type = null ) { - $this->type = static::DISCRIMINATOR_VALUE; + $this->type = $type; } /** + * * @return null|string */ public function getType() diff --git a/lib/commercetools-api/src/Models/Payment/PaymentUpdateActionModel.php b/lib/commercetools-api/src/Models/Payment/PaymentUpdateActionModel.php index 77100a7f7d8..bf750d11c01 100644 --- a/lib/commercetools-api/src/Models/Payment/PaymentUpdateActionModel.php +++ b/lib/commercetools-api/src/Models/Payment/PaymentUpdateActionModel.php @@ -21,6 +21,7 @@ final class PaymentUpdateActionModel extends JsonObjectModel implements PaymentU { public const DISCRIMINATOR_VALUE = ''; /** + * * @var ?string */ protected $action; @@ -36,14 +37,10 @@ final class PaymentUpdateActionModel extends JsonObjectModel implements PaymentU 'changeTransactionInteractionId' => PaymentChangeTransactionInteractionIdActionModel::class, 'changeTransactionState' => PaymentChangeTransactionStateActionModel::class, 'changeTransactionTimestamp' => PaymentChangeTransactionTimestampActionModel::class, - 'setAmountPaid' => PaymentSetAmountPaidActionModel::class, - 'setAmountRefunded' => PaymentSetAmountRefundedActionModel::class, 'setAnonymousId' => PaymentSetAnonymousIdActionModel::class, - 'setAuthorization' => PaymentSetAuthorizationActionModel::class, 'setCustomField' => PaymentSetCustomFieldActionModel::class, 'setCustomType' => PaymentSetCustomTypeActionModel::class, 'setCustomer' => PaymentSetCustomerActionModel::class, - 'setExternalId' => PaymentSetExternalIdActionModel::class, 'setInterfaceId' => PaymentSetInterfaceIdActionModel::class, 'setKey' => PaymentSetKeyActionModel::class, 'setMethodInfoInterface' => PaymentSetMethodInfoInterfaceActionModel::class, @@ -60,11 +57,13 @@ final class PaymentUpdateActionModel extends JsonObjectModel implements PaymentU * @psalm-suppress MissingParamType */ public function __construct( + ?string $action = null ) { - $this->action = static::DISCRIMINATOR_VALUE; + $this->action = $action; } /** + * * @return null|string */ public function getAction() diff --git a/lib/commercetools-api/src/Models/ProductType/ProductTypeUpdateActionModel.php b/lib/commercetools-api/src/Models/ProductType/ProductTypeUpdateActionModel.php index cba571c73fe..3419437f469 100644 --- a/lib/commercetools-api/src/Models/ProductType/ProductTypeUpdateActionModel.php +++ b/lib/commercetools-api/src/Models/ProductType/ProductTypeUpdateActionModel.php @@ -21,6 +21,7 @@ final class ProductTypeUpdateActionModel extends JsonObjectModel implements Prod { public const DISCRIMINATOR_VALUE = ''; /** + * * @var ?string */ protected $action; @@ -35,7 +36,6 @@ final class ProductTypeUpdateActionModel extends JsonObjectModel implements Prod 'addPlainEnumValue' => ProductTypeAddPlainEnumValueActionModel::class, 'changeAttributeConstraint' => ProductTypeChangeAttributeConstraintActionModel::class, 'changeAttributeName' => ProductTypeChangeAttributeNameActionModel::class, - 'changeAttributeOrder' => ProductTypeChangeAttributeOrderActionModel::class, 'changeAttributeOrderByName' => ProductTypeChangeAttributeOrderByNameActionModel::class, 'changeDescription' => ProductTypeChangeDescriptionActionModel::class, 'changeEnumKey' => ProductTypeChangeEnumKeyActionModel::class, @@ -57,11 +57,13 @@ final class ProductTypeUpdateActionModel extends JsonObjectModel implements Prod * @psalm-suppress MissingParamType */ public function __construct( + ?string $action = null ) { - $this->action = static::DISCRIMINATOR_VALUE; + $this->action = $action; } /** + * * @return null|string */ public function getAction() diff --git a/lib/commercetools-api/src/Models/Project/ProjectUpdateActionModel.php b/lib/commercetools-api/src/Models/Project/ProjectUpdateActionModel.php index 46686e07dcf..a133e9ac03a 100644 --- a/lib/commercetools-api/src/Models/Project/ProjectUpdateActionModel.php +++ b/lib/commercetools-api/src/Models/Project/ProjectUpdateActionModel.php @@ -21,6 +21,7 @@ final class ProjectUpdateActionModel extends JsonObjectModel implements ProjectU { public const DISCRIMINATOR_VALUE = ''; /** + * * @var ?string */ protected $action; @@ -36,7 +37,6 @@ final class ProjectUpdateActionModel extends JsonObjectModel implements ProjectU 'changeCurrencies' => ProjectChangeCurrenciesActionModel::class, 'changeLanguages' => ProjectChangeLanguagesActionModel::class, 'changeMessagesConfiguration' => ProjectChangeMessagesConfigurationActionModel::class, - 'changeMessagesEnabled' => ProjectChangeMessagesEnabledActionModel::class, 'changeName' => ProjectChangeNameActionModel::class, 'changeOrderSearchStatus' => ProjectChangeOrderSearchStatusActionModel::class, 'changeProductSearchIndexingEnabled' => ProjectChangeProductSearchIndexingEnabledActionModel::class, @@ -49,11 +49,13 @@ final class ProjectUpdateActionModel extends JsonObjectModel implements ProjectU * @psalm-suppress MissingParamType */ public function __construct( + ?string $action = null ) { - $this->action = static::DISCRIMINATOR_VALUE; + $this->action = $action; } /** + * * @return null|string */ public function getAction() diff --git a/lib/commercetools-api/src/Models/Type/TypeUpdateActionModel.php b/lib/commercetools-api/src/Models/Type/TypeUpdateActionModel.php index 11e831915ed..b1224b9a1ea 100644 --- a/lib/commercetools-api/src/Models/Type/TypeUpdateActionModel.php +++ b/lib/commercetools-api/src/Models/Type/TypeUpdateActionModel.php @@ -21,6 +21,7 @@ final class TypeUpdateActionModel extends JsonObjectModel implements TypeUpdateA { public const DISCRIMINATOR_VALUE = ''; /** + * * @var ?string */ protected $action; @@ -35,7 +36,6 @@ final class TypeUpdateActionModel extends JsonObjectModel implements TypeUpdateA 'addLocalizedEnumValue' => TypeAddLocalizedEnumValueActionModel::class, 'changeEnumValueLabel' => TypeChangeEnumValueLabelActionModel::class, 'changeEnumValueOrder' => TypeChangeEnumValueOrderActionModel::class, - 'changeFieldDefinitionLabel' => TypeChangeFieldDefinitionLabelActionModel::class, 'changeFieldDefinitionOrder' => TypeChangeFieldDefinitionOrderActionModel::class, 'changeInputHint' => TypeChangeInputHintActionModel::class, 'changeKey' => TypeChangeKeyActionModel::class, @@ -51,11 +51,13 @@ final class TypeUpdateActionModel extends JsonObjectModel implements TypeUpdateA * @psalm-suppress MissingParamType */ public function __construct( + ?string $action = null ) { - $this->action = static::DISCRIMINATOR_VALUE; + $this->action = $action; } /** + * * @return null|string */ public function getAction() diff --git a/lib/commercetools-base/src/Base/JsonObjectModel.php b/lib/commercetools-base/src/Base/JsonObjectModel.php index f0cb848be3d..35fb2fdfeee 100644 --- a/lib/commercetools-base/src/Base/JsonObjectModel.php +++ b/lib/commercetools-base/src/Base/JsonObjectModel.php @@ -48,12 +48,12 @@ function ($value) { /** * @return static|mixed */ - public function with(callable $callback = null) + public function with(callable $callable = null) { - if (is_null($callback)) { + if (is_null($callable)) { return $this; } - return $callback($this); + return $callable($this); } } diff --git a/test/unit/ProductProjectionsTest.php b/test/unit/ProductProjectionsTest.php index 2324548cad9..fcb606dcb07 100644 --- a/test/unit/ProductProjectionsTest.php +++ b/test/unit/ProductProjectionsTest.php @@ -30,11 +30,16 @@ public function testAttributeMapping() /** @var AttributeAccessor $attrAccessor */ $attrAccessor = $attribute->with(AttributeAccessor::of()); switch ($attrAccessor->getName()) { - case "someStringAttribute": $stringValue = $attrAccessor->getValueAsString(); break; - case "someEnumAttribute": $enumValue = $attrAccessor->getValueAsEnum(); break; - case "someBooleanAttribute": $boolValue = $attrAccessor->getValueAsBool(); break; - case "text1": self::assertSame("englisch1", $attrAccessor->getValueAsLocalizedString()->at("en")); break; - case "aboolean": self::assertTrue($attrAccessor->getValueAsBool()); break; + case "someStringAttribute": $stringValue = $attrAccessor->getValueAsString(); + break; + case "someEnumAttribute": $enumValue = $attrAccessor->getValueAsEnum(); + break; + case "someBooleanAttribute": $boolValue = $attrAccessor->getValueAsBool(); + break; + case "text1": self::assertSame("englisch1", $attrAccessor->getValueAsLocalizedString()->at("en")); + break; + case "aboolean": self::assertTrue($attrAccessor->getValueAsBool()); + break; } } }