Skip to content

Commit

Permalink
Codefixes
Browse files Browse the repository at this point in the history
  • Loading branch information
JakubTesarek committed Dec 16, 2020
1 parent 7e7ebf3 commit 466ad3f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 18 deletions.
3 changes: 0 additions & 3 deletions src/Model/Command/AbstractRecommendation.php
Expand Up @@ -50,9 +50,6 @@ public function setCount(int $count): self
return $this;
}

/**
* Scenario name.
*/
protected function setScenario(string $scenario): void
{
Assertion::typeIdentifier($scenario);
Expand Down
2 changes: 1 addition & 1 deletion src/Model/Command/AbstractUserRecommendation.php
Expand Up @@ -91,7 +91,7 @@ protected function getCommandParameters(): array
$parameters['rotation_rate'] = $this->rotationRate;
}

if ($this->rotationRate !== null) {
if ($this->rotationTime !== null) {
$parameters['rotation_time'] = $this->rotationTime;
}

Expand Down
25 changes: 11 additions & 14 deletions tests/integration/RequestBuilder/EventsRequestBuilderTest.php
Expand Up @@ -15,14 +15,11 @@
*/
class EventsRequestBuilderTest extends IntegrationTestCase
{
private static function getPropertiesList(): array
{
return [
'test_property_a',
'test_property_b',
'test_property_c',
];
}
private const PROPERTIES_LIST = [
'test_property_a',
'test_property_b',
'test_property_c',
];

public static function setUpBeforeClass(): void
{
Expand All @@ -34,7 +31,7 @@ public static function setUpBeforeClass(): void
public static function tearDownAfterClass(): void
{
$matej = static::createMatejInstance();
static::removeItemProperties($matej);
static::resetItemProperties($matej);
}

/** @test */
Expand Down Expand Up @@ -78,7 +75,7 @@ public function shouldExecuteInteractionAndUserMergeAndItemPropertyCommands(): v
private static function setupItemProperties(Matej $matej): void
{
$request = $matej->request()->setupItemProperties();
foreach (static::getPropertiesList() as $property) {
foreach (static::PROPERTIES_LIST as $property) {
$request->addProperty(ItemPropertySetup::string($property));
}
$request->send();
Expand All @@ -95,17 +92,17 @@ private static function waitForItemPropertiesSetup(Matej $matej): void
$properties[] = $property->name;
}

if (!array_diff(static::getPropertiesList(), $properties)) {
if (!array_diff(static::PROPERTIES_LIST, $properties)) {
return;
}
usleep(1000000); # 0.1s
usleep(100000); # 0.1s
}
}

private static function removeItemProperties(Matej $matej): void
private static function resetItemProperties(Matej $matej): void
{
$request = $matej->request()->deleteItemProperties();
foreach (static::getPropertiesList() as $property) {
foreach (static::PROPERTIES_LIST as $property) {
$request->addProperty(ItemPropertySetup::string($property));
}
$request->send();
Expand Down
23 changes: 23 additions & 0 deletions tests/unit/Model/Command/UserItemRecommendationTest.php
Expand Up @@ -73,6 +73,29 @@ public function shouldUseCustomParameters(): void
);
}

/** @test */
public function shouldUseRotationTimeWithoutRotationRate(): void
{
$userId = 'user-' . md5(microtime());
$scenario = 'scenario-' . md5(microtime());
$rotationTime = random_int(1, 86400);

$command = UserItemRecommendation::create($userId, $scenario)
->setRotationTime($rotationTime);

$this->assertEquals(
[
'type' => 'user-item-recommendations',
'parameters' => [
'user_id' => $userId,
'scenario' => $scenario,
'rotation_time' => $rotationTime,
],
],
$command->jsonSerialize()
);
}

/** @test */
public function shouldAssembleMqlFilters(): void
{
Expand Down

0 comments on commit 466ad3f

Please sign in to comment.