Skip to content

Commit

Permalink
[CHORE] Code styles
Browse files Browse the repository at this point in the history
  • Loading branch information
cngJo committed Nov 7, 2023
1 parent 8e6e956 commit 489ee83
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 37 deletions.
1 change: 1 addition & 0 deletions ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
$ecsConfig->skip([
__DIR__ . "/tests/TestBootstrap.php",
__DIR__ . "/tests/TestBootstrapper.php",
__DIR__ . "/tests/Support/StorefrontControllerTestBehaviour.php",
]);

$ecsConfig->sets([
Expand Down
1 change: 1 addition & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ parameters:
excludePaths:
- tests/TestBootstrap.php
- tests/TestBootstrapper.php
- tests/Support/StorefrontControllerTestBehaviour.php
1 change: 1 addition & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
$rectorConfig->skip([
__DIR__ . "/tests/TestBootstrap.php",
__DIR__ . "/tests/TestBootstrapper.php",
__DIR__ . "/tests/Support/StorefrontControllerTestBehaviour.php",
]);

$rectorConfig->sets([
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Mamo/MetricsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private function validateHmacRequest(Request $request, string $secret): void
}

$body = $request->getContent();
if (! $body) {
if ($body === '' || $body === '0') {
$this->logger->info('Request body is missing.');
throw new HttpException(400);
}
Expand Down
18 changes: 9 additions & 9 deletions tests/Controller/MetricsControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class MetricsControllerTest extends TestCase
use IntegrationTestBehaviour;
use StorefrontControllerTestBehaviour;

private const TESTING_SECRET = "testing-secret";
private const TESTING_SECRET = 'testing-secret';

public function testMetricsAction(): void
{
Expand Down Expand Up @@ -55,9 +55,9 @@ public function testFailWithInvalidHmacHeader(): void
$systemConfigService->set(MobiMamoConnector::CONFIG_KEY_SECRET, self::TESTING_SECRET);

$metrics = $this->request('GET', 'mamo-connector/metrics', [
"header" => [
"Hmac" => "dummy"
]
'header' => [
'Hmac' => 'dummy',
],
]);
$content = $metrics->getContent();

Expand All @@ -75,7 +75,7 @@ public function testValidRequestWithHmac(): void
$content = '{"validateTime":' . mktime(0) . '}';

$metrics = $this->request('GET', 'mamo-connector/metrics', [], [], [
"HTTP_Hmac" => hash_hmac('sha256', '{"validateTime":' . mktime(0) . '}', self::TESTING_SECRET),
'HTTP_Hmac' => hash_hmac('sha256', '{"validateTime":' . mktime(0) . '}', self::TESTING_SECRET),
], $content);
$content = $metrics->getContent();

Expand All @@ -94,8 +94,8 @@ public function testHmacMissingBody(): void
$content = '{"validateTime":' . mktime(0) . '}';

$metrics = $this->request('GET', 'mamo-connector/metrics', [], [], [
"HTTP_Hmac" => hash_hmac('sha256', '{"validateTime":' . mktime(0) . '}', self::TESTING_SECRET),
], ""); // <- missing request body
'HTTP_Hmac' => hash_hmac('sha256', '{"validateTime":' . mktime(0) . '}', self::TESTING_SECRET),
], ''); // <- missing request body
$content = $metrics->getContent();

static::assertNotFalse($content);
Expand All @@ -112,8 +112,8 @@ public function testHmacMismatch(): void
$content = '{"validateTime":' . mktime(0) . '}';

$metrics = $this->request('GET', 'mamo-connector/metrics', [], [], [
"HTTP_Hmac" => hash_hmac('sha256', '{"validateTime":' . mktime(0) . '}', self::TESTING_SECRET),
], "hmac-mismatch"); // <- missing request body
'HTTP_Hmac' => hash_hmac('sha256', '{"validateTime":' . mktime(0) . '}', self::TESTING_SECRET),
], 'hmac-mismatch'); // <- missing request body
$content = $metrics->getContent();

static::assertNotFalse($content);
Expand Down
4 changes: 3 additions & 1 deletion tests/MobiMamoConnectorTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace MobilisticsGmbH\MamoConnector\Tests;

use MobilisticsGmbH\MamoConnector\MobiMamoConnector;
Expand All @@ -9,7 +11,7 @@ class MobiMamoConnectorTest extends TestCase
{
public function testExecuteComposerCommandsIsSet(): void
{
$plugin = new MobiMamoConnector(true, "");
$plugin = new MobiMamoConnector(true, '');
static::assertTrue($plugin->executeComposerCommands());
}
}
57 changes: 31 additions & 26 deletions tests/Service/ShopwareApiClientTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace MobilisticsGmbH\MamoConnector\Tests\Service;

use MobilisticsGmbH\MamoConnector\Service\ShopwareApiClient;
Expand All @@ -14,31 +16,6 @@ class ShopwareApiClientTest extends TestCase
{
use IntegrationTestBehaviour;

private function getInstanceService(): InstanceService
{
/** @var InstanceService $instanceService */
$instanceService = $this->getContainer()->get(InstanceService::class);

return $instanceService;
}

/**
* @param MockResponse[] $responses
* @return HttpClientInterface
*/
private function getMockedHttpClient(array $responses): HttpClientInterface
{
return new MockHttpClient($responses);
}

private function getMockApiClient(array $responses): ShopwareApiClient
{
return new ShopwareApiClient(
$this->getInstanceService(),
$this->getMockedHttpClient($responses),
);
}

public function testEmptryReponseBody(): void
{
$client = $this->getMockApiClient([
Expand All @@ -62,7 +39,8 @@ public function testEmptyResponseFromApi(): void
public function testPluginResponsesFromApi(): void
{
$responses = [
new MockResponse(<<<JSON
new MockResponse(
<<<JSON
{
"data": [
{
Expand Down Expand Up @@ -99,4 +77,31 @@ public function testPluginResponsesFromApi(): void
static::assertSame('MobiSecondPlugin', $result[1]->name);
static::assertSame('2.0.0', $result[1]->version);
}

private function getInstanceService(): InstanceService
{
/** @var InstanceService $instanceService */
$instanceService = $this->getContainer()->get(InstanceService::class);

return $instanceService;
}

/**
* @param MockResponse[] $responses
*/
private function getMockedHttpClient(array $responses): HttpClientInterface
{
return new MockHttpClient($responses);
}

/**
* @param MockResponse[] $responses
*/
private function getMockApiClient(array $responses): ShopwareApiClient
{
return new ShopwareApiClient(
$this->getInstanceService(),
$this->getMockedHttpClient($responses),
);
}
}

0 comments on commit 489ee83

Please sign in to comment.