Skip to content

Commit

Permalink
[RequestMapper] Added SonarCloud checks, refactor GitHub actions
Browse files Browse the repository at this point in the history
  • Loading branch information
fractalzombie committed Mar 6, 2023
1 parent 0e654d8 commit d5b2ee1
Show file tree
Hide file tree
Showing 22 changed files with 164 additions and 125 deletions.
112 changes: 112 additions & 0 deletions .github/workflows/build.yml
@@ -0,0 +1,112 @@
name: Build

on:
push:
branches:
- main
- develop
- 'releases/**'
paths-ignore:
- '**/*.md'
- '**/*.gitignore'
- '**/*.gitattributes'

pull_request:
types:
- published
- created
- edited
- opened
- synchronize
- reopened
paths-ignore:
- '**/*.md'
- '**/*.gitignore'
- '**/*.gitattributes'

jobs:
build:
name: PHP
runs-on: ubuntu-latest

strategy:
matrix:
php:
- "8.1"
- "8.2"
include:
- php-versions: ["8.1", "8.2"]
- composer-options: "--ignore-platform-reqs"

steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: "${{ matrix.php }}"
extensions: mbstring, intl
coverage: xdebug
tools: pecl, phpunit, composer
ini-values: post_max_size=256M

- name: Setup composer
uses: ramsey/composer-install@v1
with:
composer-options: "${{ matrix.composer-options }}"

- name: Validate composer files
run: composer validate

- name: Cache composer packages
id: composer-cache
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
- name: Install dependencies
if: steps.composer-cache.outputs.cache-hit != 'true'
run: composer update --prefer-dist --no-progress

- name: Setup tests directories
run: mkdir -p build/logs

- name: Execute unit tests
run: ./vendor/bin/phpunit --colors=always --configuration phpunit.xml.dist --coverage-cobertura tests-cobertura.xml --coverage-clover tests-coverage.xml --log-junit tests-execution.xml

- name: Prepare coverages and logs
run: cp tests-coverage.xml build/logs/clover.xml && cp tests-cobertura.xml build/logs/cobertura.xml && cp tests-execution.xml build/logs/junit.xml

- name: Push to Coveralls
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COVERALLS_PARALLEL: true
COVERALLS_FLAG_NAME: php-${{ matrix.php-versions }}
run: |
composer global require php-coveralls/php-coveralls
php-coveralls -v
- name: SonarCloud scan
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
projectBaseDir: ${{ github.workspace }}

finish:
needs: [ build ]
runs-on: ubuntu-latest

steps:
- name: Coveralls Finished
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
parallel-finished: true
84 changes: 0 additions & 84 deletions .github/workflows/ci.yml

This file was deleted.

