From a0ae34ec0dd5806297552bee881ae9e6b4f5148e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 21 Apr 2022 00:49:09 +0000 Subject: [PATCH 1/8] Bump TheDragonCode/codestyler from 2.0.0 to 2.0.1 Bumps [TheDragonCode/codestyler](https://github.com/TheDragonCode/codestyler) from 2.0.0 to 2.0.1. - [Release notes](https://github.com/TheDragonCode/codestyler/releases) - [Commits](https://github.com/TheDragonCode/codestyler/compare/v2.0.0...v2.0.1) --- updated-dependencies: - dependency-name: TheDragonCode/codestyler dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .github/workflows/lint-check.yml | 2 +- .github/workflows/lint-fixer.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/lint-check.yml b/.github/workflows/lint-check.yml index 58367b7..f5481d1 100644 --- a/.github/workflows/lint-check.yml +++ b/.github/workflows/lint-check.yml @@ -11,4 +11,4 @@ jobs: uses: actions/checkout@v3 - name: Checking PHP Syntax - uses: TheDragonCode/codestyler@v2.0.0 + uses: TheDragonCode/codestyler@v2.0.1 diff --git a/.github/workflows/lint-fixer.yml b/.github/workflows/lint-fixer.yml index 110a676..64a9e13 100644 --- a/.github/workflows/lint-fixer.yml +++ b/.github/workflows/lint-fixer.yml @@ -13,7 +13,7 @@ jobs: uses: actions/checkout@v3 - name: Checking PHP Syntax - uses: TheDragonCode/codestyler@v2.0.0 + uses: TheDragonCode/codestyler@v2.0.1 with: github_token: ${{ secrets.COMPOSER_TOKEN }} fix: true From 63ec3c73c278836808d856557716205798512b46 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Thu, 5 May 2022 08:36:51 +0900 Subject: [PATCH 2/8] Update config.sh --- shell/config.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/shell/config.sh b/shell/config.sh index 32c48ea..6ed28d7 100644 --- a/shell/config.sh +++ b/shell/config.sh @@ -10,3 +10,6 @@ # Set git config git config --local user.email "action@github.com" git config --local user.name "GitHub Action" + +# Set safe directory +git config --global --add safe.directory /github/workspace From a5511889abc7b01f46b9df0674872c86f3528fc5 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Thu, 5 May 2022 08:46:46 +0900 Subject: [PATCH 3/8] Update config.sh --- shell/config.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shell/config.sh b/shell/config.sh index 6ed28d7..99e16ae 100644 --- a/shell/config.sh +++ b/shell/config.sh @@ -8,8 +8,8 @@ }; # Set git config -git config --local user.email "action@github.com" -git config --local user.name "GitHub Action" +git config --global user.email "action@github.com" +git config --global user.name "GitHub Action" # Set safe directory git config --global --add safe.directory /github/workspace From 4eca6eb2e4b139931713c986da877cb259eebf6a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 5 May 2022 00:43:23 +0000 Subject: [PATCH 4/8] Bump TheDragonCode/codestyler from 2.0.1 to 2.0.3 Bumps [TheDragonCode/codestyler](https://github.com/TheDragonCode/codestyler) from 2.0.1 to 2.0.3. - [Release notes](https://github.com/TheDragonCode/codestyler/releases) - [Commits](https://github.com/TheDragonCode/codestyler/compare/v2.0.1...v2.0.3) --- updated-dependencies: - dependency-name: TheDragonCode/codestyler dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .github/workflows/lint-check.yml | 2 +- .github/workflows/lint-fixer.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/lint-check.yml b/.github/workflows/lint-check.yml index f5481d1..d9ea97d 100644 --- a/.github/workflows/lint-check.yml +++ b/.github/workflows/lint-check.yml @@ -11,4 +11,4 @@ jobs: uses: actions/checkout@v3 - name: Checking PHP Syntax - uses: TheDragonCode/codestyler@v2.0.1 + uses: TheDragonCode/codestyler@v2.0.3 diff --git a/.github/workflows/lint-fixer.yml b/.github/workflows/lint-fixer.yml index 64a9e13..a648869 100644 --- a/.github/workflows/lint-fixer.yml +++ b/.github/workflows/lint-fixer.yml @@ -13,7 +13,7 @@ jobs: uses: actions/checkout@v3 - name: Checking PHP Syntax - uses: TheDragonCode/codestyler@v2.0.1 + uses: TheDragonCode/codestyler@v2.0.3 with: github_token: ${{ secrets.COMPOSER_TOKEN }} fix: true From 894274b513467d296cbf7668a9587d49b5a0e906 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Thu, 5 May 2022 12:21:26 +0900 Subject: [PATCH 5/8] Removed symfony 5.x components --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index c7f82c9..3e981cf 100644 --- a/composer.json +++ b/composer.json @@ -14,8 +14,8 @@ "ext-json": "*", "dragon-code/support": "^6.1", "friendsofphp/php-cs-fixer": "^3.8", - "symfony/console": "^5.0 || ^6.0", - "symfony/yaml": "^5.0 || ^6.0" + "symfony/console": "^6.0", + "symfony/yaml": "^6.0" }, "minimum-stability": "stable", "autoload": { From 4b4596452d8dd9282e1cd2e845c7b9c13959d159 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Thu, 5 May 2022 12:58:22 +0900 Subject: [PATCH 6/8] Fixed PHP versions compare and added version tests --- .github/workflows/phpunit.yml | 25 +++++ composer.json | 10 +- phpunit.xml | 22 +++++ src/Support/PhpVersion.php | 33 +++++-- tests/Fixtures/Support/PhpVersion.php | 22 +++++ tests/Support/PhpVersionTest.php | 137 ++++++++++++++++++++++++++ tests/TestCase.php | 9 ++ 7 files changed, 248 insertions(+), 10 deletions(-) create mode 100644 .github/workflows/phpunit.yml create mode 100644 phpunit.xml create mode 100644 tests/Fixtures/Support/PhpVersion.php create mode 100644 tests/Support/PhpVersionTest.php create mode 100644 tests/TestCase.php diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml new file mode 100644 index 0000000..c065767 --- /dev/null +++ b/.github/workflows/phpunit.yml @@ -0,0 +1,25 @@ +name: phpunit + +on: [ push, pull_request ] + +jobs: + build: + runs-on: ubuntu-latest + + name: PHP Unit + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + extensions: curl, mbstring, zip, pcntl, pdo, pdo_sqlite, iconv, json + coverage: none + + - name: Install dependencies + run: composer update --prefer-stable --prefer-dist --no-progress --no-interaction + + - name: Execute tests + run: sudo vendor/bin/phpunit --colors=always diff --git a/composer.json b/composer.json index 3e981cf..c63ba48 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,15 @@ "DragonCode\\CodeStyler\\": "src" } }, + "autoload-dev": { + "psr-4": { + "Tests\\": "tests" + } + }, "bin": [ "bin/codestyle" - ] + ], + "require-dev": { + "phpunit/phpunit": "^9.5" + } } diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..aa8d462 --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,22 @@ + + + + + ./tests + + + diff --git a/src/Support/PhpVersion.php b/src/Support/PhpVersion.php index 93456a1..27722b6 100644 --- a/src/Support/PhpVersion.php +++ b/src/Support/PhpVersion.php @@ -7,6 +7,7 @@ use DragonCode\Support\Concerns\Makeable; use DragonCode\Support\Facades\Application\Version; use DragonCode\Support\Facades\Helpers\Arr; +use DragonCode\Support\Facades\Helpers\Str; class PhpVersion { @@ -14,6 +15,8 @@ class PhpVersion public const DEFAULT = '8.1'; + public const MIN = '7.2'; + public function get(): string { if ($composer = $this->composer()) { @@ -25,24 +28,36 @@ public function get(): string protected function find(array $composer) { - $version = Arr::get($composer, 'require.php', Arr::get($composer, 'require-dev.php', '')); + preg_match_all('/\d\.\d/', (string) $this->getVersions($composer), $output); - preg_match_all('/\d\.\d/', $version, $output); + return Arr::of($output[0]) + ->map(fn (string $value) => $this->getMinVersion($value)) + ->unique() + ->sort() + ->values() + ->first(default: self::DEFAULT); + } - sort($output[0]); + protected function getVersions(array $composer, array $keys = ['require.php', 'require-dev.php']): ?string + { + foreach ($keys as $key) { + if ($versions = Arr::get($composer, $key)) { + return $versions; + } + } - $versions = Arr::of($output[0]) - ->filter(static fn (string $value) => Version::of($value)->gte('7.2')) - ->values() - ->toArray(); + return null; + } - return $versions[0] ?? self::DEFAULT; + protected function getMinVersion(string $version): string + { + return Version::of($version)->gt(self::MIN) ? self::MIN : $version; } protected function composer(): ?array { if ($path = realpath('./composer.json')) { - return file_exists($path) ? json_decode(file_get_contents($path), true) : null; + return Arr::ofFile($path)->toArray(); } return null; diff --git a/tests/Fixtures/Support/PhpVersion.php b/tests/Fixtures/Support/PhpVersion.php new file mode 100644 index 0000000..2003394 --- /dev/null +++ b/tests/Fixtures/Support/PhpVersion.php @@ -0,0 +1,22 @@ +composer = $values; + + return $this; + } + + protected function composer(): ?array + { + return $this->composer; + } +} diff --git a/tests/Support/PhpVersionTest.php b/tests/Support/PhpVersionTest.php new file mode 100644 index 0000000..d30fadc --- /dev/null +++ b/tests/Support/PhpVersionTest.php @@ -0,0 +1,137 @@ +setComposer([ + 'require' => [ + 'php' => '^8.0 || ^7.1', + 'ext-json' => '*', + 'foo/bar' => '^1.0', + ], + ])->get(); + + $this->assertSame('7.2', $helper); + } + + public function test72Dev() + { + $helper = PhpVersion::make()->setComposer([ + 'require-dev' => [ + 'php' => '^8.0 || ^7.1', + 'ext-json' => '*', + 'foo/bar' => '^1.0', + ], + ])->get(); + + $this->assertSame('7.2', $helper); + } + + public function test74() + { + $helper = PhpVersion::make()->setComposer([ + 'require' => [ + 'php' => '^8.0 || ^7.4', + 'ext-json' => '*', + 'foo/bar' => '^1.0', + ], + ])->get(); + + $this->assertSame('7.4', $helper); + } + + public function test74Dev() + { + $helper = PhpVersion::make()->setComposer([ + 'require-dev' => [ + 'php' => '^8.0 || ^7.4', + 'ext-json' => '*', + 'foo/bar' => '^1.0', + ], + ])->get(); + + $this->assertSame('7.4', $helper); + } + + public function test80() + { + $helper = PhpVersion::make()->setComposer([ + 'require' => [ + 'php' => '^8.0', + 'ext-json' => '*', + 'foo/bar' => '^1.0', + ], + ])->get(); + + $this->assertSame('8.0', $helper); + } + + public function test80Dev() + { + $helper = PhpVersion::make()->setComposer([ + 'require-dev' => [ + 'php' => '^8.0', + 'ext-json' => '*', + 'foo/bar' => '^1.0', + ], + ])->get(); + + $this->assertSame('8.0', $helper); + } + + public function test81() + { + $helper = PhpVersion::make()->setComposer([ + 'require' => [ + 'php' => '^8.1', + 'ext-json' => '*', + 'foo/bar' => '^1.0', + ], + ])->get(); + + $this->assertSame('8.1', $helper); + } + + public function test81Dev() + { + $helper = PhpVersion::make()->setComposer([ + 'require-dev' => [ + 'php' => '^8.1', + 'ext-json' => '*', + 'foo/bar' => '^1.0', + ], + ])->get(); + + $this->assertSame('8.1', $helper); + } + + public function testDefault() + { + $helper = PhpVersion::make()->setComposer([ + 'require' => [ + 'ext-json' => '*', + 'foo/bar' => '^1.0', + ], + ])->get(); + + $this->assertSame('8.1', $helper); + } + + public function testDefaultDev() + { + $helper = PhpVersion::make()->setComposer([ + 'require-dev' => [ + 'ext-json' => '*', + 'foo/bar' => '^1.0', + ], + ])->get(); + + $this->assertSame('8.1', $helper); + } +} diff --git a/tests/TestCase.php b/tests/TestCase.php new file mode 100644 index 0000000..690e86f --- /dev/null +++ b/tests/TestCase.php @@ -0,0 +1,9 @@ + Date: Thu, 5 May 2022 03:59:31 +0000 Subject: [PATCH 7/8] =?UTF-8?q?Update=20code-style=20=F0=9F=92=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Support/PhpVersion.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Support/PhpVersion.php b/src/Support/PhpVersion.php index 27722b6..bab4cc3 100644 --- a/src/Support/PhpVersion.php +++ b/src/Support/PhpVersion.php @@ -7,7 +7,6 @@ use DragonCode\Support\Concerns\Makeable; use DragonCode\Support\Facades\Application\Version; use DragonCode\Support\Facades\Helpers\Arr; -use DragonCode\Support\Facades\Helpers\Str; class PhpVersion { From 32d6fd141cd4ccaca8acddb0d070a35586a69360 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Thu, 5 May 2022 03:59:35 +0000 Subject: [PATCH 8/8] =?UTF-8?q?Normalize=20`composer.json`=20=F0=9F=91=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composer.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index c63ba48..c1c33f5 100644 --- a/composer.json +++ b/composer.json @@ -17,6 +17,9 @@ "symfony/console": "^6.0", "symfony/yaml": "^6.0" }, + "require-dev": { + "phpunit/phpunit": "^9.5" + }, "minimum-stability": "stable", "autoload": { "psr-4": { @@ -30,8 +33,5 @@ }, "bin": [ "bin/codestyle" - ], - "require-dev": { - "phpunit/phpunit": "^9.5" - } + ] }