diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..1f23847 --- /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..672e0fa --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,4 @@ +parameters: + level: 1 + 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 + + + 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 +} diff --git a/src/Tests/Unit/DependencyInjection/AligentGeoDetectionExtensionTest.php b/src/Tests/Unit/DependencyInjection/AligentGeoDetectionExtensionTest.php new file mode 100644 index 0000000..d64499f --- /dev/null +++ b/src/Tests/Unit/DependencyInjection/AligentGeoDetectionExtensionTest.php @@ -0,0 +1,41 @@ + + * @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(), ['aligent_geo_detection' => ['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, [])); + } +}