14 changes: 12 additions & 2 deletions README.md
@@ -1,15 +1,25 @@
RequestMapper Component
=============================
![Workflow Build Status](https://github.com/fractalzombie/frzb-request-mapper/actions/workflows/ci.yml/badge.svg?event=push)
![Workflow Build Status](https://github.com/fractalzombie/frzb-request-mapper/actions/workflows/build.yml/badge.svg?event=push)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/fractalzombie/frzb-request-mapper/badges/quality-score.png?b=main)](https://scrutinizer-ci.com/g/fractalzombie/frzb-request-mapper/?branch=main)
[![Code Intelligence Status](https://scrutinizer-ci.com/g/fractalzombie/frzb-request-mapper/badges/code-intelligence.svg?b=main)](https://scrutinizer-ci.com/code-intelligence)
[![Build Status](https://scrutinizer-ci.com/g/fractalzombie/frzb-request-mapper/badges/build.png?b=main)](https://scrutinizer-ci.com/g/fractalzombie/frzb-request-mapper/build-status/main)
[![Coverage Status](https://coveralls.io/repos/github/fractalzombie/frzb-request-mapper/badge.svg?branch=main)](https://coveralls.io/github/fractalzombie/frzb-request-mapper?branch=main)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=fractalzombie_frzb-request-mapper&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=fractalzombie_frzb-request-mapper)
[![Bugs](https://sonarcloud.io/api/project_badges/measure?project=fractalzombie_frzb-request-mapper&metric=bugs)](https://sonarcloud.io/summary/new_code?id=fractalzombie_frzb-request-mapper)
[![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=fractalzombie_frzb-request-mapper&metric=security_rating)](https://sonarcloud.io/summary/new_code?id=fractalzombie_frzb-request-mapper)
[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=fractalzombie_frzb-request-mapper&metric=sqale_rating)](https://sonarcloud.io/summary/new_code?id=fractalzombie_frzb-request-mapper)
[![Code Smells](https://sonarcloud.io/api/project_badges/measure?project=fractalzombie_frzb-request-mapper&metric=code_smells)](https://sonarcloud.io/summary/new_code?id=fractalzombie_frzb-request-mapper)
[![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=fractalzombie_frzb-request-mapper&metric=ncloc)](https://sonarcloud.io/summary/new_code?id=fractalzombie_frzb-request-mapper)
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=fractalzombie_frzb-request-mapper&metric=coverage)](https://sonarcloud.io/summary/new_code?id=fractalzombie_frzb-request-mapper)
[![Technical Debt](https://sonarcloud.io/api/project_badges/measure?project=fractalzombie_frzb-request-mapper&metric=sqale_index)](https://sonarcloud.io/summary/new_code?id=fractalzombie_frzb-request-mapper)
[![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=fractalzombie_frzb-request-mapper&metric=reliability_rating)](https://sonarcloud.io/summary/new_code?id=fractalzombie_frzb-request-mapper)
[![Duplicated Lines (%)](https://sonarcloud.io/api/project_badges/measure?project=fractalzombie_frzb-request-mapper&metric=duplicated_lines_density)](https://sonarcloud.io/summary/new_code?id=fractalzombie_frzb-request-mapper)
[![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=fractalzombie_frzb-request-mapper&metric=vulnerabilities)](https://sonarcloud.io/summary/new_code?id=fractalzombie_frzb-request-mapper)

The RequestMapper component allows you to serialize JSON request to Request class and validate it.

Resources
---------

* [Documentation](https://github.com/fractalzombie/frzb-request-mapper/blob/main/Documentation/USAGE.MD)
* [License](https://github.com/fractalzombie/frzb-request-mapper/blob/main/LICENSE)
2 changes: 1 addition & 1 deletion Tests/Func/EventListener/JsonRequestListenerTest.php
Expand Up @@ -51,7 +51,7 @@ public function testOnKernelRequestMethod(
}

/** @throws \JsonException */
public function caseProvider(): iterable
public static function caseProvider(): iterable
{
yield 'with valid GET JSON request' => [
'method' => Request::METHOD_GET,
Expand Down
2 changes: 1 addition & 1 deletion Tests/Func/EventListener/RequestMapperListenerTest.php
Expand Up @@ -62,7 +62,7 @@ public function testOnKernelController(
}
}

public function dataProvider(): iterable
public static function dataProvider(): iterable
{
$params = ['name' => 'some name', 'model' => 'Product'];

Expand Down
2 changes: 1 addition & 1 deletion Tests/Func/ExceptionFormatter/ExceptionFormatterTest.php
Expand Up @@ -46,7 +46,7 @@ public function test(\Throwable $e, ErrorContract $errorContract): void
self::assertJsonStringEqualsJsonString(json_encode($errorContract), json_encode($formattedErrorContract));
}

public function caseProvider(): iterable
public static function caseProvider(): iterable
{
yield sprintf('Format "%s"', HttpException::class) => [
'exception' => new HttpException(Response::HTTP_INTERNAL_SERVER_ERROR, 'Internal Server Error'),
Expand Down
4 changes: 2 additions & 2 deletions Tests/Func/Locator/ExceptionFormatterLocatorTest.php
Expand Up @@ -38,11 +38,11 @@ public function testGetAndHasMethods(\Throwable $e, string $formatterClass, bool
{
$formatter = $this->locator->get($e);

self::assertSame($formatterClass, $formatter::class);
self::assertInstanceOf($formatterClass, $formatter);
self::assertSame($existsInLocator, $this->locator->has($e));
}

public function caseProvider(): iterable
public static function caseProvider(): iterable
{
yield sprintf('"%s" uses "%s" converter', HttpException::class, HttpExceptionFormatter::class) => [
'exception' => new HttpException(Response::HTTP_INTERNAL_SERVER_ERROR, 'Internal Server Error'),
Expand Down
2 changes: 1 addition & 1 deletion Tests/Func/RequestMapper/RequestMapperTest.php
Expand Up @@ -64,7 +64,7 @@ public function testConvertMethod(Request $nativeRequest, RequestBody $requestBo
}

/** @throws \Exception */
public function caseProvider(): iterable
public static function caseProvider(): iterable
{
$params = ['name' => TestConstant::USER_NAME, 'userId' => TestConstant::USER_ID, 'amount' => TestConstant::USER_AMOUNT, 'testEnum' => TestEnum::One->value];
$attribute = new RequestBody(requestClass: CreateUserRequestWithEnum::class, argumentName: 'typed_request');
Expand Down
2 changes: 1 addition & 1 deletion Tests/Unit/Attribute/RequestBodyAttributeTest.php
Expand Up @@ -31,7 +31,7 @@ public function testEqualsMethod(RequestBody $first, object $second, bool $expec
self::assertSame($expected, $first->equals($second));
}

public function equalsCaseProvider(): iterable
public static function equalsCaseProvider(): iterable
{
yield 'with equals parameter class' => [
'first' => new RequestBody(CreateUserRequest::class),
Expand Down
2 changes: 1 addition & 1 deletion Tests/Unit/Data/TypeErrorTest.php
Expand Up @@ -32,7 +32,7 @@ public function testCreation(array $params, bool $throws = false): void
self::assertSame($params['proposed'], $error->proposed);
}

public function caseProvider(): iterable
public static function caseProvider(): iterable
{
yield 'all parameters are exists' => [
'params' => [
Expand Down
2 changes: 1 addition & 1 deletion Tests/Unit/EventListener/ExceptionListenerTest.php
Expand Up @@ -53,7 +53,7 @@ public function testOnKernelRequestMethod(array $headers, InvocationOrder $expec
self::assertSame($headers, HeaderHelper::getHeaders($request));
}

public function caseProvider(): iterable
public static function caseProvider(): iterable
{
yield 'with header content-type equals application/json' => [
'headers' => ['content-type' => 'application/json'],
Expand Down
2 changes: 1 addition & 1 deletion Tests/Unit/EventListener/RequestMapperListenerTest.php
Expand Up @@ -47,7 +47,7 @@ public function testOnKernelController(array $params, string $httpMethod, string
}
}

public function dataProvider(): iterable
public static function dataProvider(): iterable
{
$params = ['name' => 'some name', 'model' => 'Product'];

Expand Down
Expand Up @@ -47,7 +47,7 @@ public function testMapping(
self::assertSame($message, $error->getMessage());
}

public function caseProvider(): iterable
public static function caseProvider(): iterable
{
yield 'test it with type of template' => [
'parameter' => 'name',
Expand Down
2 changes: 1 addition & 1 deletion Tests/Unit/Extractor/DiscriminatorMapExtractorTest.php
Expand Up @@ -37,7 +37,7 @@ public function testExtractMethod(string $givenClass, string $expectedClass, arr
self::assertSame($expectedClass, $extractedClass);
}

public function caseProvider(): iterable
public static function caseProvider(): iterable
{
yield sprintf('Class "%s" without discriminator', CreateUserRequest::class) => [
'given_class' => CreateUserRequest::class,
Expand Down
2 changes: 1 addition & 1 deletion Tests/Unit/Extractor/ParametersExtractorTest.php
Expand Up @@ -49,7 +49,7 @@ public function testExtractMethod(string $class, array $parameters): void
self::assertSame($parameters, $this->parameterExtractor->extract($class, $parameters));
}

public function caseProvider(): iterable
public static function caseProvider(): iterable
{
$parameters = [
'name' => TestConstant::USER_NAME,
Expand Down
12 changes: 6 additions & 6 deletions Tests/Unit/Helper/ClassHelperTest.php
Expand Up @@ -21,7 +21,7 @@ public function testIsNotBuiltinAndExistsMethod(string $class, bool $isNotBuilti
self::assertSame($isNotBuiltinAndExists, ClassHelper::isNotBuiltinAndExists($class));
}

public function isNotBuiltinCaseProvider(): iterable
public static function isNotBuiltinCaseProvider(): iterable
{
yield sprintf('with "%s"', CreateUserRequest::class) => [
'class' => CreateUserRequest::class,
Expand All @@ -45,7 +45,7 @@ public function testGetShortNameMethod(string $className, string $expectedName):
self::assertSame($expectedName, ClassHelper::getShortName($className));
}

public function getShortNameCaseProvider(): iterable
public static function getShortNameCaseProvider(): iterable
{
yield sprintf('class "%s"', CreateUserRequest::class) => [
'class_name' => CreateUserRequest::class,
Expand All @@ -69,7 +69,7 @@ public function testIsNameContainsMethod(string $className, array $haystack, boo
self::assertSame($contains, ClassHelper::isNameContains($className, ...$haystack));
}

public function nameContainsCaseProvider(): iterable
public static function nameContainsCaseProvider(): iterable
{
yield sprintf('class "%s" and haystack "%s"', CreateUserRequest::class, implode(', ', ['Request'])) => [
'class_name' => CreateUserRequest::class,
Expand Down Expand Up @@ -107,7 +107,7 @@ public function testGetMethodParametersMethod(string $className, string $method,
self::assertSame($expectedMapping, $mapping);
}

public function getMethodParametersCaseProvider(): iterable
public static function getMethodParametersCaseProvider(): iterable
{
yield sprintf('class "%s", mapping "%s"', CreateUserRequest::class, implode(', ', ['name', 'userId', 'amount'])) => [
'class_name' => CreateUserRequest::class,
Expand All @@ -128,7 +128,7 @@ public function testIsEnumMethod(string $className, bool $expectedResult): void
self::assertSame(ClassHelper::isEnum($className), $expectedResult);
}

public function isEnumCaseProvider(): iterable
public static function isEnumCaseProvider(): iterable
{
yield sprintf('enum "%s" is valid', TestEnum::class) => [
'value' => TestEnum::class,
Expand All @@ -147,7 +147,7 @@ public function testIsArrayHasAllPropertiesFromClass(array $properties, string $
self::assertSame($expected, ClassHelper::isArrayHasAllPropertiesFromClass($properties, $class));
}

public function isArrayHasAllPropertiesFromClassCaseProvider(): iterable
public static function isArrayHasAllPropertiesFromClassCaseProvider(): iterable
{
$properties = ['name' => TestConstant::USER_NAME, 'userId' => TestConstant::UUID, 'amount' => TestConstant::USER_AMOUNT];

Expand Down

0 comments on commit d5b2ee1

Please sign in to comment.