Skip to content

Commit

Permalink
Merge branch 'master' into feature/integration-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
foglcz committed Dec 5, 2017
2 parents 53588a1 + a7618d7 commit 02ca722
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 12 deletions.
11 changes: 9 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,20 @@
<!-- There is always Unreleased section on the top. Subsections (Added, Changed, Fixed, Removed) should be added as needed. -->

## 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
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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"
},
Expand Down
2 changes: 1 addition & 1 deletion src/Http/HmacAuthentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/Matej.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 12 additions & 1 deletion src/Model/Command/ItemProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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';
Expand Down
5 changes: 5 additions & 0 deletions src/Model/Command/ItemPropertySetup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
14 changes: 13 additions & 1 deletion tests/unit/Model/Command/ItemPropertySetupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Lmc\Matej\Model\Command;

use Lmc\Matej\Exception\DomainException;
use PHPUnit\Framework\TestCase;

class ItemPropertySetupTest extends TestCase
Expand All @@ -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(
Expand All @@ -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[]
*/
Expand Down
15 changes: 11 additions & 4 deletions tests/unit/Model/Command/ItemPropertyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'],
],
];
}
}

0 comments on commit 02ca722

Please sign in to comment.