Skip to content

Commit

Permalink
Merge 840277a into 9666a62
Browse files Browse the repository at this point in the history
  • Loading branch information
OndraM authored Jan 15, 2024
2 parents 9666a62 + 840277a commit d759bb0
Show file tree
Hide file tree
Showing 27 changed files with 153 additions and 72 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/php.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-version: ['7.1', '7.2', '7.3', '7.4']
php-version: ['7.3', '7.4']
dependencies: ['']
include:
- { php-version: '7.1', dependencies: '--prefer-lowest' }
- { php-version: '7.3', dependencies: '--prefer-lowest' }
- { php-version: '8.0', dependencies: '--ignore-platform-req=php' }

name: PHP ${{ matrix.php-version }} ${{ matrix.dependencies }} (unit tests)
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
<!-- There is always Unreleased section on the top. Subsections (Added, Changed, Fixed, Removed) should be added as needed. -->

## Unreleased
### Changed
- Require PHP ^7.3

## 4.1.0 - 2021-08-19
### Added
Expand Down
21 changes: 11 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
}
],
"require": {
"php": "^7.1 || ^8.0",
"php": "^7.3 || ^8.0",
"ext-hash": "*",
"ext-json": "*",
"beberlei/assert": "^2.8 || ^3.0",
Expand All @@ -28,16 +28,17 @@
},
"require-dev": {
"ergebnis/composer-normalize": "^2.4",
"lmc/coding-standard": "^1.3 || ^2.0",
"http-interop/http-factory-guzzle": "^1.2",
"lmc/coding-standard": "^3.0.0",
"php-coveralls/php-coveralls": "^2.4",
"php-http/guzzle6-adapter": "^1.1.1 || ^2.0",
"php-http/mock-client": "^1.0",
"php-mock/php-mock-phpunit": "^2.1.2",
"php-parallel-lint/php-parallel-lint": "^1.1",
"phpstan/extension-installer": "^1.0.5",
"phpstan/phpstan": "^0.12.48",
"phpstan/phpstan-phpunit": "^0.12.16",
"phpunit/phpunit": "^7.5.20 || ^8.0 || ^9.0",
"phpstan/extension-installer": "^1.3",
"phpstan/phpstan": "^1.10",
"phpstan/phpstan-phpunit": "^1.3",
"phpunit/phpunit": "^9.0",
"symfony/var-dumper": "^3.3 || ^4.0 || ^5.0"
},
"minimum-stability": "stable",
Expand All @@ -54,9 +55,9 @@
},
"config": {
"allow-plugins": {
"composer/package-versions-deprecated": true,
"dealerdirect/phpcodesniffer-composer-installer": true,
"ergebnis/composer-normalize": true,
"php-http/discovery": true,
"phpstan/extension-installer": true
},
"sort-packages": true
Expand All @@ -68,15 +69,15 @@
"@test"
],
"analyze": [
"vendor/bin/ecs check src/ tests/ --ansi",
"vendor/bin/ecs check src/ tests/ ecs.php --ansi",
"vendor/bin/phpstan analyze -c phpstan.neon --ansi"
],
"fix": [
"@composer normalize",
"./vendor/bin/ecs check ./src/ ./tests/ --ansi --fix"
"./vendor/bin/ecs check ./src/ ./tests/ ecs.php --ansi --fix"
],
"lint": [
"vendor/bin/parallel-lint -j 10 ./src ./tests",
"vendor/bin/parallel-lint -j 10 ./src ./tests ecs.php",
"@composer validate",
"@composer normalize --dry-run"
],
Expand Down
12 changes: 0 additions & 12 deletions easy-coding-standard.yaml

This file was deleted.

32 changes: 32 additions & 0 deletions ecs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php declare(strict_types=1);

use Lmc\CodingStandard\Sniffs\Naming\ClassNameSuffixByParentSniff;
use PhpCsFixer\Fixer\PhpUnit\PhpUnitTestAnnotationFixer;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\CodingStandard\Fixer\LineLength\LineLengthFixer;
use Symplify\EasyCodingStandard\ValueObject\Option;

return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(
Option::SKIP,
[
ClassNameSuffixByParentSniff::class => ['src/Model/Command/*.php'],
]
);

$containerConfigurator->import(__DIR__ . '/vendor/lmc/coding-standard/ecs.php');

$services = $containerConfigurator->services();

// All tests must have @test annotation instead of "test" prefix.
$services->set(PhpUnitTestAnnotationFixer::class)
->call('configure', [['style' => 'annotation']]);

// Force line length
$services->set(LineLengthFixer::class)
->call(
'configure',
[['line_length' => 120, 'break_long_lines' => true, 'inline_short_lines' => false]]
);
};
4 changes: 2 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ parameters:
- '#Unsafe usage of new static\(\)#'
- message: '#expects class-string#'
path: tests/
- message: '#parameter \$factoryArguments with no typehint specified#'
path: tests/unit/RequestBuilder/RequestBuilderFactoryTest.php
- message: '#Unsafe access to private constant .+ through static::#'
path: tests/

