From a4262963e1ba5995a55ae8490203a83c8b524df3 Mon Sep 17 00:00:00 2001 From: Mikel Martin Date: Tue, 9 Jan 2024 13:19:15 +0100 Subject: [PATCH] Added an integration test that passes --- .github/workflows/main.yml | 55 +++++++++---------- .../CreateOrderRequestBuilderTest.php | 20 ++++--- Test/_files/sequra_configuration.php | 55 +++++++++++++++++++ 3 files changed, 93 insertions(+), 37 deletions(-) create mode 100644 Test/_files/sequra_configuration.php diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 685391e..aea8c66 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -58,38 +58,37 @@ jobs: with: path: magento/app/code/Sequra/Core - - uses: "shivammathur/setup-php@v2" - with: - php-version: "8.2" + # - uses: "shivammathur/setup-php@v2" + # with: + # php-version: "8.2" - - name: 'Alternative unit test' - working-directory: magento - env: - COMPOSER_AUTH: ${{ steps.composer_auth.outputs.auth }} - run: | - rm -rf app/code/Sequra/Core - vendor/bin/composer config minimum-stability dev - vendor/bin/composer config repositories.sequra/magento2-core vcs git@github.com:sequra/magento2-core.git - vendor/bin/composer require sequra/magento2-core:"dev-${{ steps.extract_branch.outputs.branch }}" --ignore-platform-reqs - vendor/bin/phpunit --bootstrap app/bootstrap.php vendor/sequra/magento2-core/Test/Unit + # - name: 'Alternative unit test' + # working-directory: magento + # env: + # COMPOSER_AUTH: ${{ steps.composer_auth.outputs.auth }} + # run: | + # rm -rf app/code/Sequra/Core + # vendor/bin/composer config minimum-stability dev + # vendor/bin/composer config repositories.sequra/magento2-core vcs git@github.com:sequra/magento2-core.git + # vendor/bin/composer require sequra/magento2-core:"dev-${{ steps.extract_branch.outputs.branch }}" --ignore-platform-reqs + # vendor/bin/phpunit --bootstrap app/bootstrap.php vendor/sequra/magento2-core/Test/Unit - - name: 'launch magento2 unit test' - if: always() - uses: MAD-I-T/magento-actions@v3.25 - env: - COMPOSER_AUTH: ${{ steps.composer_auth.outputs.auth }} - with: - process: 'unit-test' - unit_test_subset_path: 'vendor/sequra/magento2-core/Test/Unit' - override_settings: 1 - magento_version: ${{ matrix.magento_version }} - - - name: 'debug' - run: ls -l magento/vendor/sequra + # - name: 'launch magento2 unit test' + # if: always() + # uses: MAD-I-T/magento-actions@v3.25 + # env: + # COMPOSER_AUTH: ${{ steps.composer_auth.outputs.auth }} + # with: + # process: 'unit-test' + # unit_test_subset_path: 'vendor/sequra/magento2-core/Test/Unit' + # override_settings: 1 + # magento_version: ${{ matrix.magento_version }} # Integrations tests - - name: "copy integration test's phpunit.xml" - run: cp magento/app/code/Sequra/Core/Test/Integration/phpunit.xml.dist magento/dev/tests/integration/phpunit.xml + - name: "Run Integration tests" + working-directory: magento + run: | + cd dev/tests/integration && ../../../vendor/bin/phpunit app/code/Sequra/Core/Test/Integration - name: 'To run all test in copied phpunit.xml' uses: MAD-I-T/magento-actions@master env: diff --git a/Test/Integration/Model/Api/Builders/CreateOrderRequestBuilderTest.php b/Test/Integration/Model/Api/Builders/CreateOrderRequestBuilderTest.php index 7d723fb..8c0768c 100644 --- a/Test/Integration/Model/Api/Builders/CreateOrderRequestBuilderTest.php +++ b/Test/Integration/Model/Api/Builders/CreateOrderRequestBuilderTest.php @@ -5,13 +5,7 @@ use Sequra\Core\Model\Api\Builders\CreateOrderRequestBuilder; use Sequra\Core\Model\Api\Builders\CreateOrderRequestBuilderFactory; - -use Magento\Framework\Api\SearchCriteriaBuilder; use Magento\Quote\Model\Quote; -use Magento\Quote\Model\QuoteManagement; -use Magento\Sales\Api\Data\OrderInterface; -use Magento\Sales\Api\OrderManagementInterface; -use Magento\Sales\Api\OrderRepositoryInterface; use Magento\TestFramework\Helper\Bootstrap; use PHPUnit\Framework\TestCase; @@ -24,11 +18,14 @@ class CreateOrderRequestBuilderTest extends TestCase /** * @magentoDataFixture Magento/Sales/_files/quote_with_customer.php + * @magentoDataFixture Sequra_Core::Test/_files/sequra_configuration.php */ public function testBuildCreateOrderRequestForOrderWithShippingMethod() { // quote $this->quote->load('test01', 'reserved_order_id'); + // setShippingAddress in spain + $this->quote->getShippingAddress()->setCountryId('ES'); // setShippingMethod $this->quote->getShippingAddress() ->setShippingMethod('flatrate_flatrate') @@ -40,14 +37,19 @@ public function testBuildCreateOrderRequestForOrderWithShippingMethod() 'cartId' => $this->quote->getId(), 'storeId' => (string)$this->quote->getStore()->getId(), ]); - $request = $builder->build(); - assert($request->getShippingMethod() === 'flatrate_flatrate'); + $order = $builder->build()->toArray(); + self::assertEquals($order['delivery_method']['name'],'flatrate_flatrate'); + self::assertEquals($order['cart']['order_total_with_tax'], 1000); } public function setUp(): void { $objectManager = Bootstrap::getObjectManager(); + $_SERVER['REMOTE_ADDR'] = "255.255.255.255"; + $_SERVER['HTTP_USER_AGENT'] = "Integration tests"; $this->quote = $objectManager->create(Quote::class); $this->createOrderRequestBuilderFactory = $objectManager->create(CreateOrderRequestBuilderFactory::class); + $this->bootstrap =$objectManager->create(\Sequra\Core\Services\Bootstrap::class); + $this->bootstrap->initInstance(); } -} \ No newline at end of file +} diff --git a/Test/_files/sequra_configuration.php b/Test/_files/sequra_configuration.php new file mode 100644 index 0000000..4a64072 --- /dev/null +++ b/Test/_files/sequra_configuration.php @@ -0,0 +1,55 @@ +quote->load('test01', 'reserved_order_id'); + // setShippingAddress in spain + $this->quote->getShippingAddress()->setCountryId('ES'); + // setShippingMethod + $this->quote->getShippingAddress() + ->setShippingMethod('flatrate_flatrate') + ->setCollectShippingRates(true) + ->collectShippingRates() + ->save(); + /** @var CreateOrderRequestBuilder $builder */ + $builder = $this->createOrderRequestBuilderFactory->create([ + 'cartId' => $this->quote->getId(), + 'storeId' => (string)$this->quote->getStore()->getId(), + ]); + $order = $builder->build()->toArray(); + assert($order['delivery_method']['name'] === 'flatrate_flatrate'); + assert($order['cart']['order_total_with_tax'] === 1000); + } + + public function setUp(): void + { + $objectManager = Bootstrap::getObjectManager(); + $_SERVER['REMOTE_ADDR'] = "255.255.255.255"; + $_SERVER['HTTP_USER_AGENT'] = "Integration tests"; + $this->quote = $objectManager->create(Quote::class); + $this->createOrderRequestBuilderFactory = $objectManager->create(CreateOrderRequestBuilderFactory::class); + $this->bootstrap =$objectManager->create(\Sequra\Core\Services\Bootstrap::class); + $this->bootstrap->initInstance(); + } +}