Skip to content

Commit

Permalink
Merge pull request #11 from AmpersandHQ/add-automated-travis-tests
Browse files Browse the repository at this point in the history
Add automated travis tests and cherry pick #10
  • Loading branch information
convenient authored Mar 26, 2020
2 parents c4f7e6e + 46ecf9d commit d33192c
Show file tree
Hide file tree
Showing 25 changed files with 496 additions and 22 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
vendor/
composer.lock
.php_cs.cache
65 changes: 65 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
language: php
php: 7.3

env:
- TEST_GROUP=latest
- TEST_GROUP=two_three_three

install:
# Composer install
- composer install --no-interaction
# Do a quick code style check
- ./vendor/bin/php-cs-fixer fix --dry-run --rules=@PSR2 --diff src/
# Install magento
- if [[ $TEST_GROUP = two_three_three ]]; then NAME=disablestockres VERSION=2.3.3 . ./vendor/bin/travis-install-magento.sh; fi
- if [[ $TEST_GROUP = latest ]]; then NAME=disablestockres . ./vendor/bin/travis-install-magento.sh; fi
# Install this module
- cd vendor/ampersand/travis-vanilla-magento/instances/disablestockres
- export COMPOSER_MEMORY_LIMIT=-1
- composer config repo.disablestockres git "../../../../../"
- composer require ampersand/magento2-disable-stock-reservation dev-$TRAVIS_BRANCH || composer require ampersand/magento2-disable-stock-reservation $TRAVIS_BRANCH
- php bin/magento setup:upgrade
# compile magento
- php bin/magento setup:di:compile
# Set up test configuration
- magerun2 config:store:set checkout/options/guest_checkout 1
- magerun2 config:store:set payment/checkmo/active 1
- magerun2 integration:create disablestockres [email protected] https://example.com --access-token="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
- magerun2 cache:flush
# warm caches
- php bin/magento
- cd -

