Skip to content

Commit

Permalink
Merge 1172576 into 9666a62
Browse files Browse the repository at this point in the history
  • Loading branch information
OndraM committed Jan 15, 2024
2 parents 9666a62 + 1172576 commit e699dbf
Show file tree
Hide file tree
Showing 20 changed files with 114 additions and 39 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
13 changes: 7 additions & 6 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,7 +28,8 @@
},
"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",
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]]
);
};
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
4 changes: 3 additions & 1 deletion src/Model/Response/RecommendationsResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ protected function decodeRawCommandResponses(array $commandResponses): array
$decodedResponses = [];
foreach ($commandResponses as $index => $rawCommandResponse) {
if ($index === static::RECOMMENDATION_INDEX) {
$decodedResponses[] = RecommendationCommandResponse::createFromRawCommandResponseObject($rawCommandResponse);
$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
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
4 changes: 3 additions & 1 deletion 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 Down
8 changes: 6 additions & 2 deletions tests/unit/MatejTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ public function shouldBeInstantiable(): void
/** @test */
public function shouldExecuteRequestViaBuilder(): void
{
$dummyHttpResponse = $this->createJsonResponseFromFile(__DIR__ . '/Http/Fixtures/response-one-successful-command.json');
$dummyHttpResponse = $this->createJsonResponseFromFile(
__DIR__ . '/Http/Fixtures/response-one-successful-command.json'
);

$mockClient = new Client();
$mockClient->addResponse($dummyHttpResponse);
Expand Down Expand Up @@ -52,7 +54,9 @@ public function shouldExecuteRequestViaBuilder(): void
/** @test */
public function shouldOverwriteBaseUrl(): void
{
$dummyHttpResponse = $this->createJsonResponseFromFile(__DIR__ . '/Http/Fixtures/response-one-successful-command.json');
$dummyHttpResponse = $this->createJsonResponseFromFile(
__DIR__ . '/Http/Fixtures/response-one-successful-command.json'
);

$mockClient = new Client();
$mockClient->addResponse($dummyHttpResponse);
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/Model/Command/ItemPropertySetupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ public function shouldBeInstantiableViaNamedConstructors(
public function shouldNotAllowItemIdAsPropertyName(string $constructorName): void
{
$this->expectException(DomainException::class);
$this->expectExceptionMessage('Cannot manipulate with property "item_id" - it is used by Matej to identify items.');
$this->expectExceptionMessage(
'Cannot manipulate with property "item_id" - it is used by Matej to identify items.'
);
ItemPropertySetup::$constructorName('item_id');
}

Expand Down
4 changes: 3 additions & 1 deletion tests/unit/Model/Command/ItemPropertyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ class ItemPropertyTest extends TestCase
public function shouldNotAllowItemIdInProperties(): void
{
$this->expectException(DomainException::class);
$this->expectExceptionMessage('Cannot update value of "item_id" property - it is used by Matej to identify the item and cannot be altered once created.');
$this->expectExceptionMessage(
'Cannot update value of "item_id" property - it is used by Matej to identify the item and cannot be altered once created.'
);
ItemProperty::create('exampleItemId', ['item_id' => 'customItemId']);
}

Expand Down
4 changes: 3 additions & 1 deletion tests/unit/Model/Command/UserMergeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ public function shouldGenerateCorrectSignature(): void
public function shouldThrowExceptionWhenMergingSameUsers(): void
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('You have to provide different source and target user id in UserMerge ("test-user" set for both)');
$this->expectExceptionMessage(
'You have to provide different source and target user id in UserMerge ("test-user" set for both)'
);

UserMerge::mergeInto('test-user', 'test-user');
}
Expand Down
6 changes: 5 additions & 1 deletion tests/unit/Model/Response/RecommendationsResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ public function shouldBeInstantiable(array $recommendationResponseData): void
'data' => $recommendationResponseData,
];

$response = new RecommendationsResponse(3, 3, 0, 0, [$interactionCommandResponse, $userMergeCommandResponse, $recommendationCommandResponse]);
$response = new RecommendationsResponse(3, 3, 0, 0, [
$interactionCommandResponse,
$userMergeCommandResponse,
$recommendationCommandResponse,
]);

$this->assertTrue($response->getInteraction()->isSuccessful());
$this->assertTrue($response->getUserMerge()->isSuccessful());
Expand Down
6 changes: 5 additions & 1 deletion tests/unit/Model/Response/SortingResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ public function shouldBeInstantiable(): void
'data' => ['MOCK' => 'SORTING'],
];

$response = new SortingResponse(3, 3, 0, 0, [$interactionCommandResponse, $userMergeCommandResponse, $sortingCommandReponse]);
$response = new SortingResponse(3, 3, 0, 0, [
$interactionCommandResponse,
$userMergeCommandResponse,
$sortingCommandReponse,
]);

$this->assertTrue($response->getInteraction()->isSuccessful());
$this->assertTrue($response->getUserMerge()->isSuccessful());
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/RequestBuilder/ForgetRequestBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ public function shouldThrowExceptionWhenBuildingEmptyCommands(): void
$builder = new ForgetRequestBuilder();

$this->expectException(LogicException::class);
$this->expectExceptionMessage('At least one UserForget command must be added to the builder before sending the request');
$this->expectExceptionMessage(
'At least one UserForget command must be added to the builder before sending the request'
);
$builder->build();
}

Expand Down

0 comments on commit e699dbf

Please sign in to comment.