diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f12fea87..0a9bb8df 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -15,7 +15,7 @@ jobs: php-version: [8.2,8.3] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 0 @@ -23,7 +23,46 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php-version }} - tools: composer:v1 + tools: composer:v2 + + - name: Define Hyvä Checkout repositories + run: | + composer config repositories.hyva-themes/hyva-checkout git git@gitlab.hyva.io:hyva-checkout/checkout.git + composer config repositories.hyva-themes/magento2-theme-module git git@gitlab.hyva.io:hyva-themes/magento2-theme-module.git + composer config repositories.hyva-themes/magento2-reset-theme git git@gitlab.hyva.io:hyva-themes/magento2-reset-theme.git + composer config repositories.hyva-themes/magento2-email-theme git git@gitlab.hyva.io:hyva-themes/magento2-email-module.git + composer config repositories.hyva-default-theme git git@gitlab.hyva.io:hyva-themes/magento2-default-theme.git + + - name: Configure SSH access to Hyvä Gitlab + env: + SSH_AUTH_SOCK: /tmp/ssh_agent.sock + HYVA_GITLAB_SSH_KEY: ${{ secrets.GITLAB_SSH_KEY }} + run: | + mkdir -p ~/.ssh + ssh-keyscan gitlab.hyva.io >> ~/.ssh/known_hosts + echo "${HYVA_GITLAB_SSH_KEY}" > ~/.ssh/hyva_id_rsa + chmod 600 ~/.ssh/hyva_id_rsa + ssh-agent -a ${SSH_AUTH_SOCK} > /dev/null + ssh-add ~/.ssh/hyva_id_rsa + + - name: Install the plugin + run: | + echo "{\"http-basic\":{\"repo.magento.com\":{\"username\":\"${MAGENTO_USERNAME}\",\"password\":\"${MAGENTO_PASSWORD}\"}}}" > auth.json + composer install --prefer-dist + env: + CI: true + SSH_AUTH_SOCK: /tmp/ssh_agent.sock + MAGENTO_USERNAME: ${{ secrets.MAGENTO_USERNAME }} + MAGENTO_PASSWORD: ${{ secrets.MAGENTO_PASSWORD }} + + - name: Code Sniffer + run: vendor/bin/phpcs . + + - name: Run PHPUnit + run: vendor/bin/phpunit --coverage-clover=build/clover.xml --log-junit=build/tests-log.xml -c Test/phpunit.xml Test/Unit + + - name: Fix code coverage paths + run: sed -i "s;`pwd`/;;g" build/*.xml - name: SonarCloud Scan if: ${{ env.SONAR_TOKEN }} diff --git a/Test/Unit/Magewire/Payment/Method/CreditCardTest.php b/Test/Unit/Magewire/Payment/Method/CreditCardTest.php index 6a058f1f..433d156d 100644 --- a/Test/Unit/Magewire/Payment/Method/CreditCardTest.php +++ b/Test/Unit/Magewire/Payment/Method/CreditCardTest.php @@ -244,11 +244,10 @@ public function testRefreshPropertiesThrowsException() private function setRefreshPropertiesCommonExpectations($quoteId) { - $this->session->expects($this->exactly(2)) - ->method('getQuote') + $this->session->method('getQuote') ->willReturn($this->quote); - $this->quote->expects($this->once()) + $this->quote->expects($this->exactly(2)) ->method('getShippingAddress'); $this->session->expects($this->once()) diff --git a/Test/Unit/Model/ConfigurationTest.php b/Test/Unit/Model/ConfigurationTest.php index 965707d4..74a0a15d 100644 --- a/Test/Unit/Model/ConfigurationTest.php +++ b/Test/Unit/Model/ConfigurationTest.php @@ -3,13 +3,13 @@ namespace Adyen\Hyva\Test\Unit\Model; use Adyen\Hyva\Model\Configuration; +use Adyen\Payment\Test\Unit\AbstractAdyenTestCase; use Magento\Checkout\Model\CompositeConfigProvider; use Magento\Framework\DataObjectFactory; use Psr\Log\LoggerInterface; use PHPUnit\Framework\MockObject\MockObject; -use PHPUnit\Framework\TestCase; -class ConfigurationTest extends TestCase +class ConfigurationTest extends AbstractAdyenTestCase { private Configuration $configuration; private CompositeConfigProvider|MockObject $configProvider; @@ -29,9 +29,7 @@ protected function setUp(): void $this->configProvider = $this->getMockBuilder(CompositeConfigProvider::class) ->disableOriginalConstructor() ->getMock(); - $this->dataObjectFactory = $this->getMockBuilder(DataObjectFactory::class) - ->disableOriginalConstructor() - ->getMock(); + $this->dataObjectFactory = $this->createGeneratedMock(DataObjectFactory::class, ['create']); $this->logger = $this->getMockBuilder(LoggerInterface::class) ->disableOriginalConstructor() ->getMock(); diff --git a/Test/Unit/Model/MethodListTest.php b/Test/Unit/Model/MethodListTest.php index ea1556d4..bcc4a178 100644 --- a/Test/Unit/Model/MethodListTest.php +++ b/Test/Unit/Model/MethodListTest.php @@ -3,14 +3,17 @@ namespace Adyen\Hyva\Test\Unit\Model; use Adyen\Hyva\Model\MethodList; +use Adyen\Hyva\Model\Ui\AdyenHyvaConfigProvider; +use Adyen\Payment\Test\Unit\AbstractAdyenTestCase; -class MethodListTest extends \PHPUnit\Framework\TestCase +class MethodListTest extends AbstractAdyenTestCase { private MethodList $methodList; protected function setUp(): void { - $this->methodList = new MethodList(); + $adyenHyvaConfigProviderMock = $this->createMock(AdyenHyvaConfigProvider::class); + $this->methodList = new MethodList($adyenHyvaConfigProviderMock, [], []); } public function testCollectAvailableMethodsReturnsEmptyArray(): void @@ -21,11 +24,6 @@ public function testCollectAvailableMethodsReturnsEmptyArray(): void public function testCollectAvailableMethodsReturnsCorrectMethods(): void { - $methods = ['method1', 'method2']; - $this->methodList = new MethodList($methods); - $this->assertIsArray($this->methodList->collectAvailableMethods()); - $this->assertCount(2, $this->methodList->collectAvailableMethods()); - $this->assertEquals($methods, $this->methodList->collectAvailableMethods()); } } diff --git a/Test/bootstrap.php b/Test/bootstrap.php new file mode 100644 index 00000000..a909098f --- /dev/null +++ b/Test/bootstrap.php @@ -0,0 +1,13 @@ + + */ + +require __DIR__.'/../vendor/autoload.php'; diff --git a/Test/phpunit.xml b/Test/phpunit.xml new file mode 100644 index 00000000..72ae6a7a --- /dev/null +++ b/Test/phpunit.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + . + + + + + + ../. + + + ../vendor + . + + + diff --git a/composer.json b/composer.json index a8ba315a..f230b020 100644 --- a/composer.json +++ b/composer.json @@ -9,6 +9,11 @@ "hyva-themes/magento2-default-theme": "^1.3", "hyva-themes/magento2-hyva-checkout": "^1.1" }, + "require-dev": { + "phpunit/phpunit": "~9.6.1", + "magento/magento-coding-standard": "*", + "squizlabs/php_codesniffer": "~3.8.0" + }, "autoload": { "files": [ "registration.php" @@ -16,5 +21,17 @@ "psr-4": { "Adyen\\Hyva\\": "" } + }, + "repositories": [ + { + "type": "composer", + "url": "https://repo.magento.com/" + } + ], + "config": { + "allow-plugins": { + "magento/composer-dependency-version-audit-plugin": true, + "dealerdirect/phpcodesniffer-composer-installer": true + } } } diff --git a/phpcs.xml b/phpcs.xml new file mode 100644 index 00000000..fb544e0d --- /dev/null +++ b/phpcs.xml @@ -0,0 +1,23 @@ + + + + vendor/* + . + + + + + *.js + + diff --git a/view/frontend/templates/payment/method-renderer/adyen-affirm-method.phtml b/view/frontend/templates/payment/method-renderer/adyen-affirm-method.phtml index 2b35a4c0..7de4321d 100644 --- a/view/frontend/templates/payment/method-renderer/adyen-affirm-method.phtml +++ b/view/frontend/templates/payment/method-renderer/adyen-affirm-method.phtml @@ -11,7 +11,7 @@ use Magento\Framework\View\Element\Template; ?>
-
+