From 2707d242b5cb00b96d6334ba71c7024e920db7f3 Mon Sep 17 00:00:00 2001 From: Reynold Tan Date: Wed, 17 Feb 2021 09:36:52 -0600 Subject: [PATCH 01/15] Implements GitHub Actions --- .github/workflows/phpunit.yml | 86 +++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 .github/workflows/phpunit.yml diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml new file mode 100644 index 0000000..b60bedc --- /dev/null +++ b/.github/workflows/phpunit.yml @@ -0,0 +1,86 @@ + +name: Run PHPUnit Tests + +# Controls when the workflow will run. +# Run this workflow every time a new commit is pushed to your repository +on: [push, pull_request] + +jobs: + # This key is the name of the job. + run-tests: + # The type of system that the job will run on. + runs-on: ubuntu-latest + # Matrix Build for this job. + strategy: + matrix: + php-versions: ['7.1', '7.2'] + # Name the matrix build so we can tell them apart. + name: PHP Unit Testing of Analyzed Phenotypes Module (PHP ${{ matrix.php-versions }}) + + # Service containers to run with `run-tests` + services: + # Label used to access the service container + postgres: + # Docker Hub image + image: postgres + env: + POSTGRES_USER: tripaladmin + POSTGRES_PASSWORD: somesupersecurepassword + POSTGRES_DB: testdb + # Set health checks to wait until postgres has started + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + # Maps tcp port 5432 on service container to the host + - 5432:5432 + + steps: + # 1) Checkout the repository and setup workspace. + - uses: actions/checkout@v2 + + # 2) Setup PHP according to the version passed in. + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + extensions: mbstring, intl, php-pgsql, php-gd, php-xml + ini-values: memory_limit=2G + coverage: xdebug + tools: composer, phpunit + + # 3) Install Drush/Drupal/Tripal + - name: Setup Drush, Drupal 7.x, Tripal 3.x + id: tripalsetup + uses: tripal/setup-tripal-action@7.x-3.x-1.0 + with: + postgres_user: tripaladmin + postgres_pass: somesupersecurepassword + postgres_db: testdb + + # 4) Install Tripal QTL + - name: Install Tripal QTL + id: installtripalqtl + env: + DRUSH: ${{ steps.tripalsetup.outputs.drush_path }} + DRUPAL_ROOT: ${{ steps.tripalsetup.outputs.drupal_root }} + run: | + mkdir -p $DRUPAL_ROOT/sites/all/modules/tripal_qtl + cp -R * $DRUPAL_ROOT/sites/all/modules/tripal_qtl + cd $DRUPAL_ROOT + $DRUSH en -y tripal_qtl + + # 5) Runs the PHPUnit tests. + # https://github.com/mheap/phpunit-github-actions-printer is used + # to report PHPUnit fails in a meaningful way to github in PRs. + - name: PHPUnit Tests + env: + DRUSH: ${{ steps.tripalsetup.outputs.drush_path }} + DRUPAL_ROOT: ${{ steps.tripalsetup.outputs.drupal_root }} + run: | + cd $DRUPAL_ROOT/sites/all/modules/tripal_qtl + composer require --dev mheap/phpunit-github-actions-printer --quiet + composer update --quiet + ./vendor/bin/phpunit --printer mheap\\GithubActionsReporter\\Printer From f79add51c7bd93840e498a583e4c941a80278bfc Mon Sep 17 00:00:00 2001 From: Reynold Tan Date: Wed, 17 Feb 2021 10:26:23 -0600 Subject: [PATCH 02/15] Implements GitHub Actions --- .github/workflows/phpunit.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index b60bedc..c8455d7 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -15,7 +15,7 @@ jobs: matrix: php-versions: ['7.1', '7.2'] # Name the matrix build so we can tell them apart. - name: PHP Unit Testing of Analyzed Phenotypes Module (PHP ${{ matrix.php-versions }}) + name: PHP Unit Testing of Tripal QTL Module (PHP ${{ matrix.php-versions }}) # Service containers to run with `run-tests` services: From 37838053b00f7208b5b31e37883570d3ae74bfb3 Mon Sep 17 00:00:00 2001 From: Reynold Date: Mon, 22 Feb 2021 09:35:51 -0600 Subject: [PATCH 03/15] Echo class value --- tests/QTLImporterTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/QTLImporterTest.php b/tests/QTLImporterTest.php index 1063c7c..86b5004 100644 --- a/tests/QTLImporterTest.php +++ b/tests/QTLImporterTest.php @@ -112,7 +112,7 @@ public function testRun() { // Now we run the importer! $success = $importer->run(); $this->assertNotFalse($success, - "The importer returned an error."); + "The importer returned an error..." . $success); // Finally, check that the data is in the correct tables, etc. // -- check that the QTL features were created. From 38d4450448fbe78f4b15ddcfcc89666f6d0cadda Mon Sep 17 00:00:00 2001 From: Reynold Date: Mon, 22 Feb 2021 09:50:08 -0600 Subject: [PATCH 04/15] Echo class values --- includes/TripalImporter/QTLImporter.inc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/includes/TripalImporter/QTLImporter.inc b/includes/TripalImporter/QTLImporter.inc index f111f2c..3034d59 100644 --- a/includes/TripalImporter/QTLImporter.inc +++ b/includes/TripalImporter/QTLImporter.inc @@ -150,28 +150,28 @@ class QTLImporter extends TripalImporter { $featuremap_id = $arguments['featuremap_name']; if (!$featuremap_id) { $this->logMessage('An Error was encountered retrieving the genetic map.'); - return FALSE; + return 1; } // Check that the map exists. $exists = chado_query('SELECT true FROM {featuremap} WHERE featuremap_id=:id', [':id' => $featuremap_id])->fetchField(); if (!$exists) { $this->logMessage('An Error was encountered retrieving the genetic map.'); - return FALSE; + return 2; } // Retrieve trait to add QTL Data to. $trait_cv_id = $arguments['trait_cv_id']; if (!$trait_cv_id) { $this->logMessage('An Error was encountered retrieving the trait cv.'); - return FALSE; + return 3; } // Check that the trait exists. $exists = chado_query('SELECT true FROM {cv} WHERE cv_id=:id', [':id' => $trait_cv_id])->fetchField(); if (!$exists) { $this->logMessage('An Error was encountered retrieving the trait.'); - return FALSE; + return 4; } // Next, add the QTLs. From d5424730343487d293529f24d18a17e581f5410e Mon Sep 17 00:00:00 2001 From: Reynold Date: Mon, 22 Feb 2021 10:03:50 -0600 Subject: [PATCH 05/15] Echo class values --- includes/TripalImporter/QTLImporter.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/TripalImporter/QTLImporter.inc b/includes/TripalImporter/QTLImporter.inc index 3034d59..2fe6834 100644 --- a/includes/TripalImporter/QTLImporter.inc +++ b/includes/TripalImporter/QTLImporter.inc @@ -150,7 +150,7 @@ class QTLImporter extends TripalImporter { $featuremap_id = $arguments['featuremap_name']; if (!$featuremap_id) { $this->logMessage('An Error was encountered retrieving the genetic map.'); - return 1; + return $arguments['featuremap_name']; } // Check that the map exists. $exists = chado_query('SELECT true FROM {featuremap} WHERE From 87a2ddee7bdb34afd203e81dd6fbaf117776fa18 Mon Sep 17 00:00:00 2001 From: Reynold Date: Mon, 22 Feb 2021 10:11:32 -0600 Subject: [PATCH 06/15] Echo class values --- includes/TripalImporter/QTLImporter.inc | 8 ++++---- tests/QTLImporterTest.php | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/includes/TripalImporter/QTLImporter.inc b/includes/TripalImporter/QTLImporter.inc index 2fe6834..f111f2c 100644 --- a/includes/TripalImporter/QTLImporter.inc +++ b/includes/TripalImporter/QTLImporter.inc @@ -150,28 +150,28 @@ class QTLImporter extends TripalImporter { $featuremap_id = $arguments['featuremap_name']; if (!$featuremap_id) { $this->logMessage('An Error was encountered retrieving the genetic map.'); - return $arguments['featuremap_name']; + return FALSE; } // Check that the map exists. $exists = chado_query('SELECT true FROM {featuremap} WHERE featuremap_id=:id', [':id' => $featuremap_id])->fetchField(); if (!$exists) { $this->logMessage('An Error was encountered retrieving the genetic map.'); - return 2; + return FALSE; } // Retrieve trait to add QTL Data to. $trait_cv_id = $arguments['trait_cv_id']; if (!$trait_cv_id) { $this->logMessage('An Error was encountered retrieving the trait cv.'); - return 3; + return FALSE; } // Check that the trait exists. $exists = chado_query('SELECT true FROM {cv} WHERE cv_id=:id', [':id' => $trait_cv_id])->fetchField(); if (!$exists) { $this->logMessage('An Error was encountered retrieving the trait.'); - return 4; + return FALSE; } // Next, add the QTLs. diff --git a/tests/QTLImporterTest.php b/tests/QTLImporterTest.php index 86b5004..d3c2c28 100644 --- a/tests/QTLImporterTest.php +++ b/tests/QTLImporterTest.php @@ -90,7 +90,7 @@ public function testRunExpectFail() { */ public function testRun() { // Supress tripal errors - putenv("TRIPAL_SUPPRESS_ERRORS=TRUE"); + putenv("TRIPAL_SUPPRESS_ERRORS=FALSE"); ob_start(); $seeder = GeneticMapSeeder::seed(); @@ -112,7 +112,7 @@ public function testRun() { // Now we run the importer! $success = $importer->run(); $this->assertNotFalse($success, - "The importer returned an error..." . $success); + "The importer returned an error." . $args); // Finally, check that the data is in the correct tables, etc. // -- check that the QTL features were created. From 0b7321765105788e78cb10e1794ffa992f9f025f Mon Sep 17 00:00:00 2001 From: Reynold Date: Mon, 22 Feb 2021 10:18:54 -0600 Subject: [PATCH 07/15] Echo class values --- tests/QTLImporterTest.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/QTLImporterTest.php b/tests/QTLImporterTest.php index d3c2c28..b17df19 100644 --- a/tests/QTLImporterTest.php +++ b/tests/QTLImporterTest.php @@ -90,7 +90,7 @@ public function testRunExpectFail() { */ public function testRun() { // Supress tripal errors - putenv("TRIPAL_SUPPRESS_ERRORS=FALSE"); + putenv("TRIPAL_SUPPRESS_ERRORS=TRUE"); ob_start(); $seeder = GeneticMapSeeder::seed(); @@ -112,7 +112,10 @@ public function testRun() { // Now we run the importer! $success = $importer->run(); $this->assertNotFalse($success, - "The importer returned an error." . $args); + "The importer returned an error."); + + print_r($args); + print_r($file); // Finally, check that the data is in the correct tables, etc. // -- check that the QTL features were created. From 1aff2eac66fe485f6d397382534f71ab9d0609a9 Mon Sep 17 00:00:00 2001 From: Reynold Date: Mon, 22 Feb 2021 10:31:44 -0600 Subject: [PATCH 08/15] Echo class values --- tests/QTLImporterTest.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/QTLImporterTest.php b/tests/QTLImporterTest.php index b17df19..3ab9b90 100644 --- a/tests/QTLImporterTest.php +++ b/tests/QTLImporterTest.php @@ -112,10 +112,7 @@ public function testRun() { // Now we run the importer! $success = $importer->run(); $this->assertNotFalse($success, - "The importer returned an error."); - - print_r($args); - print_r($file); + "The importer returned an error." . print_r($args)); // Finally, check that the data is in the correct tables, etc. // -- check that the QTL features were created. From 60564993d34d850b916cab14162cd718efdfc1b4 Mon Sep 17 00:00:00 2001 From: Reynold Date: Mon, 22 Feb 2021 10:50:07 -0600 Subject: [PATCH 09/15] Echo class values --- tests/QTLImporterTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/QTLImporterTest.php b/tests/QTLImporterTest.php index 3ab9b90..de70e8e 100644 --- a/tests/QTLImporterTest.php +++ b/tests/QTLImporterTest.php @@ -112,7 +112,7 @@ public function testRun() { // Now we run the importer! $success = $importer->run(); $this->assertNotFalse($success, - "The importer returned an error." . print_r($args)); + "The importer returned an error.". $mapdetails['featuremap_id'] . ' - ' . $trait_term->cv_id); // Finally, check that the data is in the correct tables, etc. // -- check that the QTL features were created. From f86117c3b7098b087a54b741f3ea83f2b5558ed3 Mon Sep 17 00:00:00 2001 From: Reynold Date: Mon, 22 Feb 2021 11:14:58 -0600 Subject: [PATCH 10/15] Implements GitHub Actions --- includes/TripalImporter/QTLImporter.inc | 2 +- tests/QTLImporterTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/TripalImporter/QTLImporter.inc b/includes/TripalImporter/QTLImporter.inc index f111f2c..ddfd09d 100644 --- a/includes/TripalImporter/QTLImporter.inc +++ b/includes/TripalImporter/QTLImporter.inc @@ -148,7 +148,7 @@ class QTLImporter extends TripalImporter { // Retrieve map to add QTL Data to. $featuremap_id = $arguments['featuremap_name']; - if (!$featuremap_id) { + if ($featuremap_id < 1) { $this->logMessage('An Error was encountered retrieving the genetic map.'); return FALSE; } diff --git a/tests/QTLImporterTest.php b/tests/QTLImporterTest.php index de70e8e..1063c7c 100644 --- a/tests/QTLImporterTest.php +++ b/tests/QTLImporterTest.php @@ -112,7 +112,7 @@ public function testRun() { // Now we run the importer! $success = $importer->run(); $this->assertNotFalse($success, - "The importer returned an error.". $mapdetails['featuremap_id'] . ' - ' . $trait_term->cv_id); + "The importer returned an error."); // Finally, check that the data is in the correct tables, etc. // -- check that the QTL features were created. From de4a3715442f8cfd2d878a21b40f43d781520a05 Mon Sep 17 00:00:00 2001 From: Reynold Date: Mon, 22 Feb 2021 11:44:06 -0600 Subject: [PATCH 11/15] Echo class values --- includes/TripalImporter/QTLImporter.inc | 3 ++- tests/QTLImporterTest.php | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/includes/TripalImporter/QTLImporter.inc b/includes/TripalImporter/QTLImporter.inc index ddfd09d..78c6c3c 100644 --- a/includes/TripalImporter/QTLImporter.inc +++ b/includes/TripalImporter/QTLImporter.inc @@ -148,7 +148,8 @@ class QTLImporter extends TripalImporter { // Retrieve map to add QTL Data to. $featuremap_id = $arguments['featuremap_name']; - if ($featuremap_id < 1) { + return (!$featuremap_id) ? 404 : $featuremap_id; + if (!$featuremap_id) { $this->logMessage('An Error was encountered retrieving the genetic map.'); return FALSE; } diff --git a/tests/QTLImporterTest.php b/tests/QTLImporterTest.php index 1063c7c..29dee3d 100644 --- a/tests/QTLImporterTest.php +++ b/tests/QTLImporterTest.php @@ -112,7 +112,7 @@ public function testRun() { // Now we run the importer! $success = $importer->run(); $this->assertNotFalse($success, - "The importer returned an error."); + "The importer returned an error....". $success); // Finally, check that the data is in the correct tables, etc. // -- check that the QTL features were created. From 9af9d227a64f428df7ce6ab054e472d48f8563a8 Mon Sep 17 00:00:00 2001 From: Reynold Date: Mon, 22 Feb 2021 12:51:59 -0600 Subject: [PATCH 12/15] Implements GitHub Actions --- includes/TripalImporter/QTLImporter.inc | 11 +++++++++-- tests/QTLImporterTest.php | 3 ++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/includes/TripalImporter/QTLImporter.inc b/includes/TripalImporter/QTLImporter.inc index 78c6c3c..8219e39 100644 --- a/includes/TripalImporter/QTLImporter.inc +++ b/includes/TripalImporter/QTLImporter.inc @@ -5,7 +5,7 @@ * Provides support for loading of MST map files. */ class QTLImporter extends TripalImporter { - + /** * The name of this loader. * @@ -92,6 +92,11 @@ class QTLImporter extends TripalImporter { */ public static $use_analysis = FALSE; + /** + * Feature map name used to run the importer. + */ + public $featuremap_name; + /** * Provides additional elements for the upload form including map metadata. */ @@ -147,8 +152,10 @@ class QTLImporter extends TripalImporter { $file_path = $this->arguments['files'][0]['file_path']; // Retrieve map to add QTL Data to. + $arguments['featuremap_name'] = $arguments['featuremap_name'] + ?? $this->featuremap_name; + $featuremap_id = $arguments['featuremap_name']; - return (!$featuremap_id) ? 404 : $featuremap_id; if (!$featuremap_id) { $this->logMessage('An Error was encountered retrieving the genetic map.'); return FALSE; diff --git a/tests/QTLImporterTest.php b/tests/QTLImporterTest.php index 29dee3d..4297a99 100644 --- a/tests/QTLImporterTest.php +++ b/tests/QTLImporterTest.php @@ -110,9 +110,10 @@ public function testRun() { $importer->prepareFiles(); // Now we run the importer! + $importer->featuremap_name = $mapdetails['featuremap_id']; $success = $importer->run(); $this->assertNotFalse($success, - "The importer returned an error....". $success); + "The importer returned an error."); // Finally, check that the data is in the correct tables, etc. // -- check that the QTL features were created. From 85c021ab83b22a671bfb21b137782b5300a31ea0 Mon Sep 17 00:00:00 2001 From: Reynold Date: Mon, 22 Feb 2021 12:59:51 -0600 Subject: [PATCH 13/15] Implements GitHub Actions --- includes/TripalImporter/QTLImporter.inc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/includes/TripalImporter/QTLImporter.inc b/includes/TripalImporter/QTLImporter.inc index 8219e39..c54bbcf 100644 --- a/includes/TripalImporter/QTLImporter.inc +++ b/includes/TripalImporter/QTLImporter.inc @@ -152,8 +152,7 @@ class QTLImporter extends TripalImporter { $file_path = $this->arguments['files'][0]['file_path']; // Retrieve map to add QTL Data to. - $arguments['featuremap_name'] = $arguments['featuremap_name'] - ?? $this->featuremap_name; + $arguments['featuremap_name'] = $this->featuremap_name; $featuremap_id = $arguments['featuremap_name']; if (!$featuremap_id) { From 584b55d3a9eb6e9e2bb93496248d43399644b70e Mon Sep 17 00:00:00 2001 From: Reynold Date: Mon, 22 Feb 2021 13:09:34 -0600 Subject: [PATCH 14/15] Echo class values --- includes/TripalImporter/QTLImporter.inc | 4 +--- tests/QTLImporterTest.php | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/includes/TripalImporter/QTLImporter.inc b/includes/TripalImporter/QTLImporter.inc index c54bbcf..93f6923 100644 --- a/includes/TripalImporter/QTLImporter.inc +++ b/includes/TripalImporter/QTLImporter.inc @@ -152,12 +152,10 @@ class QTLImporter extends TripalImporter { $file_path = $this->arguments['files'][0]['file_path']; // Retrieve map to add QTL Data to. - $arguments['featuremap_name'] = $this->featuremap_name; - $featuremap_id = $arguments['featuremap_name']; if (!$featuremap_id) { $this->logMessage('An Error was encountered retrieving the genetic map.'); - return FALSE; + return $this->featuremap_name . '-' . $featuremap_id; } // Check that the map exists. $exists = chado_query('SELECT true FROM {featuremap} WHERE diff --git a/tests/QTLImporterTest.php b/tests/QTLImporterTest.php index 4297a99..8092218 100644 --- a/tests/QTLImporterTest.php +++ b/tests/QTLImporterTest.php @@ -113,7 +113,7 @@ public function testRun() { $importer->featuremap_name = $mapdetails['featuremap_id']; $success = $importer->run(); $this->assertNotFalse($success, - "The importer returned an error."); + "The importer returned an error." . 'b:' . $mapdetails['featuremap_id'] . 'a:' . $success); // Finally, check that the data is in the correct tables, etc. // -- check that the QTL features were created. From eda99dfa10ee34419f988b9e7719fe9821a194c1 Mon Sep 17 00:00:00 2001 From: Reynold Date: Mon, 22 Feb 2021 13:21:46 -0600 Subject: [PATCH 15/15] Implements GitHub Actions --- includes/TripalImporter/QTLImporter.inc | 12 ++++-------- tests/QTLImporterTest.php | 5 ++--- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/includes/TripalImporter/QTLImporter.inc b/includes/TripalImporter/QTLImporter.inc index 93f6923..a9368a8 100644 --- a/includes/TripalImporter/QTLImporter.inc +++ b/includes/TripalImporter/QTLImporter.inc @@ -92,11 +92,6 @@ class QTLImporter extends TripalImporter { */ public static $use_analysis = FALSE; - /** - * Feature map name used to run the importer. - */ - public $featuremap_name; - /** * Provides additional elements for the upload form including map metadata. */ @@ -135,7 +130,7 @@ class QTLImporter extends TripalImporter { /** * Import the map. */ - public function run() { + public function run($f_id = null) { // All values provided by the user in the Importer's form widgets are // made available to us here by the Class' arguments member variable. @@ -152,10 +147,11 @@ class QTLImporter extends TripalImporter { $file_path = $this->arguments['files'][0]['file_path']; // Retrieve map to add QTL Data to. - $featuremap_id = $arguments['featuremap_name']; + $featuremap_id = ($f_id && $f_id > 1) ? $f_id : $arguments['featuremap_name']; + if (!$featuremap_id) { $this->logMessage('An Error was encountered retrieving the genetic map.'); - return $this->featuremap_name . '-' . $featuremap_id; + return FALSE; } // Check that the map exists. $exists = chado_query('SELECT true FROM {featuremap} WHERE diff --git a/tests/QTLImporterTest.php b/tests/QTLImporterTest.php index 8092218..8d87d09 100644 --- a/tests/QTLImporterTest.php +++ b/tests/QTLImporterTest.php @@ -110,10 +110,9 @@ public function testRun() { $importer->prepareFiles(); // Now we run the importer! - $importer->featuremap_name = $mapdetails['featuremap_id']; - $success = $importer->run(); + $success = $importer->run($mapdetails['featuremap_id']); $this->assertNotFalse($success, - "The importer returned an error." . 'b:' . $mapdetails['featuremap_id'] . 'a:' . $success); + "The importer returned an error."); // Finally, check that the data is in the correct tables, etc. // -- check that the QTL features were created.