diff --git a/CHANGELOG.md b/CHANGELOG.md index 40fc921..63f6a18 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,13 +5,20 @@ ## Unreleased + +## 1.0.0 - 2017-12-05 ### Added - Commands which include user now implements `UserAwareInterface` and `getUserId()` method (ie. Interaction, Sorting, UserMerge, UserRecommendation). +- Custom request ID could be passed to a request (via `setRequestId()` method of request builders). If none is set, random request ID is generated. +- Response ID could be read from the response via `getRequestId()` method of the Response object. ### Changed - Validate all commands of `recommendation()` and `sorting()` request involve the same user. -- Custom request ID could be passed to a request (via `setRequestId()` method of request builders). If none is set, random request ID is generated. -- Response ID could be read from the response via `getRequestId()` method of the Response object. +- Validate Item properties to not contain `$property['item_id']` as that would redefine the primary key in Matej database. +- Validate Item property setup to not set up property named `item_id` as that would conflict with the primary key in Matej database. + +### Fixed +- URL assembling was not working on systems with non-standard setting of `arg_separator.output` PHP directive. ## 0.10.0 - 2017-11-30 ### Changed diff --git a/composer.json b/composer.json index dba4d7b..2d3e632 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,7 @@ "php-http/discovery": "^1.0", "fig/http-message-util": "^1.1", "php-http/client-common": "^1.6", - "beberlei/assert": "^2.7", + "beberlei/assert": "^2.8", "ramsey/uuid": "^3.7" }, "require-dev": { @@ -40,7 +40,7 @@ "friendsofphp/php-cs-fixer": "^2.7", "phpstan/phpstan-shim": "^0.9.0", "phpstan/phpstan-phpunit": "^0.9.0", - "php-coveralls/php-coveralls": "^1.0", + "php-coveralls/php-coveralls": "^2.0@dev", "symfony/var-dumper": "^3.3 || ^4.0", "php-mock/php-mock-phpunit": "^1.0 || ^2.0" }, diff --git a/src/Http/HmacAuthentication.php b/src/Http/HmacAuthentication.php index de43312..1003693 100644 --- a/src/Http/HmacAuthentication.php +++ b/src/Http/HmacAuthentication.php @@ -53,7 +53,7 @@ private function createRequestWithParams(RequestInterface $request, array $param { $uri = $request->getUri(); - $query = http_build_query($params); + $query = http_build_query($params, '', '&'); $uri = $uri->withQuery($query); return $request->withUri($uri); diff --git a/src/Matej.php b/src/Matej.php index ee90838..a4f980e 100644 --- a/src/Matej.php +++ b/src/Matej.php @@ -11,7 +11,7 @@ class Matej { public const CLIENT_ID = 'php-client'; - public const VERSION = '0.10.0'; + public const VERSION = '1.0.0'; /** @var string */ private $accountId; diff --git a/src/Model/Command/ItemProperty.php b/src/Model/Command/ItemProperty.php index bdddcd7..71d1ea5 100644 --- a/src/Model/Command/ItemProperty.php +++ b/src/Model/Command/ItemProperty.php @@ -17,7 +17,7 @@ class ItemProperty extends AbstractCommand private function __construct(string $itemId, array $properties) { $this->setItemId($itemId); - $this->properties = $properties; + $this->setProperties($properties); } public static function create(string $itemId, array $properties = []): self @@ -32,6 +32,17 @@ protected function setItemId(string $itemId): void $this->itemId = $itemId; } + protected function setProperties(array $properties): void + { + Assertion::keyNotExists( + $properties, + 'item_id', + 'Cannot update value of "item_id" property - it is used by Matej to identify the item and cannot be altered once created.' + ); + + $this->properties = $properties; + } + protected function getCommandType(): string { return 'item-properties'; diff --git a/src/Model/Command/ItemPropertySetup.php b/src/Model/Command/ItemPropertySetup.php index 293b871..b37a5a9 100644 --- a/src/Model/Command/ItemPropertySetup.php +++ b/src/Model/Command/ItemPropertySetup.php @@ -60,6 +60,11 @@ public static function set(string $propertyName): self protected function setPropertyName(string $propertyName): void { Assertion::typeIdentifier($propertyName); + Assertion::notEq( + $propertyName, + 'item_id', + 'Cannot manipulate with property "item_id" - it is used by Matej to identify items.' + ); $this->propertyName = $propertyName; } diff --git a/tests/unit/Model/Command/ItemPropertySetupTest.php b/tests/unit/Model/Command/ItemPropertySetupTest.php index ac0e226..fc26aea 100644 --- a/tests/unit/Model/Command/ItemPropertySetupTest.php +++ b/tests/unit/Model/Command/ItemPropertySetupTest.php @@ -2,6 +2,7 @@ namespace Lmc\Matej\Model\Command; +use Lmc\Matej\Exception\DomainException; use PHPUnit\Framework\TestCase; class ItemPropertySetupTest extends TestCase @@ -17,7 +18,7 @@ public function shouldBeInstantiableViaNamedConstructors( $propertyName = 'examplePropertyName'; /** @var ItemPropertySetup $command */ - $command = forward_static_call([ItemPropertySetup::class, $constructorName], $propertyName); + $command = ItemPropertySetup::$constructorName($propertyName); $this->assertInstanceOf(ItemPropertySetup::class, $command); $this->assertSame( @@ -32,6 +33,17 @@ public function shouldBeInstantiableViaNamedConstructors( ); } + /** + * @test + * @dataProvider provideConstructorName + */ + public function shouldNotAllowItemIdAsPropertyName(string $constructorName): void + { + $this->expectException(DomainException::class); + $this->expectExceptionMessage('Cannot manipulate with property "item_id" - it is used by Matej to identify items.'); + ItemPropertySetup::$constructorName('item_id'); + } + /** * @return array[] */ diff --git a/tests/unit/Model/Command/ItemPropertyTest.php b/tests/unit/Model/Command/ItemPropertyTest.php index fa217f5..529a760 100644 --- a/tests/unit/Model/Command/ItemPropertyTest.php +++ b/tests/unit/Model/Command/ItemPropertyTest.php @@ -2,10 +2,21 @@ namespace Lmc\Matej\Model\Command; +use Lmc\Matej\Exception\DomainException; use PHPUnit\Framework\TestCase; class ItemPropertyTest extends TestCase { + /** + * @test + */ + public function shouldNotAllowItemIdInProperties(): void + { + $this->expectException(DomainException::class); + $this->expectExceptionMessage('Cannot update value of "item_id" property - it is used by Matej to identify the item and cannot be altered once created.'); + ItemProperty::create('exampleItemId', ['item_id' => 'customItemId']); + } + /** * @test * @dataProvider provideProperties @@ -36,10 +47,6 @@ public function provideProperties(): array ['item1' => 'value1', 'item2' => 'value2'], ['item1' => 'value1', 'item2' => 'value2', 'item_id' => 'exampleItemId'], ], - 'Should not allow to override item_id' => [ - ['item_id' => 'customItemId'], - ['item_id' => 'exampleItemId'], - ], ]; } }