Skip to content

Commit

Permalink
Added an integration test that passes
Browse files Browse the repository at this point in the history
  • Loading branch information
m1k3lm committed Jan 9, 2024
1 parent b2f2993 commit a426296
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 37 deletions.
55 changes: 27 additions & 28 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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')
Expand All @@ -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();
}
}
}
55 changes: 55 additions & 0 deletions Test/_files/sequra_configuration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
declare(strict_types=1);

namespace Sequra\Core\Test\Integration\Model\Api\Builders;

use Sequra\Core\Model\Api\Builders\CreateOrderRequestBuilder;
use Sequra\Core\Model\Api\Builders\CreateOrderRequestBuilderFactory;
use Magento\Quote\Model\Quote;
use Magento\TestFramework\Helper\Bootstrap;
use PHPUnit\Framework\TestCase;

/**
* @magentoDbIsolation enabled
* @magentoAppIsolation enabled
*/
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')
->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();
}
}

0 comments on commit a426296

Please sign in to comment.