before_install:
- mkdir -p $HOME/bin/
# Install magerun2
- test -f $HOME/bin/magerun2 || (wget https://files.magerun.net/n98-magerun2-latest.phar && chmod +x n98-magerun2-latest.phar && mv n98-magerun2-latest.phar $HOME/bin/magerun2)

script:
- ADDITIONAL_ARGS="-v"
- if [[ $TRAVIS_COMMIT_MESSAGE == *"VERBOSE"* ]]; then ADDITIONAL_ARGS="-vvv"; fi;
- ./vendor/bin/codecept build -c dev
- URL="https://magento-disablestockres.localhost/" MYSQL_USER="root" MYSQL_HOST="127.0.0.1" MYSQL_DB="databasedisablestockres" MYSQL_PORT="3306" ./vendor/bin/codecept run acceptance -c dev $ADDITIONAL_ARGS

addons:
apt:
packages:
- postfix
- apache2
- libapache2-mod-fastcgi

services:
- mysql

cache:
apt: true
directories:
- $HOME/.composer/cache
- $HOME/bin

after_failure:
- test -d ./vendor/ampersand/travis-vanilla-magento/instances/disablestockres/var/report/ && for r in ./vendor/ampersand/travis-vanilla-magento/instances/disablestockres/var/report/*; do cat $r; done
- test -f ./vendor/ampersand/travis-vanilla-magento/instances/disablestockres/var/log/system.log && grep -v "Broken reference" ./vendor/ampersand/travis-vanilla-magento/instances/disablestockres/var/log/system.log
- test -f ./vendor/ampersand/travis-vanilla-magento/instances/disablestockres/var/log/exception.log && cat ./vendor/ampersand/travis-vanilla-magento/instances/disablestockres/var/log/exception.log
- test -f ./vendor/ampersand/travis-vanilla-magento/instances/disablestockres/var/log/support_report.log && grep -v "Broken reference" ./vendor/ampersand/travis-vanilla-magento/instances/disablestockres/var/log/support_report.log
- sleep 10; # give log files time to render
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# AmpersandHQ/magento2-disable-stock-reservation

[![Build Status](https://travis-ci.org/AmpersandHQ/magento2-disable-stock-reservation.svg?branch=master)](https://travis-ci.org/AmpersandHQ/magento2-disable-stock-reservation)

This module disables the inventory reservation logic introduced as part of MSI in Magento 2.3.3 - see
https://github.com/magento/inventory/issues/2269 for more information about the way MSI was implemented, and the issues
that can happen with external WMS integrations.
Expand Down
20 changes: 18 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "ampersand/magento2-disable-stock-reservation",
"description": "This module disables the inventory reservation logic introduced as part of MSI in Magento 2.3.3",
"type": "magento2-module",
"minimum-stability": "dev",
"require": {
Expand All @@ -8,10 +9,25 @@
},
"autoload": {
"files": [
"registration.php"
"src/registration.php"
],
"psr-4": {
"Ampersand\\DisableStockReservation\\": ""
"Ampersand\\DisableStockReservation\\": "src"
}
},
"repositories": [
{
"type": "composer",
"url": "https://repo-magento-mirror.fooman.co.nz/"
}
],
"require-dev": {
"codeception/codeception": "^4.1.1",
"codeception/module-phpbrowser": "^1.0.0",
"codeception/module-asserts": "^1.1.0",
"codeception/module-db": "^1.0.1",
"ampersand/travis-vanilla-magento": "^1.0",
"codeception/module-rest": "^1.2.0",
"friendsofphp/php-cs-fixer": "^2.16"
}
}
15 changes: 15 additions & 0 deletions dev/codeception.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
**Do not run these tests in production, they delete from and insert into your database as well as generate an integration token.**

To run these tests locally you will need to

1. Install a vanilla magento instance locally
2. Install this module
3. `magerun2 config:store:set checkout/options/guest_checkout 1`
4. `magerun2 config:store:set payment/checkmo/active 1`
5. `magerun2 integration:create disablestockres [email protected] https://example.com --access-token="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"`
6. `magerun2 cache:flush`
7. Run with the appropriate environment vars set,

```
URL="https://magento-disablestockres.localhost/" MYSQL_USER="root" MYSQL_HOST="127.0.0.1" MYSQL_DB="databasedisablestockres" MYSQL_PORT="3306" ./dev/run-codeception.sh
```
15 changes: 15 additions & 0 deletions dev/codeception.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
paths:
tests: tests
output: tests/_output
data: tests/_data
support: tests/_support
envs: tests/_envs
actor_suffix: Tester
settings:
colors: true
memory_limit: 1024M
extensions:
enabled:
- Codeception\Extension\RunFailed
params:
- env
6 changes: 6 additions & 0 deletions dev/run-codeception.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

DIR_BASE="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

$DIR_BASE/../vendor/bin/codecept build -c dev
$DIR_BASE/../vendor/bin/codecept run acceptance -c dev $1 -vvv
Empty file added dev/tests/_data/.gitkeep
Empty file.
2 changes: 2 additions & 0 deletions dev/tests/_output/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
27 changes: 27 additions & 0 deletions dev/tests/_support/AcceptanceTester.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php


/**
* Inherited Methods
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method void pause()
*
* @SuppressWarnings(PHPMD)
*/
class AcceptanceTester extends \Codeception\Actor
{
use _generated\AcceptanceTesterActions;

/**
* Define custom actions here
*/
use \Codeception\Lib\Actor\Shared\Retry;
}
56 changes: 56 additions & 0 deletions dev/tests/_support/Helper/Acceptance.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
namespace Helper;

// here you can define custom actions
// all public methods declared in helper class will be available in $I
use Codeception\Exception\ModuleException;
use Symfony\Component\BrowserKit\Cookie;

class Acceptance extends \Codeception\Module
{
/** @var \Codeception\Module\Db */
private $databaseModule;

/** @var \Codeception\Module\REST */
private $restModule;

/**
* Event hook before a test starts.
*
* @param \Codeception\TestInterface $test
*
* @throws \Exception
*/
public function _before(\Codeception\TestInterface $test)
{
$this->databaseModule = $this->getModule('Db');
$this->restModule = $this->getModule('REST');
}

/**
* @param $url
* @param array $params
* @param array $files
*/
public function sendPOSTAndVerifyResponseCodeIs200($url, $params = [], $files = [])
{
$this->restModule->sendPOST($url, $params, $files);
$this->restModule->seeResponseCodeIs(200);
}

/**
* Set XDEBUG cookie for debugging rest connections
*/
public function haveRESTXdebugCookie()
{
$this->restModule->client->getCookieJar()->set(new Cookie('XDEBUG_SESSION', 'phpstorm'));
}
/**
* @param $table
* @param $criteria
*/
public function deleteFromDatabase($table, $criteria = [])
{
$this->databaseModule->_getDriver()->deleteQueryByCriteria($table, $criteria);
}
}
2 changes: 2 additions & 0 deletions dev/tests/_support/_generated/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
29 changes: 29 additions & 0 deletions dev/tests/acceptance.suite.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Codeception Test Suite Configuration
#
# Suite for acceptance tests.
# Perform tests in browser using the WebDriver or PhpBrowser.
# If you need both WebDriver and PHPBrowser tests - create a separate suite.

actor: AcceptanceTester
step_decorators:
- \Codeception\Step\Retry
- \Codeception\Step\TryTo
modules:
enabled:
- PhpBrowser
- Asserts
- Db
- REST
- \Helper\Acceptance
config:
REST:
depends: PhpBrowser
url: '%URL%rest/'
shortDebugResponse: 1000 # only the first 300 chars of the response
PhpBrowser:
url: '%URL%'
timeout: 60
Db:
dsn: 'mysql:host=%MYSQL_HOST%;dbname=%MYSQL_DB%;port=%MYSQL_PORT%'
user: '%MYSQL_USER%'
password:
Loading

0 comments on commit d33192c

Please sign in to comment.