From b8ab83529361b174579c675c5093b1f81f79e973 Mon Sep 17 00:00:00 2001
From: David Alger <david@classyllama.com>
Date: Sat, 27 Feb 2016 17:22:46 -0600
Subject: [PATCH] Cleans up the integration test preparation

- moves everything into one place, the before_script.sh
- now removes `update/dev/tests/integration/testsuite` set from all but test set 1
- integration set handling should be flexible by configuration env vars in single location (.travis.xml)
- fixed an oops in d2884f0 (accidental change to matrix exclusions)
---
 .travis.yml                                   |  6 +--
 .../integration/IntegationTestsForTravis.sh   | 44 ------------------
 dev/travis/before_install.sh                  |  2 +
 dev/travis/before_script.sh                   | 46 +++++++++++++++++--
 dev/travis/script.sh                          |  9 ++--
 5 files changed, 49 insertions(+), 58 deletions(-)
 delete mode 100644 dev/tests/integration/IntegationTestsForTravis.sh

diff --git a/.travis.yml b/.travis.yml
index fc7dc03ee91..cfd01103bf4 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -14,8 +14,8 @@ php:
   - 7.0
 env:
   - TEST_SUITE=unit
-  - TEST_SUITE=integration_part_1
-  - TEST_SUITE=integration_part_2
+  - TEST_SUITE=integration INTEGRATION_INDEX=1 INTEGRATION_SETS=2
+  - TEST_SUITE=integration INTEGRATION_INDEX=2 INTEGRATION_SETS=2
   - TEST_SUITE=integration_integrity
   - TEST_SUITE=static_phpcs
   - TEST_SUITE=static_annotation
@@ -32,7 +32,7 @@ matrix:
       env: TEST_SUITE=static_annotation
     - php: 7.0
       env: TEST_SUITE=static_phpcs
-    - php: 
+    - php: 7.0
       env: TEST_SUITE=static_annotation
 before_install: ./dev/travis/before_install.sh
 before_script: ./dev/travis/before_script.sh
diff --git a/dev/tests/integration/IntegationTestsForTravis.sh b/dev/tests/integration/IntegationTestsForTravis.sh
deleted file mode 100644
index cb4ce14e04a..00000000000
--- a/dev/tests/integration/IntegationTestsForTravis.sh
+++ /dev/null
@@ -1,44 +0,0 @@
-#!usr/bin/bash
-
-# Copyright © 2015 Magento. All rights reserved.
-# See COPYING.txt for license details.
-
-# Get number of files in directory
-NUMBER_OF_SUITES=$1
-FOLDERSIZE=$(find ./testsuite/Magento/ -maxdepth 1 -type d|wc -l)
-FOLDERSIZE=$((FOLDERSIZE/NUMBER_OF_SUITES))
-
-# Get folders
-FOLDERS=$(ls  "./testsuite/Magento")
-
-# Create n testsuites
-i=0
-for i in `seq 1 $NUMBER_OF_SUITES`
-do
-	cp phpunit.xml.dist phpunit.xml.travis$i
-done
-
-# Replace Memory Usage Tests in all except testsuite 1
-for i in `seq 2 $NUMBER_OF_SUITES`
-do
-	perl -i -0pe 's/(<!-- Memory)(.*?)(<\/testsuite>)//ims' phpunit.xml.travis$i
-done
-
-# Create list of folders on which tests are to be run
-i=0
-j=1
-for FOLDER in $FOLDERS
-do
-	FILE[j]+="\n<directory suffix=\"Test.php\">testsuite\/Magento\/${FOLDER}<\/directory>"
-	i=$((i+1))
-	if [ "$i" -eq "$FOLDERSIZE" ] && [ "$j" -lt "$NUMBER_OF_SUITES" ]; then
-		j=$((j+1))
-		i=0
-	fi
-done
-
-# Finally replacing in config files.
-for i in `seq 1 $NUMBER_OF_SUITES`
-do
-	perl -pi -e "s/<directory suffix=\"Test.php\">testsuite<\/directory>/${FILE[i]}/g" phpunit.xml.travis$i
-done
\ No newline at end of file
diff --git a/dev/travis/before_install.sh b/dev/travis/before_install.sh
index 3eb77fa94d1..a17f48b257c 100755
--- a/dev/travis/before_install.sh
+++ b/dev/travis/before_install.sh
@@ -3,6 +3,8 @@
 # Copyright © 2015 Magento. All rights reserved.
 # See COPYING.txt for license details.
 