checkGenericClassInNonGenericObjectType: false
checkMissingIterableValueType: false
Expand Down
17 changes: 9 additions & 8 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?xml version="1.0"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="./vendor/autoload.php"
colors="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="./vendor/autoload.php"
colors="true"
>
<testsuites>
<testsuite name="unit">
Expand All @@ -13,11 +14,11 @@
</testsuite>
</testsuites>

<filter>
<whitelist>
<coverage>
<include>
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
</include>
</coverage>

<php>
<!-- E_ALL = 30719 -->
Expand Down
1 change: 1 addition & 0 deletions src/Http/ResponseDecoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function decode(ResponseInterface $httpResponse, string $responseClass =

$responseId = $httpResponse->getHeader(RequestManager::RESPONSE_ID_HEADER)[0] ?? null;

/** @phpstan-ignore-next-line */
return new $responseClass(
(int) $responseData->commands->number_of_commands,
(int) $responseData->commands->number_of_successful_commands,
Expand Down
7 changes: 5 additions & 2 deletions src/Model/Command/UserMerge.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ public static function mergeInto(string $targetUserId, string $sourceUserIdToBeD
*
* @return static
*/
public static function mergeFromSourceToTargetUser(string $sourceUserIdToBeDeleted, string $targetUserId, int $timestamp = null): self
{
public static function mergeFromSourceToTargetUser(
string $sourceUserIdToBeDeleted,
string $targetUserId,
int $timestamp = null
): self {
return new static($targetUserId, $sourceUserIdToBeDeleted, $timestamp);
}

Expand Down
9 changes: 7 additions & 2 deletions src/Model/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,13 @@ class Request
/** @var string */
private $responseClass;

public function __construct(string $path, string $method, array $data = [], string $requestId = null, string $responseClass = Response::class)
{
public function __construct(
string $path,
string $method,
array $data = [],
string $requestId = null,
string $responseClass = Response::class
) {
$this->path = $path;
$this->method = $method;
$this->data = $data;
Expand Down
12 changes: 7 additions & 5 deletions src/Model/Response/RecommendationsResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,27 @@ class RecommendationsResponse extends Response

public function getInteraction(): CommandResponse
{
return $this->getCommandResponse(static::INTERACTION_INDEX);
return $this->getCommandResponse(self::INTERACTION_INDEX);
}

public function getUserMerge(): CommandResponse
{
return $this->getCommandResponse(static::USER_MERGE_INDEX);
return $this->getCommandResponse(self::USER_MERGE_INDEX);
}

public function getRecommendation(): CommandResponse
{
return $this->getCommandResponse(static::RECOMMENDATION_INDEX);
return $this->getCommandResponse(self::RECOMMENDATION_INDEX);
}

protected function decodeRawCommandResponses(array $commandResponses): array
{
$decodedResponses = [];
foreach ($commandResponses as $index => $rawCommandResponse) {
if ($index === static::RECOMMENDATION_INDEX) {
$decodedResponses[] = RecommendationCommandResponse::createFromRawCommandResponseObject($rawCommandResponse);
if ($index === self::RECOMMENDATION_INDEX) {
$decodedResponses[] = RecommendationCommandResponse::createFromRawCommandResponseObject(
$rawCommandResponse
);
} else {
$decodedResponses[] = CommandResponse::createFromRawCommandResponseObject($rawCommandResponse);
}
Expand Down
7 changes: 6 additions & 1 deletion src/RequestBuilder/CampaignRequestBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ public function build(): Request
}
Assertion::batchSize($this->commands);

return new Request(static::ENDPOINT_PATH, RequestMethodInterface::METHOD_POST, $this->commands, $this->requestId);
return new Request(
static::ENDPOINT_PATH,
RequestMethodInterface::METHOD_POST,
$this->commands,
$this->requestId
);
}
}
7 changes: 6 additions & 1 deletion src/RequestBuilder/EventsRequestBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ public function build(): Request
}
Assertion::batchSize($this->commands);

return new Request(static::ENDPOINT_PATH, RequestMethodInterface::METHOD_POST, $this->commands, $this->requestId);
return new Request(
static::ENDPOINT_PATH,
RequestMethodInterface::METHOD_POST,
$this->commands,
$this->requestId
);
}
}
15 changes: 12 additions & 3 deletions tests/integration/IntegrationTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,18 @@ protected static function createMatejInstance(): Matej
protected function assertResponseCommandStatuses(Response $response, string ...$expectedCommandStatuses): void
{
$this->assertSame(count($expectedCommandStatuses), $response->getNumberOfCommands());
$this->assertSame(count(array_intersect($expectedCommandStatuses, ['OK'])), $response->getNumberOfSuccessfulCommands());
$this->assertSame(count(array_intersect($expectedCommandStatuses, ['INVALID'])), $response->getNumberOfFailedCommands());
$this->assertSame(count(array_intersect($expectedCommandStatuses, ['SKIPPED'])), $response->getNumberOfSkippedCommands());
$this->assertSame(
count(array_intersect($expectedCommandStatuses, ['OK'])),
$response->getNumberOfSuccessfulCommands()
);
$this->assertSame(
count(array_intersect($expectedCommandStatuses, ['INVALID'])),
$response->getNumberOfFailedCommands()
);
$this->assertSame(
count(array_intersect($expectedCommandStatuses, ['SKIPPED'])),
$response->getNumberOfSkippedCommands()
);

$commandResponses = $response->getCommandResponses();
foreach ($expectedCommandStatuses as $key => $expectedStatus) {
Expand Down
20 changes: 10 additions & 10 deletions tests/integration/RequestBuilder/EventsRequestBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ class EventsRequestBuilderTest extends IntegrationTestCase

public static function setUpBeforeClass(): void
{
$matej = static::createMatejInstance();
static::setupItemProperties($matej);
static::waitForItemPropertiesSetup($matej);
$matej = self::createMatejInstance();
self::setupItemProperties($matej);
self::waitForItemPropertiesSetup($matej);
}

public static function tearDownAfterClass(): void
{
$matej = static::createMatejInstance();
static::resetItemProperties($matej);
$matej = self::createMatejInstance();
self::resetItemProperties($matej);
}

/** @test */
Expand All @@ -40,7 +40,7 @@ public function shouldThrowExceptionWhenSendingBlankRequest(): void
$this->expectException(LogicException::class);
$this->expectExceptionMessage('At least one command must be added to the builder before sending the request');

static::createMatejInstance()
self::createMatejInstance()
->request()
->events()
->send();
Expand All @@ -49,7 +49,7 @@ public function shouldThrowExceptionWhenSendingBlankRequest(): void
/** @test */
public function shouldExecuteInteractionAndUserMergeAndItemPropertyCommands(): void
{
$response = static::createMatejInstance()
$response = self::createMatejInstance()
->request()
->events()
->addInteraction(Interaction::withItem('search', 'user-a', 'item-a'))
Expand All @@ -75,7 +75,7 @@ public function shouldExecuteInteractionAndUserMergeAndItemPropertyCommands(): v
private static function setupItemProperties(Matej $matej): void
{
$request = $matej->request()->setupItemProperties();
foreach (static::PROPERTIES_LIST as $property) {
foreach (self::PROPERTIES_LIST as $property) {
$request->addProperty(ItemPropertySetup::string($property));
}
$request->send();
Expand All @@ -92,7 +92,7 @@ private static function waitForItemPropertiesSetup(Matej $matej): void
$properties[] = $property->name;
}

if (!array_diff(static::PROPERTIES_LIST, $properties)) {
if (!array_diff(self::PROPERTIES_LIST, $properties)) {
return;
}
usleep(100000); # 0.1s
Expand All @@ -102,7 +102,7 @@ private static function waitForItemPropertiesSetup(Matej $matej): void
private static function resetItemProperties(Matej $matej): void
{
$request = $matej->request()->deleteItemProperties();
foreach (static::PROPERTIES_LIST as $property) {
foreach (self::PROPERTIES_LIST as $property) {
$request->addProperty(ItemPropertySetup::string($property));
}
$request->send();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ class ItemPropertiesSetupRequestBuilderTest extends IntegrationTestCase
public function shouldThrowExceptionWhenSendingBlankRequests(ItemPropertiesSetupRequestBuilder $builder): void
{
$this->expectException(LogicException::class);
$this->expectExceptionMessage('At least one ItemPropertySetup command must be added to the builder before sending the request');
$this->expectExceptionMessage(
'At least one ItemPropertySetup command must be added to the builder before sending the request'
);
$builder->send();
}

Expand Down
4 changes: 3 additions & 1 deletion tests/integration/RequestBuilder/SortingRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ public function shouldReturnInvalidCommandOnInvalidModelName(): void
{
$response = static::createMatejInstance()
->request()
->sorting(ItemSorting::create('user-b', ['item-a', 'item-b', 'itemC-c'])->setModelName('invalid-model-name'))
->sorting(
ItemSorting::create('user-b', ['item-a', 'item-b', 'itemC-c'])->setModelName('invalid-model-name')
)
->send();

$this->assertInstanceOf(SortingResponse::class, $response);
Expand Down
6 changes: 4 additions & 2 deletions tests/unit/Http/RequestManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ class RequestManagerTest extends UnitTestCase
*/
public function shouldSendAndDecodeRequest(): void
{
$dummyHttpResponse = $this->createJsonResponseFromFile(__DIR__ . '/Fixtures/response-one-successful-command.json');
$dummyHttpResponse = $this->createJsonResponseFromFile(
__DIR__ . '/Fixtures/response-one-successful-command.json'
);

$mockClient = new Client();
$mockClient->addResponse($dummyHttpResponse);
Expand All @@ -43,7 +45,7 @@ public function shouldSendAndDecodeRequest(): void
// Assert properties of the send request
$recordedRequests = $mockClient->getRequests();
$this->assertCount(1, $recordedRequests);
$this->assertRegExp(
$this->assertMatchesRegularExpression(
'~https\://account\-id\.matej\.lmc\.cz/foo/endpoint\?hmac_timestamp\=[0-9]+&hmac_sign\=[[:alnum:]]~',
$recordedRequests[0]->getUri()->__toString()
);
Expand Down
Loading

0 comments on commit d759bb0

Please sign in to comment.