From e7f91b69338d911f76b10eb14b09a9e18fec695d Mon Sep 17 00:00:00 2001 From: Adam Hall Date: Tue, 5 Jul 2022 14:37:07 +0930 Subject: [PATCH 1/6] Add oro bundle template github workflows --- .github/CODEOWNERS | 2 ++ .github/dependabot.yml | 7 ++++ .github/workflows/phpcs.yml | 44 +++++++++++++++++++++++ .github/workflows/phpstan.yml | 44 +++++++++++++++++++++++ .github/workflows/release.yml | 32 +++++++++++++++++ .github/workflows/unit_tests.yml | 32 +++++++++++++++++ .gitignore | 12 ++++++- RELEASE_NOTES.md | 3 ++ composer.json | 60 ++++++++++++++++++++++---------- phpcs.xml | 10 ++++++ phpstan.neon | 4 +++ phpunit.xml | 49 ++++++++++++++++++++++++++ 12 files changed, 279 insertions(+), 20 deletions(-) create mode 100644 .github/CODEOWNERS create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/phpcs.yml create mode 100644 .github/workflows/phpstan.yml create mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/unit_tests.yml create mode 100644 RELEASE_NOTES.md create mode 100644 phpcs.xml create mode 100644 phpstan.neon create mode 100644 phpunit.xml diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..bc4a2e0 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1,2 @@ +* AdamJHall aligent/oro-developers + diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..6bfb065 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,7 @@ +version: 2 + +updates: + - package-ecosystem: "composer" + directory: "/" + schedule: + interval: "weekly" \ No newline at end of file diff --git a/.github/workflows/phpcs.yml b/.github/workflows/phpcs.yml new file mode 100644 index 0000000..b623aaf --- /dev/null +++ b/.github/workflows/phpcs.yml @@ -0,0 +1,44 @@ +name: Code Style Checks + +on: [pull_request] + +jobs: + test: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: true + matrix: + os: [ubuntu-latest] + php: [8.0] + stability: [prefer-lowest, prefer-stable] + + name: PHP-${{ matrix.php }} - ${{ matrix.stability }} - ${{ matrix.os }} - PHPCS + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: "dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo" + coverage: none + + - name: Validate composer.json + run: composer validate + + - name: Cache Composer packages + id: composer-cache + uses: actions/cache@v2 + with: + path: vendor + key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-php- + + - name: Install dependencies + run: composer update --${{ matrix.stability }} --prefer-dist --no-interaction + + - name: Execute PHPCS + run: bin/phpcs \ No newline at end of file diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml new file mode 100644 index 0000000..c409b8b --- /dev/null +++ b/.github/workflows/phpstan.yml @@ -0,0 +1,44 @@ +name: Static analysis + +on: [pull_request] + +jobs: + test: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: true + matrix: + os: [ubuntu-latest] + php: [8.0] + stability: [prefer-lowest, prefer-stable] + + name: PHP-${{ matrix.php }} - ${{ matrix.stability }} - ${{ matrix.os }} - PHPStan + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: "dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo" + coverage: none + + - name: Validate composer.json + run: composer validate + + - name: Cache Composer packages + id: composer-cache + uses: actions/cache@v2 + with: + path: vendor + key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-php- + + - name: Install dependencies + run: composer update --${{ matrix.stability }} --prefer-dist --no-interaction + + - name: Execute PHPStan + run: bin/phpstan \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..d27e3be --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,32 @@ +on: + push: + # Sequence of patterns matched against refs/tags + tags: + - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10 + +name: Create Release + +jobs: + build: + name: Create Release + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Create Release + id: create_release + uses: softprops/action-gh-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.ref }} + name: Release ${{ github.ref }} + draft: false + prerelease: false + body_path: RELEASE_NOTES.md + + - name: Update Packagist + env: + API_TOKEN: ${{ secrets.PackagistApiToken }} + run: curl -XPOST -H'content-type:application/json' 'https://packagist.org/api/update-package?username=aligent&apiToken='$API_TOKEN -d'{"repository":{"url":"https://packagist.org/packages/aligent/oro-geo-detection"}}' diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml new file mode 100644 index 0000000..20db649 --- /dev/null +++ b/.github/workflows/unit_tests.yml @@ -0,0 +1,32 @@ +name: Tests + +on: [pull_request] + +jobs: + test: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: true + matrix: + os: [ubuntu-latest] + php: [8.0] + stability: [prefer-lowest, prefer-stable] + + name: PHP-${{ matrix.php }} - ${{ matrix.stability }} - ${{ matrix.os }} - PHPUnit + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: "dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo" + coverage: none + + - name: Install dependencies + run: composer update --${{ matrix.stability }} --prefer-dist --no-interaction + + - name: Execute tests + run: bin/phpunit \ No newline at end of file diff --git a/.gitignore b/.gitignore index 9f33dd5..6e9d31c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,12 @@ +# IDE +.idea + +# PHPUnit +.phpunit.result.cache + +# Composer +composer.lock vendor/ -.idea/ \ No newline at end of file + +# Binaries +bin/ \ No newline at end of file diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md new file mode 100644 index 0000000..a6b59d0 --- /dev/null +++ b/RELEASE_NOTES.md @@ -0,0 +1,3 @@ +### 4.2.3 Release + +- Added Github Workflows (PHPCS, PHPStan and PHPUnit) \ No newline at end of file diff --git a/composer.json b/composer.json index 1256bf7..97eb9f6 100644 --- a/composer.json +++ b/composer.json @@ -1,22 +1,44 @@ { - "name": "aligent/oro-geo-detection", - "description": "A Bundle for OroCommerce to provide application level geo-detection using the maxmind db", - "type": "library", - "license": "GPL-3.0", - "version": "4.2.0", - "authors": [ - { - "name": "Adam Hall", - "email": "adam.hall@aligent.com.au" - } - ], - "require": { - "php": "~7.4.14 || ~8.0.0", - "oro/commerce": "^4.2", - "geoip2/geoip2": "~2.0", - "guzzlehttp/guzzle": "^7.2" - }, - "autoload": { - "psr-4": { "Aligent\\GeoDetectionBundle\\": "./src/" } + "name": "aligent/oro-geo-detection", + "description": "A Bundle for OroCommerce to provide application level geo-detection using the maxmind db", + "type": "library", + "license": "GPL-3.0", + "authors": [ + { + "name": "Adam Hall", + "email": "adam.hall@aligent.com.au" } + ], + "repositories": { + "oro": { + "type": "composer", + "url": "https://packagist.orocrm.com" + } + }, + "autoload": { + "psr-4": { + "Aligent\\GeoDetectionBundle\\": "./src/" + } + }, + "config": { + "bin-dir": "bin" + }, + "minimum-stability": "dev", + "prefer-stable": true, + "require": { + "php": "~7.4.14 || ~8.0.0", + "oro/commerce": "^4.2", + "geoip2/geoip2": "~2.0", + "guzzlehttp/guzzle": "^7.2" + }, + "require-dev": { + "phpunit/phpunit": "^9.5", + "phpstan/phpstan": "^1.7", + "phpmd/phpmd": "^2.12", + "friendsofphp/php-cs-fixer": "~2.18.2 || ~3.1.0", + "nelmio/alice": "~3.8.0 || ~3.9.0", + "theofidry/alice-data-fixtures": "~1.4.0 || ~1.5.0", + "symfony/phpunit-bridge": "~4.4.24 || ~6.1.0", + "squizlabs/php_codesniffer": "^3.6" + } } diff --git a/phpcs.xml b/phpcs.xml new file mode 100644 index 0000000..a486453 --- /dev/null +++ b/phpcs.xml @@ -0,0 +1,10 @@ + + + The PSR-2 coding standard. + + + + + src/ + *\.js + \ No newline at end of file diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..b999b4e --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,4 @@ +parameters: + level: 6 + paths: + - src \ No newline at end of file diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..80887e1 --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,49 @@ + + + + + + + + src/Tests/Unit + + + + + + + + + + + + + + + + + src + + + From 6d6a79bd2b8f37b39a1b8cba3fbf050266775d15 Mon Sep 17 00:00:00 2001 From: Adam Hall Date: Tue, 5 Jul 2022 14:37:38 +0930 Subject: [PATCH 2/6] Autofix phpcs issues --- src/Providers/GeoDetectionProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Providers/GeoDetectionProvider.php b/src/Providers/GeoDetectionProvider.php index 6a59cb0..7a2fe67 100644 --- a/src/Providers/GeoDetectionProvider.php +++ b/src/Providers/GeoDetectionProvider.php @@ -94,4 +94,4 @@ public function getClientCountry(): ?string return $country; } -} \ No newline at end of file +} From 419d996c01c4d50d4cf93dec1747f07543e5055b Mon Sep 17 00:00:00 2001 From: Adam Hall Date: Tue, 5 Jul 2022 14:42:43 +0930 Subject: [PATCH 3/6] Set phpstan to level 1 until next upgrade --- phpstan.neon | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpstan.neon b/phpstan.neon index b999b4e..672e0fa 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,4 +1,4 @@ parameters: - level: 6 + level: 1 paths: - src \ No newline at end of file From a3d16a3223ca15910195e1f16266a74e26ed0c6c Mon Sep 17 00:00:00 2001 From: Adam Hall Date: Tue, 5 Jul 2022 14:44:49 +0930 Subject: [PATCH 4/6] Fix codeowners --- .github/CODEOWNERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index bc4a2e0..1f23847 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1,2 +1,2 @@ -* AdamJHall aligent/oro-developers +* @AdamJHall @aligent/oro-developers From 576f684aa11859e8a22892732b7156d86e89ee79 Mon Sep 17 00:00:00 2001 From: Adam Hall Date: Tue, 5 Jul 2022 15:01:08 +0930 Subject: [PATCH 5/6] Add basic DI test for workflow --- .../AligentGeoDetectionExtensionTest.php | 42 +++++++++++++++ .../DependencyInjection/ConfigurationTest.php | 53 +++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 src/Tests/Unit/DependencyInjection/AligentGeoDetectionExtensionTest.php create mode 100644 src/Tests/Unit/DependencyInjection/ConfigurationTest.php diff --git a/src/Tests/Unit/DependencyInjection/AligentGeoDetectionExtensionTest.php b/src/Tests/Unit/DependencyInjection/AligentGeoDetectionExtensionTest.php new file mode 100644 index 0000000..fb8b387 --- /dev/null +++ b/src/Tests/Unit/DependencyInjection/AligentGeoDetectionExtensionTest.php @@ -0,0 +1,42 @@ + + * @copyright 2022 Aligent Consulting. + * @license + * @link http://www.aligent.com.au/ + */ +namespace Aligent\GeoDetectionBundle\Tests\Unit\DependencyInjection; + + +use Aligent\GeoDetectionBundle\DependencyInjection\AligentGeoDetectionExtension; +use Oro\Bundle\TestFrameworkBundle\Test\DependencyInjection\ExtensionTestCase; + +class AligentGeoDetectionExtensionTest extends ExtensionTestCase +{ + public function testLoad(): void + { + $this->loadExtension(new AligentGeoDetectionExtension(), ['database' => []]); + + // Services + $expectedDefinitions = [ + 'aligent_geo_detection.form.type.geo_detection_countries_collection', + 'aligent_geo_detection.form.type.geo_detection_country', + 'aligent_geo_detection.form.type.geo_detection_system_config', + 'aligent_geo_detection.reader', + 'aligent_geo_detection.layout_context_configurator.geo_detection', + 'aligent_geo_detection.provider.redirection_config_provider', + 'aligent_geo_detection.provider.geo_detection', + 'aligent_geo_detection.cache', + 'aligent_geo_detection.layout.block_type.redirection_block', + 'aligent_geo_detection.layout.block_type.site_select_block', + 'aligent_geo_detection.layout.data_provider.redirection_provider', + 'aligent_geo_detection.cache.warmer', + ]; + $this->assertDefinitionsLoaded($expectedDefinitions); + + $expectedExtensionConfigs = ['aligent_geo_detection']; + $this->assertExtensionConfigsLoaded($expectedExtensionConfigs); + } +} diff --git a/src/Tests/Unit/DependencyInjection/ConfigurationTest.php b/src/Tests/Unit/DependencyInjection/ConfigurationTest.php new file mode 100644 index 0000000..4eac324 --- /dev/null +++ b/src/Tests/Unit/DependencyInjection/ConfigurationTest.php @@ -0,0 +1,53 @@ + + * @copyright 2022 Aligent Consulting. + * @license + * @link http://www.aligent.com.au/ + */ +namespace Aligent\GeoDetectionBundle\Tests\Unit\DependencyInjection; + +use Aligent\GeoDetectionBundle\DependencyInjection\Configuration; +use Symfony\Component\Config\Definition\Processor; + +class ConfigurationTest extends \PHPUnit\Framework\TestCase +{ + public function testGetConfigTreeBuilder(): void + { + $configuration = new Configuration(); + $builder = $configuration->getConfigTreeBuilder(); + $this->assertInstanceOf('Symfony\Component\Config\Definition\Builder\TreeBuilder', $builder); + + $root = $builder->buildTree(); + $this->assertInstanceOf('Symfony\Component\Config\Definition\ArrayNode', $root); + $this->assertEquals('aligent_geo_detection', $root->getName()); + } + + public function testProcessConfiguration(): void + { + $configuration = new Configuration(); + $processor = new Processor(); + + $expected = [ + 'settings' => [ + 'resolved' => true, + 'enabled' => [ + 'value' => false, + 'scope' => 'app' + ], + 'enabled_countries' => [ + 'value' => [], + 'scope' => 'app' + ], + 'database_download_url' => [ + 'value' => Configuration::INITIAL_DOWNLOAD_URL_VALUE, + 'scope' => 'app' + ] + ], + ]; + + $this->assertEquals($expected, $processor->processConfiguration($configuration, [])); + } +} From 6f77d1254e97c0305ad2d7636be8fa1a4cf94628 Mon Sep 17 00:00:00 2001 From: Adam Hall Date: Tue, 5 Jul 2022 15:08:23 +0930 Subject: [PATCH 6/6] Fix phpcs and failing test --- .../DependencyInjection/AligentGeoDetectionExtensionTest.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Tests/Unit/DependencyInjection/AligentGeoDetectionExtensionTest.php b/src/Tests/Unit/DependencyInjection/AligentGeoDetectionExtensionTest.php index fb8b387..d64499f 100644 --- a/src/Tests/Unit/DependencyInjection/AligentGeoDetectionExtensionTest.php +++ b/src/Tests/Unit/DependencyInjection/AligentGeoDetectionExtensionTest.php @@ -9,7 +9,6 @@ */ namespace Aligent\GeoDetectionBundle\Tests\Unit\DependencyInjection; - use Aligent\GeoDetectionBundle\DependencyInjection\AligentGeoDetectionExtension; use Oro\Bundle\TestFrameworkBundle\Test\DependencyInjection\ExtensionTestCase; @@ -17,7 +16,7 @@ class AligentGeoDetectionExtensionTest extends ExtensionTestCase { public function testLoad(): void { - $this->loadExtension(new AligentGeoDetectionExtension(), ['database' => []]); + $this->loadExtension(new AligentGeoDetectionExtension(), ['aligent_geo_detection' => ['database' => '']]); // Services $expectedDefinitions = [