Skip to content

Commit

Permalink
Let's try to run integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
m1k3lm committed Feb 16, 2024
1 parent 3a39bd9 commit 86d511f
Show file tree
Hide file tree
Showing 7 changed files with 355 additions and 37 deletions.
152 changes: 116 additions & 36 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ name: m2-actions-sequra-core-test
on: [push]

jobs:
magento2-build:
magento2-test:
runs-on: ubuntu-latest
container: ubuntu
name: 'm2 tests & build'
name: 'm2 unit and integration tests'
services:
mysql:
image: docker://mysql:8.0
Expand All @@ -21,53 +21,133 @@ jobs:
ports:
- 9200:9200
options: -e="discovery.type=single-node" -e "plugins.security.disabled=true" --health-cmd="curl http://localhost:9200/_cluster/health" --health-interval=10s --health-timeout=5s --health-retries=10

rabbitmq:
image: docker://rabbitmq:3.8-alpine
env:
RABBITMQ_DEFAULT_USER: "magento"
RABBITMQ_DEFAULT_PASS: "magento"
RABBITMQ_DEFAULT_VHOST: "/"
ports:
- 5672:5672
strategy:
matrix:
magento_version: [2.4.6]
steps:
### Download the third party code in custom dir###
- uses: actions/checkout@v3
with:
path: Sequra_Core
- name: Extract branch name
shell: bash
run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT
id: extract_branch

- name: Build composer auth
shell: bash
run: |
echo "auth={\"http-basic\": {\"repo.magento.com\": {\"username\": \"5310458a34d580de1700dfe826ff19a1\",\"password\":\"${{ secrets.REPO_MAGENTO_PASS }}\"} },\"github-oauth\":{\"github.com\":\"${{ github.token }}\"} }" >> $GITHUB_OUTPUT
id: composer_auth

- name: 'install fresh magento repo'
uses: MAD-I-T/magento-actions@v3.20
uses: MAD-I-T/magento-actions@v3.25
env:
COMPOSER_AUTH: ${{secrets.COMPOSER_AUTH}}
with:
process: 'install-magento'
magento_version: 2.4.6
magento_version: ${{ matrix.magento_version }}
no_push: 1 ## add this arg to not push to the repo ideal for quick test on specific version

- name: 'launch magento2 unit test'
if: always()
uses: MAD-I-T/magento-actions@v3.20
## Download our code in custom dir###
- uses: actions/checkout@v3
with:
path: magento/vendor/sequra/magento2-core

- uses: "shivammathur/setup-php@v2"
with:
php-version: "8.2"

# - name: 'Prepare for unit test'
# working-directory: magento/vendor/sequra/magento2-core
# env:
# COMPOSER_AUTH: ${{ steps.composer_auth.outputs.auth }}
# run: |
# ../../../vendor/bin/composer install --no-interaction --no-progress --no-suggest --prefer-dist

# - 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'
# unit_test_config: 'vendor/sequra/magento2-core/Test/Unit/phpunit.xml.dist'
# magento_version: ${{ matrix.magento_version }}

# Integrations tests
- name: "Run Integration tests"
working-directory: magento
run: |
cd dev/tests/integration && ../../../vendor/bin/phpunit ../../../vendor/sequra/magento2-core/Test/Integration
- name: 'To run all test in copied phpunit.xml'
uses: MAD-I-T/magento-actions@master
env:
COMPOSER_AUTH: ${{secrets.COMPOSER_AUTH}}
with:
process: 'unit-test'
unit_test_config: 'dev/tests/unit/phpunit.xml.dist'
unit_test_subset_path: '../Sequra_Core/'

- name: 'phpstan'
if: always()
uses: MAD-I-T/magento-actions@v3.20
with:
process: 'phpstan'
exec_path: '../Sequra_Core/'
process: 'integration-test'
unit_test_subset_path: "Sequra_Core Integration Tests"

# magento2-checks:
# runs-on: ubuntu-latest
# container: ubuntu
# name: 'm2 Standards, MD and PHPStan'
# strategy:
# matrix:
# magento_version: [2.4.6]
# steps:
# ### Download our code in custom dir###
# - uses: actions/checkout@v3
# with:
# path: Sequra_Core

