Skip to content

Commit

Permalink
Added unit tests for translator services.
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentmuller committed Jun 15, 2024
1 parent c85484f commit e300aa0
Show file tree
Hide file tree
Showing 9 changed files with 834 additions and 36 deletions.
10 changes: 10 additions & 0 deletions src/Service/AbstractHttpClientService.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,16 @@ public function hasLastError(): bool
return $this->lastError instanceof HttpClientError;
}

/**
* Sets the client.
*/
public function setClient(?HttpClientInterface $client): static
{
$this->client = $client;

return $this;
}

/**
* Create the HTTP client.
*
Expand Down
36 changes: 18 additions & 18 deletions src/Service/CalculationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,24 @@ public function adjustUserMargin(array $parameters): array
return $parameters;
}

/**
* Gets the row constants.
*
* @return array<string, mixed>
*/
public static function constants(): array
{
$reflection = new \ReflectionClass(self::class);
$constants = $reflection->getReflectionConstants(\ReflectionClassConstant::IS_PUBLIC);

return \array_reduce(
$constants,
/** @psalm-param array<string, mixed> $carry */
static fn (array $carry, \ReflectionClassConstant $c): array => $carry + [$c->getName() => $c->getValue()],
[]
);
}

/**
* Creates groups from a calculation.
*
Expand Down Expand Up @@ -225,24 +243,6 @@ public function createGroupsFromData(array $source): array
];
}

/**
* Gets the row constants.
*
* @return array<string, mixed>
*/
public static function getConstants(): array
{
$reflection = new \ReflectionClass(self::class);
$constants = $reflection->getReflectionConstants(\ReflectionClassConstant::IS_PUBLIC);

return \array_reduce(
$constants,
/** @psalm-param array<string, mixed> $carry */
static fn (array $carry, \ReflectionClassConstant $c): array => $carry + [$c->getName() => $c->getValue()],
[]
);
}

/**
* Gets the minimum margin, in percent, for a calculation.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Twig/ConstantExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private function loadValues(): array
$this->getIcons(),
EntityName::constants(),
EntityPermission::constants(),
CalculationService::getConstants()
CalculationService::constants()
);
}
}
2 changes: 1 addition & 1 deletion tests/Service/CalculationServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public function testCreateGroupsFromDataEmpty(): void

public function testGetConstants(): void
{
$constants = CalculationService::getConstants();
$constants = CalculationService::constants();
self::assertCount(7, $constants);

self::assertArrayHasKey('ROW_EMPTY', $constants);
Expand Down
Loading

0 comments on commit e300aa0

Please sign in to comment.