Skip to content

Commit 1f09415

Browse files
authored
Merge pull request #6 from ensi-platform/task-93411
#93411 Cleanup, php cs fixer, pest
2 parents d238759 + 2fd0723 commit 1f09415

30 files changed

+573
-544
lines changed

.github/workflows/php-cs-fixer.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Check & fix styling
2+
3+
on: [push]
4+
5+
jobs:
6+
php-cs-fixer:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- name: Checkout code
11+
uses: actions/checkout@v2
12+
with:
13+
ref: ${{ github.head_ref }}
14+
15+
- name: Run PHP CS Fixer
16+
uses: docker://oskarstark/php-cs-fixer-ga
17+
with:
18+
args: --config=.php-cs-fixer.php --allow-risky=yes
19+
20+
- name: Commit changes
21+
uses: stefanzweifel/git-auto-commit-action@v4
22+
with:
23+
commit_message: Fix styling

.github/workflows/run-tests.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: run-tests
2+
3+
on:
4+
push:
5+
branches: [master]
6+
pull_request:
7+
branches: [master]
8+
9+
jobs:
10+
test:
11+
runs-on: ${{ matrix.os }}
12+
strategy:
13+
fail-fast: true
14+
matrix:
15+
os: [ubuntu-latest, windows-latest]
16+
php: [8.1]
17+
laravel: [9.*]
18+
stability: [prefer-lowest, prefer-stable]
19+
include:
20+
- laravel: 9.*
21+
testbench: ^7.22
22+
23+
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}
24+
25+
steps:
26+
- name: Checkout code
27+
uses: actions/checkout@v2
28+
29+
- name: Setup PHP
30+
uses: shivammathur/setup-php@v2
31+
with:
32+
php-version: ${{ matrix.php }}
33+
extensions: dom, curl, libxml, mbstring, zip, pcntl, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
34+
coverage: none
35+
36+
- name: Setup problem matchers
37+
run: |
38+
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
39+
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
40+
- name: Install dependencies
41+
run: |
42+
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
43+
composer update --${{ matrix.stability }} --prefer-dist --no-interaction
44+
- name: Execute tests
45+
run: vendor/bin/pest

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ composer.lock
44
npm-debug.log
55
yarn-error.log
66
.php_cs.cache
7-
composer.lock
87

98
# IDEs #
109
###################
@@ -43,4 +42,5 @@ Thumbs.db
4342
# tests
4443
openapitools.json
4544
.phpunit.result.cache
46-
build
45+
build
46+
.php-cs-fixer.cache

.php-cs-fixer.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
$finder = Symfony\Component\Finder\Finder::create()
4+
->notPath('vendor')
5+
->in(__DIR__)
6+
->name('*.php')
7+
->notName('_ide_helper.php')
8+
->notName('_ide_helper_models.php')
9+
->ignoreDotFiles(true)
10+
->ignoreVCS(true);
11+
12+
return (new PhpCsFixer\Config())
13+
->setRules([
14+
'@PSR2' => true,
15+
'@PSR12' => true,
16+
'array_syntax' => ['syntax' => 'short'],
17+
'ordered_imports' => ['sort_algorithm' => 'alpha'],
18+
'no_unused_imports' => true,
19+
'trailing_comma_in_multiline' => true,
20+
'phpdoc_scalar' => true,
21+
'unary_operator_spaces' => true,
22+
'binary_operator_spaces' => true,
23+
'concat_space' => ['spacing' => 'one'],
24+
'blank_line_before_statement' => [
25+
'statements' => ['break', 'continue', 'declare', 'return', 'throw', 'try'],
26+
],
27+
'phpdoc_single_line_var_spacing' => true,
28+
'phpdoc_var_without_name' => true,
29+
'class_attributes_separation' => [
30+
'elements' => [
31+
'method' => 'one',
32+
],
33+
],
34+
'method_argument_space' => [
35+
'on_multiline' => 'ensure_fully_multiline',
36+
'keep_multiple_spaces_after_comma' => true,
37+
],
38+
'single_trait_insert_per_statement' => true,
39+
'no_whitespace_in_blank_line' => true,
40+
'method_chaining_indentation' => true,
41+
])
42+
->setFinder($finder);

composer.json

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
"description": "",
44
"type": "library",
55
"authors": [
6-
{
7-
"name": "Ilya Nekrasov",
8-
"email": "nekrasov@greensight.ru"
9-
}
6+
{
7+
"name": "Ilya Nekrasov",
8+
"email": "nekrasov@greensight.ru"
9+
}
1010
],
1111
"license": "MIT",
1212
"require": {
@@ -15,14 +15,20 @@
1515
"nette/php-generator": "^3.5"
1616
},
1717
"autoload": {
18-
"psr-4": {
19-
"Ensi\\LaravelOpenapiClientGenerator\\": "src/"
20-
}
18+
"psr-4": {
19+
"Ensi\\LaravelOpenapiClientGenerator\\": "src/"
20+
}
21+
},
22+
"autoload-dev": {
23+
"psr-4": {
24+
"Ensi\\LaravelOpenapiClientGenerator\\Tests\\": "tests/"
25+
}
2126
},
2227
"require-dev": {
28+
"friendsofphp/php-cs-fixer": "^3.14",
2329
"laravel/framework": "^8.40 || ^9.0",
24-
"phpunit/phpunit": "^9.2",
25-
"orchestra/testbench": "^6.0 || ^7.0"
30+
"orchestra/testbench": "^6.0 || ^7.0",
31+
"pestphp/pest": "^1.22"
2632
},
2733
"extra": {
2834
"laravel": {
@@ -32,6 +38,14 @@
3238
}
3339
},
3440
"scripts": {
35-
"test": "phpunit"
41+
"cs": "php-cs-fixer fix --config .php-cs-fixer.php",
42+
"test": "./vendor/bin/pest --no-coverage",
43+
"test-coverage": "XDEBUG_MODE=coverage ./vendor/bin/pest --coverage"
44+
},
45+
"config": {
46+
"sort-packages": true,
47+
"allow-plugins": {
48+
"pestphp/pest-plugin": true
49+
}
3650
}
3751
}