# - name: 'install fresh magento repo'
# uses: MAD-I-T/magento-actions@v3.25
# env:
# COMPOSER_AUTH: ${{secrets.COMPOSER_AUTH}}
# with:
# process: 'install-magento'
# magento_version: ${{ matrix.magento_version }}
# no_push: 1 ## add this arg to not push to the repo ideal for quick test on specific version

# - uses: "shivammathur/setup-php@v2"
# with:
# php-version: "8.2"
# - name: 'unit test'
# run: |
# cd Sequra_Core
# ../magento/vendor/bin/composer install
# PAT="s/\/REAL-PATH-TO-MAGENTO-ROOT/..\/magento/g"
# sed -e $PAT Test/autoload_sample.php > Test/autoload.php
# ../magento/vendor/bin/phpunit -c Test/phpunit.xml Test/Unit

# - name: 'phpstan'
# if: always()
# uses: MAD-I-T/magento-actions@v3.25
# with:
# process: 'phpstan'
# exec_path: '../Sequra_Core'

- name: 'mess detector'
if: always()
uses: MAD-I-T/magento-actions@v3.20
with:
process: 'mess-detector'
md_src_path: '../Sequra_Core/'
# - name: 'mess detector'
# if: always()
# uses: MAD-I-T/magento-actions@v3.25
# with:
# process: 'mess-detector'
# md_src_path: '../Sequra_Core'