+set -e
+
 # install or update composer in casher dir
 if [ "$CASHER_DIR" ]; then
     if [ -x $HOME/.cache/bin/composer ]; then
diff --git a/dev/travis/before_script.sh b/dev/travis/before_script.sh
index 8f3b0c6fd17..3a4ba3f64cc 100755
--- a/dev/travis/before_script.sh
+++ b/dev/travis/before_script.sh
@@ -3,7 +3,7 @@
 # Copyright © 2015 Magento. All rights reserved.
 # See COPYING.txt for license details.
 
-# prefer our cached binaries
+set -e
 export PATH="$HOME/.cache/bin:$PATH"
 
 # mock mail
@@ -14,13 +14,49 @@ echo 'sendmail_path = "/usr/sbin/sendmail -t -i "' > ~/.phpenv/versions/$(phpenv
 # disable xDebug
 echo > ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini
 
-# create database for integration tests
+# prepare for integration tests
 case $TEST_SUITE in
-    integration_part_1|integration_part_2)
-        ./dev/tests/integration/IntegationTestsForTravis.sh 2
+    integration)
+        cd dev/tests/integration
+
+        test_set_list=$(find testsuite/* -maxdepth 1 -mindepth 1 -type d)
+        test_set_size=$(($(printf "$test_set_list" | wc -l)/INTEGRATION_SETS))
+
+        # create n testsuites
+        for i in $(seq 1 $INTEGRATION_SETS); do
+            cp phpunit.xml.dist phpunit.xml.travis$i
+        done
+
+        # remove memory usage and update integration tests from all except testsuite 1
+        for i in $(seq 2 $INTEGRATION_SETS); do
+            perl -pi -0e 's#^\s+<!-- Memory(.*?)</testsuite>\n##ims' phpunit.xml.travis$i
+            perl -pi -e 's#\s+<directory.*>../../../update/dev/tests.*</directory>\n##g' phpunit.xml.travis$i
+        done
+
+        # create list of folders on which tests are to be run
+        i=0; j=1
+        for test_set in $test_set_list; do
+            test_xml[j]+="            <directory suffix=\"Test.php\">$test_set</directory>\n"
+            
+            i=$((i+1))
+            if [ $i -eq $test_set_size ] && [ $j -lt $INTEGRATION_SETS ]; then
+                j=$((j+1))
+                i=0
+            fi
+        done
+
+        # Finally replacing in config files.
+        for i in `seq 1 $INTEGRATION_SETS`; do
+            perl -pi -e "s#\s+<directory.*>testsuite</directory>#${test_xml[i]}#g" phpunit.xml.travis$i
+        done
+
+        cd ../../..
         ;&  # intentional fallthrough
     integration_integrity)
-        mysql -uroot -e 'SET @@global.sql_mode = NO_ENGINE_SUBSTITUTION; CREATE DATABASE magento_integration_tests;'
+        mysql -uroot -e '
+            SET @@global.sql_mode = NO_ENGINE_SUBSTITUTION;
+            CREATE DATABASE magento_integration_tests;
+        '
         mv dev/tests/integration/etc/install-config-mysql.travis.php.dist \
             dev/tests/integration/etc/install-config-mysql.php
         ;;
diff --git a/dev/travis/script.sh b/dev/travis/script.sh
index fad2f5cc2e8..f015938724d 100755
--- a/dev/travis/script.sh
+++ b/dev/travis/script.sh
@@ -3,6 +3,7 @@
 # Copyright © 2015 Magento. All rights reserved.
 # See COPYING.txt for license details.
 
+set -e
 PATH="./../../../vendor/bin:$PATH"
 
 case $TEST_SUITE in
@@ -10,13 +11,9 @@ case $TEST_SUITE in
         cd dev/tests/unit
         phpunit -c phpunit.xml.dist
         ;;
-    integration_part_1)
+    integration)
         cd dev/tests/integration
-        phpunit -c phpunit.xml.travis1
-        ;;
-    integration_part_2)
-        cd dev/tests/integration
-        phpunit -c phpunit.xml.travis2
+        phpunit -c phpunit.xml.travis$INTEGRATION_INDEX
         ;;
     integration_integrity)
         cd dev/tests/integration
-- 
GitLab