config/openapi-client-generator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
'apiPackage' => 'Api',
7575
'invokerPackage' => '<paste_your_php_package_namespace>',
7676
'modelPackage' => 'Dto',
77-
'packageName' => '<paste_your_php_package_name>'
77+
'packageName' => '<paste_your_php_package_name>',
7878
],
7979

8080
/**
@@ -91,5 +91,5 @@
9191
* Options for disable patch section "require" composer.json
9292
*/
9393
'composer_disable_patch_require' => false,
94-
]
94+
],
9595
];

phpunit.xml

Lines changed: 0 additions & 31 deletions
This file was deleted.

phpunit.xml.dist

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
5+
backupGlobals="false"
6+
backupStaticAttributes="false"
7+
bootstrap="vendor/autoload.php"
8+
colors="true"
9+
convertErrorsToExceptions="true"
10+
convertNoticesToExceptions="true"
11+
convertWarningsToExceptions="true"
12+
processIsolation="false"
13+
stopOnFailure="false"
14+
executionOrder="random"
15+
failOnWarning="true"
16+
failOnRisky="true"
17+
failOnEmptyTestSuite="true"
18+
beStrictAboutOutputDuringTests="true"
19+
verbose="true"
20+
>
21+
<testsuites>
22+
<testsuite name="VendorName Test Suite">
23+
<directory>tests</directory>
24+
</testsuite>
25+
</testsuites>
26+
<coverage>
27+
<include>
28+
<directory suffix=".php">./src</directory>
29+
</include>
30+
<report>
31+
<html outputDirectory="build/coverage"/>
32+
<text outputFile="build/coverage.txt"/>
33+
<clover outputFile="build/logs/clover.xml"/>
34+
</report>
35+
</coverage>
36+
<logging>
37+
<junit outputFile="build/report.junit.xml"/>
38+
</logging>
39+
</phpunit>

src/Commands/GenerateClient.php

Lines changed: 15 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -7,57 +7,27 @@
77

88
abstract class GenerateClient extends Command
99
{
10-
/**
11-
* @var string
12-
* Client name: js or php, must be set in child classes
13-
*/
14-
protected $client;
10+
/** Client name: js or php, must be set in child classes */
11+
protected string $client;
1512

16-
/**
17-
* @var string
18-
* Generator name, one of valid openapi generators names
19-
*/
20-
protected $generator;
13+
/** Generator name, one of valid openapi generators names */
14+
protected string $generator;
2115

22-
/**
23-
* @var string
24-
*/
25-
protected $apidocDir;
16+
protected string $apidocDir;
2617

27-
/**
28-
* @var string
29-
*/
30-
protected $outputDir;
18+
protected string $outputDir;
3119

32-
/**
33-
* @var string
34-
*/
35-
protected $gitUser;
20+
protected string $gitUser;
3621

37-
/**
38-
* @var string
39-
*/
40-
protected $gitRepo;
22+
protected string $gitRepo;
4123

42-
/**
43-
* @var string
44-
*/
45-
protected $gitHost;
24+
protected string $gitHost;
4625

47-
/**
48-
* @var array
49-
*/
50-
protected $params;
26+
protected array $params;
5127

52-
/**
53-
* @var string
54-
*/
55-
protected $templateDir;
28+
protected string $templateDir;
5629

57-
/**
58-
* @var array
59-
*/
60-
protected $filesToIgnoreDuringCleanup;
30+
protected array $filesToIgnoreDuringCleanup;
6131

6232
public function __construct()
6333
{
@@ -90,11 +60,11 @@ public function handle(): int
9060
return self::SUCCESS;
9161
}
9262

93-
protected abstract function patchClientPackage(): void;
63+
abstract protected function patchClientPackage(): void;
9464

9565
private function generateClientPackage(): int
9666
{
97-
$bin = 'npx @openapitools/openapi-generator-cli';
67+
$bin = 'npx --yes @openapitools/openapi-generator-cli';
9868
$i = escapeshellarg($this->apidocDir . DIRECTORY_SEPARATOR . "index.yaml");
9969
$g = escapeshellarg($this->generator);
10070
$o = escapeshellarg($this->outputDir);
@@ -143,6 +113,7 @@ private function getAdditionalParamsArgument(): string
143113
return collect($this->params)
144114
->map(function ($value, $name) {
145115
$escapedValue = PHP_OS_FAMILY !== 'Windows' ? str_replace("\\", "\\\\", $value) : $value;
116+
146117
return "$name=$escapedValue";
147118
})
148119
->join(',');

0 commit comments

Comments
 (0)