- name: 'Magento coding standard checking'
if: always()
uses: MAD-I-T/magento-actions@v3.20
with:
process: 'phpcs-test'
extension: 'Sequra_Core'
severity: 10
standard: 'Magento2'
# - name: 'Magento coding standard checking'
# if: always()
# uses: MAD-I-T/magento-actions@v3.25
# with:
# process: 'phpcs-test'
# extension: 'Sequra_Core'
# severity: 10
# standard: 'Magento2'


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();
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();
}
}
101 changes: 101 additions & 0 deletions Test/Integration/phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
colors="true"
columns="max"
beStrictAboutTestsThatDoNotTestAnything="false"
bootstrap="./framework/bootstrap.php"
stderr="true"
testSuiteLoaderClass="Magento\TestFramework\SuiteLoader"
testSuiteLoaderFile="framework/Magento/TestFramework/SuiteLoader.php">
<coverage>
<include>
<directory suffix=".php">../../../app/code/Magento</directory>
<directory suffix=".php">../../../lib/internal/Magento</directory>
</include>
<exclude>
<directory>../../../app/code/*/*/Test</directory>
<directory>../../../lib/internal/*/*/Test</directory>
<directory>../../../lib/internal/*/*/*/Test</directory>
<directory>../../../setup/src/*/*/Test</directory>
</exclude>
</coverage>
<!-- Test suites definition -->
<testsuites>
<testsuite name="Magento Integration Tests">
<file>testsuite/Magento/IntegrationTest.php</file>
</testsuite>
<!-- Memory tests run first to prevent influence of other tests on accuracy of memory measurements -->
<testsuite name="Memory Usage Tests">
<file>testsuite/Magento/MemoryUsageTest.php</file>
</testsuite>
<testsuite name="Sequra_Core Integration Tests">
<directory suffix="Test.php">../../../../Sequra_Core/Test/Integration</directory>
</testsuite>
</testsuites>
<!-- Code coverage filters -->
<!-- PHP INI settings and constants definition -->
<php>
<includePath>.</includePath>
<includePath>testsuite</includePath>
<ini name="date.timezone" value="America/Los_Angeles"/>
<ini name="xdebug.max_nesting_level" value="200"/>
<!-- Local XML configuration file ('.dist' extension will be added, if the specified file doesn't exist) -->
<const name="TESTS_INSTALL_CONFIG_FILE" value="etc/install-config-mysql.php"/>
<!-- Local XML post installation configuration file ('.dist' extension will be added, if the specified file doesn't exist) -->
<const name="TESTS_POST_INSTALL_SETUP_COMMAND_CONFIG_FILE" value="etc/post-install-setup-command-config.php"/>
<!-- Local XML configuration file ('.dist' extension will be added, if the specified file doesn't exist) -->
<const name="TESTS_GLOBAL_CONFIG_FILE" value="etc/config-global.php"/>
<!-- Semicolon-separated 'glob' patterns, that match global XML configuration files -->
<const name="TESTS_GLOBAL_CONFIG_DIR" value="../../../app/etc"/>
<!-- Whether to cleanup the application before running tests or not -->
<const name="TESTS_CLEANUP" value="enabled"/>
<!-- Memory usage and estimated leaks thresholds -->
<!--<const name="TESTS_MEM_USAGE_LIMIT" value="1024M"/>-->
<const name="TESTS_MEM_LEAK_LIMIT" value=""/>
<!-- Path to Percona Toolkit bin directory -->
<!--<const name="PERCONA_TOOLKIT_BIN_DIR" value=""/>-->
<!-- CSV Profiler Output file -->
<!--<const name="TESTS_PROFILER_FILE" value="profiler.csv"/>-->
<!-- Bamboo compatible CSV Profiler Output file name -->
<!--<const name="TESTS_BAMBOO_PROFILER_FILE" value="profiler.csv"/>-->
<!-- Metrics for Bamboo Profiler Output in PHP file that returns array -->
<!--<const name="TESTS_BAMBOO_PROFILER_METRICS_FILE" value="../../build/profiler_metrics.php"/>-->
<!-- Whether to output all CLI commands executed by the bootstrap and tests -->
<const name="TESTS_EXTRA_VERBOSE_LOG" value="1"/>
<!-- Magento mode for tests execution. Possible values are "default", "developer" and "production". -->
<const name="TESTS_MAGENTO_MODE" value="developer"/>
<!-- Minimum error log level to listen for. Possible values: -1 ignore all errors, and level constants form http://tools.ietf.org/html/rfc5424 standard -->
<const name="TESTS_ERROR_LOG_LISTENER_LEVEL" value="-1"/>
<!-- Connection parameters for MongoDB library tests -->
<!--<const name="MONGODB_CONNECTION_STRING" value="mongodb://localhost:27017"/>-->
<!--<const name="MONGODB_DATABASE_NAME" value="magento_integration_tests"/>-->
<!-- Connection parameters for RabbitMQ tests -->
<!--<const name="RABBITMQ_MANAGEMENT_PROTOCOL" value="https"/>-->
<!--<const name="RABBITMQ_MANAGEMENT_PORT" value="15672"/>-->
<!--<const name="RABBITMQ_VIRTUALHOST" value="/"/>-->
<!--<const name="TESTS_PARALLEL_RUN" value="1"/>-->
<const name="USE_OVERRIDE_CONFIG" value="enabled"/>
</php>
<!-- Test listeners -->
<listeners>
<!-- Run after AllureAdapter to allow it to initialize properly -->
<listener class="Magento\TestFramework\Event\PhpUnit"/>
<listener class="Magento\TestFramework\ErrorLog\Listener"/>
</listeners>
<extensions>
<extension class="Qameta\Allure\PHPUnit\AllureExtension">
<!-- Optional arguments block; omit it if you want to use default values -->
<arguments>
<!-- Path to config file (default is config/allure.config.php) -->
<string>allure/allure.config.php</string>
</arguments>
</extension>
</extensions>
</phpunit>
12 changes: 12 additions & 0 deletions Test/Unit/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
use Magento\Framework\App\Bootstrap;
use Magento\Framework\App\Cron;
// Load magento's booststrap
require __DIR__ . '/../../../../../app/bootstrap.php';

if (file_exists(__DIR__ . '/vendor/autoload.php')) {
include __DIR__ . '/vendor/autoload.php';
}

$bootstrap = Bootstrap::create(BP, $_SERVER);
$bootstrap->createApplication(Cron::class);
8 changes: 8 additions & 0 deletions Test/Unit/phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="./bootstrap.php" colors="true">
<testsuites>
<testsuite name="Sequra Magento 2 Core Test Suite">
<directory>./</directory>
</testsuite>
</testsuites>
</phpunit>
Loading

0 comments on commit 86d511f

Please sign in to comment.