From 2e20204737ee26a5e7dd79de17dd5de8dbbc2826 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Votava?= Date: Wed, 26 Mar 2025 16:01:49 +0100 Subject: [PATCH 1/4] Update dependencies, testing workflows, and code quality checks Upgraded various dependencies, enhanced syntax consistency, and adjusted workflows for PHP versions 8.1-8.4. Improved documentation configuration, reformatted code for PHPStan compatibility, and replaced deprecated functions. Introduced `sphinx-design` extension and adjusted testing setup for unit tests and code analysis. --- .github/dependabot.yml | 4 ++-- .github/workflows/code_analyse.yml | 33 +++++++++++++++--------------- .github/workflows/unit_tests.yml | 16 +++++++++------ composer.json | 6 +++--- docs/conf.py | 19 ++++++++--------- docs/usage.rst | 4 ++-- phpstan.neon | 1 - requirements.txt | 5 +++-- src/Components/GPWebPayControl.php | 23 +++++---------------- tests/GPWebPayTestCase.php | 6 +++--- tests/bootstrap.php | 8 +------- 11 files changed, 54 insertions(+), 71 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 0227f01..571ad71 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -3,8 +3,8 @@ updates: - package-ecosystem: composer directory: "/" schedule: - interval: daily - open-pull-requests-limit: 10 + interval: monthly + open-pull-requests-limit: 5 ignore: - dependency-name: pixidos/coding-standards versions: diff --git a/.github/workflows/code_analyse.yml b/.github/workflows/code_analyse.yml index faa7402..387cfc6 100644 --- a/.github/workflows/code_analyse.yml +++ b/.github/workflows/code_analyse.yml @@ -2,27 +2,28 @@ name: Code Analyse on: [push, pull_request] jobs: - unit_tests: + code_quality: name: GPWebPay-core (PHP ${{ matrix.php-versions }}) runs-on: ubuntu-latest strategy: fail-fast: false matrix: - php-versions: ['8.0', '8.1', '8.2'] + php-versions: [ '8.1', '8.2', '8.3', '8.4' ] steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Setup PHP, with composer and extensions - uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php - with: - php-version: ${{ matrix.php-versions }} - extensions: openssl, mbstring, json, intl, iconv, xml, tokenizer - coverage: none #optional - - name: Composer dependencies - uses: "ramsey/composer-install@v1" + - name: Checkout + uses: actions/checkout@v4 + - name: Setup PHP, with composer and extensions + uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php + with: + php-version: ${{ matrix.php-versions }} + extensions: openssl + coverage: none #optional + tools: composer:v2 + - name: Composer dependencies + uses: "ramsey/composer-install@v3" - - name: Run Codestyle chceck - run: php vendor/bin/phpcs -p + - name: Run Codestyle chceck + run: php vendor/bin/phpcs -p - - name: Run PHPStan - run: php vendor/bin/phpstan analyse + - name: Run PHPStan + run: php vendor/bin/phpstan analyse diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml index f4beb20..98c68e4 100644 --- a/.github/workflows/unit_tests.yml +++ b/.github/workflows/unit_tests.yml @@ -8,23 +8,27 @@ jobs: strategy: fail-fast: false matrix: - php-versions: [ '8.0', '8.1', '8.2' ] + php-versions: [ '8.1', '8.2', '8.3', '8.4' ] steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Setup PHP, with composer and extensions uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php with: php-version: ${{ matrix.php-versions }} - extensions: openssl, mbstring, json, intl, iconv, xml, tokenizer + extensions: openssl coverage: xdebug #optional + tools: composer:v2 + - name: Composer dependencies - uses: "ramsey/composer-install@v1" + uses: "ramsey/composer-install@v3" - name: Run Tests - run: vendor/bin/tester -p phpdbg tests -s -C --coverage ./coverage.xml --coverage-src ./src + run: php vendor/bin/phpunit --coverage-clover=coverage.xml - name: Upload Codecov - uses: "codecov/codecov-action@v1" + uses: "codecov/codecov-action@v5" with: + token: ${{ secrets.CODECOV_TOKEN }} files: ./coverage.xml + slug: Pixidos/GPWebpay diff --git a/composer.json b/composer.json index 5fd23b5..5d987f2 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,7 @@ "nette/application": "^v3.1 || ^v4.0", "nette/utils": "^4.0", "latte/latte": "^v3.0", - "pixidos/gpwebpay-core": "~2.2", + "pixidos/gpwebpay-core": "~2.4", "nette/bootstrap": "^3.1" }, "require-dev": { @@ -37,8 +37,8 @@ "nette/caching": "^3.0", "nette/finder": "^3.0", "nette/tester": "^2.4", - "pixidos/coding-standards": "^1.2.2", - "phpstan/phpstan-nette": "^1.2.3", + "pixidos/coding-standards": "^2.0.0", + "phpstan/phpstan-nette": "^2.0.3", "roave/security-advisories": "dev-master" }, "autoload": { diff --git a/docs/conf.py b/docs/conf.py index 615a931..581ac6e 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -27,7 +27,7 @@ def get_version(): if os.environ.get('READTHEDOCS') == 'True': return os.environ.get('READTHEDOCS_VERSION') - pipe = Popen('git branch | grep \*', stdout=PIPE, shell=True, universal_newlines=True) + pipe = Popen(r'git branch | grep \*', stdout=PIPE, shell=True, universal_newlines=True) version = pipe.stdout.read() if version: @@ -45,7 +45,7 @@ def get_version(): # -- Project information ----------------------------------------------------- project = u'GPWebPay' -copyright = u'2020, Ondra Votava' +copyright = '%Y, Ondra Votava' author = u'Ondra Votava' epub_author = u'Ondra Votava' @@ -65,8 +65,10 @@ def get_version(): # ones. extensions = [ 'sphinx_rtd_theme', + 'sphinx_design', ] + # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates'] @@ -84,7 +86,7 @@ def get_version(): # # This is also used if you do content translation via gettext catalogs. # Usually you set "language" from the command line for these cases. -language = None +language = 'en' # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. @@ -100,7 +102,7 @@ def get_version(): # a list of builtin themes. # html_theme = 'sphinx_rtd_theme' -html_title = "Pixidos\GPWebPay %s Manual" % get_version() +html_title = "Pixidos\\GPWebPay %s Manual" % get_version() # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the @@ -110,16 +112,11 @@ def get_version(): on_rtd = os.environ.get('READTHEDOCS', None) == 'True' if not on_rtd: import sphinx_rtd_theme - html_theme_path = [sphinx_rtd_theme.get_html_theme_path()] html_theme_options = { - 'analytics_id': 'UA-157707836-2', # Provided by Google in your dashboard 'logo_only': False, - 'display_version': True, 'prev_next_buttons_location': 'bottom', 'style_external_links': False, - #'style_nav_header_background': 'red', - # Toc options 'collapse_navigation': False, 'sticky_navigation': True, 'navigation_depth': 4, @@ -232,5 +229,5 @@ def get_version(): def setup(app): - app.add_stylesheet('css/custom.css') - app.add_stylesheet('css/highlight.css') + app.add_css_file('css/custom.css') + app.add_css_file('css/highlight.css') diff --git a/docs/usage.rst b/docs/usage.rst index b3edc69..4e3d72f 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -17,7 +17,7 @@ Example: use Pixidos\GPWebPay\Enum\Currency as CurrencyEnum; use Pixidos\GPWebPay\Exceptions\GPWebPayException; use Pixidos\GPWebPay\Factory\ResponseFactory; - use Pixidos\GPWebPay\Param\Amount; + use Pixidos\GPWebPay\Param\AmountInPennies; use Pixidos\GPWebPay\Param\Currency; use Pixidos\GPWebPay\Param\OrderNumber; use Pixidos\GPWebPay\Param\ResponseUrl; @@ -55,7 +55,7 @@ Example: { $operation = new Operation( new OrderNumber(time()), - new Amount(1000), + new AmountInPennies(100000), new Currency(CurrencyEnum::CZK()), 'czk', // leave empty or null for default key new ResponseUrl($this->link('//Payment:processResponse')) // you can setup by config responseUrl: diff --git a/phpstan.neon b/phpstan.neon index 7e6b9b6..d4e6d42 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -8,7 +8,6 @@ parameters: - tests/bootstrap.php paths: - src - - tests level: max inferPrivatePropertyTypeFromConstructor: true reportUnmatchedIgnoredErrors: false diff --git a/requirements.txt b/requirements.txt index c2b5b2f..f227a02 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ -Sphinx==1.8.5 -sphinx_rtd_theme==0.4.3 +sphinx==8.2.3 +sphinx_rtd_theme>=1.0.0 +sphinx-design>=0.4.1 \ No newline at end of file diff --git a/src/Components/GPWebPayControl.php b/src/Components/GPWebPayControl.php index 685b442..e901a94 100644 --- a/src/Components/GPWebPayControl.php +++ b/src/Components/GPWebPayControl.php @@ -25,25 +25,14 @@ class GPWebPayControl extends UI\Control { /** - * @var Closure[], signature: function(GPWebPayControl $control) + * @var array */ public array $onCheckout = []; - - /** - * @var OperationInterface $operation - */ private OperationInterface $operation; - private ?string $templateFile; - /** - * @var RequestFactory - */ - private $requestFactory; + private string|null $templateFile = null; + private RequestFactory $requestFactory; + - /** - * @param OperationInterface $operation - * @param RequestFactory $requestFactory - * - */ public function __construct(OperationInterface $operation, RequestFactory $requestFactory) { $this->operation = $operation; @@ -65,9 +54,7 @@ public function handleCheckout(): void $presenter->redirectUrl($url); } - /** - * @param string $templateFile - */ + public function setTemplateFile(string $templateFile): void { $this->templateFile = $templateFile; diff --git a/tests/GPWebPayTestCase.php b/tests/GPWebPayTestCase.php index dba8ec4..ab61689 100644 --- a/tests/GPWebPayTestCase.php +++ b/tests/GPWebPayTestCase.php @@ -24,9 +24,9 @@ abstract class GPWebPayTestCase extends TestCase { - protected ?Presenter $presenter; + protected ?Presenter $presenter = null; - private ?Container $container; + private ?Container $container = null; /** * @return Container @@ -50,7 +50,7 @@ public function getContainer(): Container protected function prepareContainer(string $configNeon): Container { $config = new Nette\Bootstrap\Configurator(); - $config->setTempDirectory(TEMP_DIR); + $config->setTempDirectory(TEMP_DIR); //phpstan-ignore-line $config->addStaticParameters(['container' => ['class' => 'SystemContainer_' . md5(TEMP_DIR)]]); $config->addConfig(sprintf(__DIR__ . '/config/nette-reset.neon')); GPWebPayExtension::register($config); diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 99d0fb4..4e4cdf7 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -20,13 +20,7 @@ Helpers::purge(TEMP_DIR); -$_SERVER = array_intersect_key($_SERVER, array_flip([ - 'PHP_SELF', 'SCRIPT_NAME', 'SERVER_ADDR', 'SERVER_SOFTWARE', 'HTTP_HOST', 'DOCUMENT_ROOT', 'OS', 'argc', 'argv'])); -$_SERVER['REQUEST_TIME'] = 1234567890; -$_ENV = $_GET = $_POST = []; - - function run(Tester\TestCase $testCase): void { - $testCase->run(isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : null); + $testCase->run(); } From 9068f824a6349b6b8baa61da560879f4b8c03caa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Votava?= Date: Wed, 26 Mar 2025 16:04:09 +0100 Subject: [PATCH 2/4] Update dependencies, testing workflows, and code quality checks Upgraded various dependencies, enhanced syntax consistency, and adjusted workflows for PHP versions 8.1-8.4. Improved documentation configuration, reformatted code for PHPStan compatibility, and replaced deprecated functions. Introduced `sphinx-design` extension and adjusted testing setup for unit tests and code analysis. --- .github/workflows/unit_tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml index 98c68e4..45a24cf 100644 --- a/.github/workflows/unit_tests.yml +++ b/.github/workflows/unit_tests.yml @@ -24,7 +24,7 @@ jobs: uses: "ramsey/composer-install@v3" - name: Run Tests - run: php vendor/bin/phpunit --coverage-clover=coverage.xml + run: vendor/bin/tester -p phpdbg tests -s -C --coverage ./coverage.xml --coverage-src ./src - name: Upload Codecov uses: "codecov/codecov-action@v5" From 83b4cafe70d8b95180c50406dca75d4539ca42bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Votava?= Date: Wed, 26 Mar 2025 17:12:06 +0100 Subject: [PATCH 3/4] Refactor GPWebPay tests and improve configuration handling Updated test assertions and parameters to align with recent changes, including the use of AmountInPennies and refined default gateway logic. Enhanced DI extension to automatically set 'depositFlag' when missing in the configuration. Adjusted CI workflow to include necessary PHP extensions and simplified the test runner command. --- .github/workflows/unit_tests.yml | 4 ++-- docs/configuration.rst | 2 +- src/DI/GPWebPayExtension.php | 23 ++++++++++++++++++++++- tests/Components/GPWebPayControlTest.php | 4 ++++ tests/DI/GPWebPayExtensionTest.php | 3 ++- tests/GPWebPayTestCase.php | 2 +- tests/TestPresenter.php | 17 +++++++---------- 7 files changed, 39 insertions(+), 16 deletions(-) diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml index 45a24cf..6f66576 100644 --- a/.github/workflows/unit_tests.yml +++ b/.github/workflows/unit_tests.yml @@ -16,7 +16,7 @@ jobs: uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php with: php-version: ${{ matrix.php-versions }} - extensions: openssl + extensions: openssl, mbstring, json, intl, iconv, xml, tokenizer coverage: xdebug #optional tools: composer:v2 @@ -24,7 +24,7 @@ jobs: uses: "ramsey/composer-install@v3" - name: Run Tests - run: vendor/bin/tester -p phpdbg tests -s -C --coverage ./coverage.xml --coverage-src ./src + run: vendor/bin/tester tests -s -C --coverage ./coverage.xml --coverage-src ./src - name: Upload Codecov uses: "codecov/codecov-action@v5" diff --git a/docs/configuration.rst b/docs/configuration.rst index 8396af8..d08acb2 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -114,7 +114,7 @@ Single gateway url: #example: https://test.3dsecure.gpwebpay.com/unicredit/order.do merchantNumber: responseUrl: #optional you can set in Control - depositFlag: 1 #optional you can set in Operation. Can set 1 or 0. Default is 1 + depositFlag: 1 #Can set 1 or 0. Default is 1 and you can rewrite in Operation .. _configuration.example.multiple_gateways: diff --git a/src/DI/GPWebPayExtension.php b/src/DI/GPWebPayExtension.php index c47fe7a..25fa01c 100644 --- a/src/DI/GPWebPayExtension.php +++ b/src/DI/GPWebPayExtension.php @@ -38,9 +38,30 @@ public function loadConfiguration(): void $config = (array)$config; } + + if (array_key_exists('privateKey', $config)) { + // single config + if (!array_key_exists('depositFlag', $config)) { + $config['depositFlag'] = 1; + } + } else { + foreach ($config as $key => $value) { + if (!is_array($value)) { + continue; + } + if (!array_key_exists('privateKey', $value)) { + continue; + } + if (!array_key_exists('depositFlag', $value)) { + $value['depositFlag'] = 1; + $config[$key] = $value ; + } + } + } + $builder = $this->getContainerBuilder(); - $defaultGateway = 'czk'; + $defaultGateway = 'default'; if (array_key_exists(self::GATEWAY_KEY, $config)) { $defaultGateway = $config[self::GATEWAY_KEY]; unset($config[self::GATEWAY_KEY]); diff --git a/tests/Components/GPWebPayControlTest.php b/tests/Components/GPWebPayControlTest.php index 47b9b0c..f0f9b3f 100644 --- a/tests/Components/GPWebPayControlTest.php +++ b/tests/Components/GPWebPayControlTest.php @@ -22,7 +22,9 @@ * @author Ondra Votava */ +// phpcs:disable require_once __DIR__ . '/../bootstrap.php'; +// phpcs:enable class GPWebPayControlTest extends GPWebPayTestCase { @@ -93,4 +95,6 @@ private function createControl(): GPWebPayControl } } +// phpcs:disable (new GPWebPayControlTest())->run(); +// phpcs:enable \ No newline at end of file diff --git a/tests/DI/GPWebPayExtensionTest.php b/tests/DI/GPWebPayExtensionTest.php index a838f9b..cc08ef3 100644 --- a/tests/DI/GPWebPayExtensionTest.php +++ b/tests/DI/GPWebPayExtensionTest.php @@ -65,7 +65,8 @@ public function testMultipleSettingCreated(): void /** @var PaymentConfigProvider $paymentConfig */ $paymentConfig = $container->getByType(PaymentConfigProvider::class); - Assert::same('123456789', (string)$paymentConfig->getMerchantNumber($paymentConfig->getDefaultGateway())); + Assert::same('czk', $paymentConfig->getDefaultGateway()); + Assert::same('123456789', (string)$paymentConfig->getMerchantNumber()); Assert::same('123456789', (string)$paymentConfig->getMerchantNumber('czk')); Assert::same('123456780', (string)$paymentConfig->getMerchantNumber('eur')); } diff --git a/tests/GPWebPayTestCase.php b/tests/GPWebPayTestCase.php index ab61689..9d7c668 100644 --- a/tests/GPWebPayTestCase.php +++ b/tests/GPWebPayTestCase.php @@ -66,7 +66,7 @@ protected function usePresenter(string $name): void $presenterFactory = $container->getByType(IPresenterFactory::class); $presenter = $presenterFactory->createPresenter($name); if ($presenter instanceof Presenter) { - $presenter->invalidLinkMode = $presenter::INVALID_LINK_EXCEPTION; + $presenter->invalidLinkMode = $presenter::InvalidLinkException; $presenter->autoCanonicalize = false; // force the name to the presenter $refl = new ReflectionProperty(Component::class, 'name'); diff --git a/tests/TestPresenter.php b/tests/TestPresenter.php index 4d7bcf3..584019d 100644 --- a/tests/TestPresenter.php +++ b/tests/TestPresenter.php @@ -13,6 +13,7 @@ use Pixidos\GPWebPay\Enum\Currency as CurrencyEnum; use Pixidos\GPWebPay\Exceptions\InvalidArgumentException; use Pixidos\GPWebPay\Param\Amount; +use Pixidos\GPWebPay\Param\AmountInPennies; use Pixidos\GPWebPay\Param\Currency; use Pixidos\GPWebPay\Param\OrderNumber; use Pixidos\GPWebPay\Param\ResponseUrl; @@ -26,11 +27,11 @@ class TestPresenter extends Presenter { public const ORDER_NUMBER = '123456'; - public const GATEWAY = 'czk'; + public const RESPONSE_URL = 'http://test.com'; - private $gpWebPayControlFactory; + private GPWebPayControlFactory $gpWebPayControlFactory; public function __construct(GPWebPayControlFactory $controlFactory) { @@ -48,9 +49,6 @@ public function renderFake(): void $this->sendResponse($response); } - /** - * @return GPWebPayControl - */ protected function createComponentPayControl(): GPWebPayControl { $control = $this->gpWebPayControlFactory->create(self::createOperation()); @@ -65,11 +63,10 @@ protected function createComponentPayControl(): GPWebPayControl public static function createOperation(): Operation { return new Operation( - new OrderNumber(self::ORDER_NUMBER), - new Amount(1000), - new Currency(CurrencyEnum::CZK()), - self::GATEWAY, - new ResponseUrl(self::RESPONSE_URL) + orderNumber: new OrderNumber(self::ORDER_NUMBER), + amount: new AmountInPennies(100000), + currency: new Currency(CurrencyEnum::CZK()), + responseUrl: new ResponseUrl(self::RESPONSE_URL) ); } } From 741698f2a3b37447c6b23da544a231bb86da7293 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Votava?= Date: Wed, 26 Mar 2025 17:19:27 +0100 Subject: [PATCH 4/4] Move `nette/bootstrap` to `require-dev` The `nette/bootstrap` package is now categorized as a development dependency instead of a production requirement. This change ensures a clearer distinction between production and development requirements in the `composer.json` file. --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 5d987f2..e2eee4a 100644 --- a/composer.json +++ b/composer.json @@ -29,10 +29,10 @@ "nette/application": "^v3.1 || ^v4.0", "nette/utils": "^4.0", "latte/latte": "^v3.0", - "pixidos/gpwebpay-core": "~2.4", - "nette/bootstrap": "^3.1" + "pixidos/gpwebpay-core": "~2.4" }, "require-dev": { + "nette/bootstrap": "^3.1", "nette/http": "^3.0", "nette/caching": "^3.0", "nette/finder": "^3.0",