Skip to content

Commit

Permalink
fixup! Add sorting command
Browse files Browse the repository at this point in the history
  • Loading branch information
OndraM committed Nov 24, 2017
1 parent 0c6e9e0 commit f203de6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 21 deletions.
24 changes: 11 additions & 13 deletions src/Model/Command/Sorting.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
namespace Lmc\Matej\Model\Command;

/**
* Sort given item ids for user-based recommendations
* Sorting items is a way how to use Matej to deliver personalized experience to users.
* It allows to sort given list of items according to the user preference.
*/
class Sorting extends AbstractCommand
{
Expand All @@ -12,15 +13,20 @@ class Sorting extends AbstractCommand
/** @var string[] */
private $itemIds = [];

/**
* Sort given item ids for user-based recommendations
*/
public function __construct(string $userId, array $itemIds)
private function __construct(string $userId, array $itemIds)
{
$this->userId = $userId;
$this->itemIds = $itemIds;
}

/**
* Sort given item ids for user-based recommendations.
*/
public static function create(string $userId, array $itemIds): self
{
return new static($userId, $itemIds);
}

public function getCommandType(): string
{
return 'sorting';
Expand All @@ -33,12 +39,4 @@ public function getCommandParameters(): array
'item_ids' => $this->itemIds,
];
}

/**
* Sort given item ids for user-based recommendations
*/
public static function create(string $userId, array $itemIds): self
{
return new static($userId, $itemIds);
}
}
11 changes: 3 additions & 8 deletions tests/Model/Command/SortingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,18 @@

namespace Lmc\Matej\Model\Command;

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

class SortingTest extends TestCase
{
/**
* @test
*/
public function shouldGenerateCorrectSignature(): void
/** @test */
public function shouldBeInstantiableViaNamedConstructor(): void
{
$userId = 'user-id';
$itemIds = ['item-1', 'item-3', 'item-2'];

$command = Sorting::create($userId, $itemIds);
$this->assertSortingObject($command, $userId, $itemIds);

$command = new Sorting($userId, $itemIds);
$this->assertSortingObject($command, $userId, $itemIds);
}

/**
Expand Down

0 comments on commit f203de6

Please sign in to comment.