Skip to content

Commit

Permalink
Merge pull request #103 from AmpersandHQ/add-refund-quantity-tests
Browse files Browse the repository at this point in the history
Refactor testing structure and setup
  • Loading branch information
convenient authored Apr 24, 2023
2 parents be5fa4c + fdff1d2 commit ee3e9ca
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 89 deletions.
4 changes: 4 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
### Checklist
- [ ] Pull request has a meaningful description of its purpose, include affected Magento versions if it is a bug.
- [ ] All commits are accompanied by meaningful commit messages
- [ ] Tests have been ran / updated (see `./dev/README.md` for how to run tests)
99 changes: 28 additions & 71 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,89 +1,46 @@
language: php
php:
- 7.4
- 8.1
git:
depth: false
dist: xenial
php: 8.1

env:
- TEST_GROUP=magento_latest
- TEST_GROUP=magento_242
- TEST_GROUP=magento_23
jobs:
exclude:
- php: 8.1
env: TEST_GROUP=magento_23
- php: 8.1
env: TEST_GROUP=magento_242
- php: 7.4
env: TEST_GROUP=magento_latest
- TEST_GROUP=2-3-7
- TEST_GROUP=2-4-0
- TEST_GROUP=2-4-1
- TEST_GROUP=2-4-2
- TEST_GROUP=2-4-3
- TEST_GROUP=2-4-4
- TEST_GROUP=2-4-5
- TEST_GROUP=2-4-6

#jobs:
# allow_failures:
# - env: TEST_GROUP=2-4-3
# - env: TEST_GROUP=2-4-4
# - env: TEST_GROUP=2-4-5
# - env: TEST_GROUP=2-4-6

before_install:
- travis_retry wget https://github.com/docker/compose/releases/download/v2.17.0/docker-compose-linux-x86_64
- sudo mv docker-compose-linux-x86_64 /usr/libexec/docker/cli-plugins/docker-compose
- sudo chmod +x /usr/libexec/docker/cli-plugins/docker-compose
- docker --version && docker compose version

install:
# Composer install
- composer install --no-interaction
# Do a quick code style check
- PHP_CS_FIXER_IGNORE_ENV=1 ./vendor/bin/php-cs-fixer fix --dry-run --rules=@PSR2 --diff src/
# Magento coding standard check
- vendor/bin/phpcs -s --standard=./ruleset.xml src/
# Install magento
- if [[ $TEST_GROUP = magento_242 ]]; then NAME=disablestockres VERSION=2.4.2 . ./vendor/bin/travis-install-magento.sh; fi
- if [[ $TEST_GROUP = magento_23 ]]; then NAME=disablestockres VERSION=2.3.7-p2 . ./vendor/bin/travis-install-magento.sh; fi
- if [[ $TEST_GROUP = magento_latest ]]; then magerun2 self-update; fi
- if [[ $TEST_GROUP = magento_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 -vvv ampersand/magento2-disable-stock-reservation:"dev-$TRAVIS_BRANCH" || composer require -vvv 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 oauth/consumer/enable_integration_as_bearer 1
- 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
- magerun2 sys:info
- cd -

before_install:
- if [ ! "$TRAVIS_PULL_REQUEST" = "false" ]; then git branch; git branch -D "$TRAVIS_BRANCH" || true; git checkout -b "$TRAVIS_BRANCH"; fi
- composer self-update --2
- mkdir -p $HOME/bin/
# Install magerun2
- test -f $HOME/bin/magerun2 || (mkdir -p $HOME/bin/ && wget https://files.magerun.net/n98-magerun2-4.9.1.phar && chmod +x n98-magerun2-4.9.1.phar && mv n98-magerun2-4.9.1.phar $HOME/bin/magerun2)

- CURRENT_EXTENSION="." FULL_INSTALL=1 vendor/bin/mtest-make $TEST_GROUP

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
- elasticsearch
- composer docker-configure-magento
- composer docker-run-codeception

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
- vendor/bin/mtest 'for r in /var/www/html/var/report/*; do cat $r; done'
- vendor/bin/mtest 'cat /var/www/html/var/log/*.log'
- docker ps
- sleep 10; # give log files time to render
13 changes: 12 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,23 @@
"codeception/module-phpbrowser": "^1.0.0",
"codeception/module-asserts": "^1.1.0",
"codeception/module-db": "^1.0.1",
"ampersand/travis-vanilla-magento": "^1.0",
"ampersand/magento-docker-test-instance": "^0.1",
"codeception/module-rest": "^1.2.0",
"friendsofphp/php-cs-fixer": "^2.16",
"magento/magento-coding-standard": "<16"
},
"scripts": {
"docker-configure-magento": [
"vendor/bin/mtest 'vendor/bin/n98-magerun2 config:store:set checkout/options/guest_checkout 1'",
"vendor/bin/mtest 'vendor/bin/n98-magerun2 config:store:set payment/checkmo/active 1'",
"vendor/bin/mtest 'vendor/bin/n98-magerun2 config:store:set oauth/consumer/enable_integration_as_bearer 1'",
"vendor/bin/mtest 'vendor/bin/n98-magerun2 integration:create disablestockres [email protected] https://example.com --access-token=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'",
"vendor/bin/mtest 'php bin/magento cache:flush'",
"vendor/bin/mtest 'php bin/magento --version'"
],
"docker-run-codeception": [
"URL=\"http://0.0.0.0:1234/\" MYSQL_USER=\"root\" MYSQL_HOST=\"0.0.0.0\" MYSQL_DB=\"magento\" MYSQL_PORT=\"1235\" ./dev/run-codeception.sh"
],
"post-install-cmd": [
"([ $COMPOSER_DEV_MODE -eq 0 ] || vendor/bin/phpcs --config-set installed_paths ../../magento/magento-coding-standard/)"
],
Expand Down
23 changes: 23 additions & 0 deletions dev/README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**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 get a copy of the repo
```
git clone https://github.com/AmpersandHQ/magento2-disable-stock-reservation/
cd magento2-disable-stock-reservation
```

Boot the docker test instance for testing against (run `./vendor/bin/mtest-make` to see supported versions)
```
CURRENT_EXTENSION="." FULL_INSTALL=1 vendor/bin/mtest-make 2-4-5
```

Configure magento test settings
```
composer docker-configure-magento
```

Run the tests
```
composer docker-run-codeception
```

16 changes: 0 additions & 16 deletions dev/codeception.MD

This file was deleted.

2 changes: 1 addition & 1 deletion dev/run-codeception.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
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
$DIR_BASE/../vendor/bin/codecept run acceptance -c dev $1 -v
1 change: 1 addition & 0 deletions dev/tests/acceptance/CheckoutCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class CheckoutCest
public function dependenciesAreConfigured(Step\Acceptance\Magento $I)
{
$I->seeNumRecords(1, 'inventory_source');
$I->seeInDatabase('core_config_data', ['path' => 'oauth/consumer/enable_integration_as_bearer', 'value' => '1']);
$I->seeInDatabase('core_config_data', ['path' => 'checkout/options/guest_checkout', 'value' => '1']);
$I->seeInDatabase('core_config_data', ['path' => 'payment/checkmo/active', 'value' => '1']);
$I->seeInDatabase('oauth_token', ['token' => Step\Acceptance\Magento::ACCESS_TOKEN]);
Expand Down

0 comments on commit ee3e9ca

Please sign in to comment.