Ver Fonte

Update tripal test suite, add more jobs api tests and use silent function where appropriate

Abdullah Almsaeed há 6 anos atrás
pai
commit
3a5c41b8f2

+ 3 - 1
composer.json

@@ -1,7 +1,9 @@
 {
+  "name": "tripal",
+  "description": "Tripal is an toolkit to facilitate construction of online genomic, genetic (and other biological) websites.",
   "require-dev": {
     "doctrine/instantiator": "1.0.*",
-    "statonlab/tripal-test-suite": "^1.1"
+    "statonlab/tripal-test-suite": "1.*"
   },
   "require": {
   }

+ 62 - 59
composer.lock

@@ -1,10 +1,10 @@
 {
     "_readme": [
         "This file locks the dependencies of your project to a known state",
-        "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
+        "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "c8b425537daabed28cd865fb02a05684",
+    "content-hash": "fd3ab0a8fd06e0532a7764f20a9aa52b",
     "packages": [],
     "packages-dev": [
         {
@@ -63,16 +63,16 @@
         },
         {
             "name": "fzaninotto/faker",
-            "version": "v1.7.1",
+            "version": "v1.8.0",
             "source": {
                 "type": "git",
                 "url": "https://github.com/fzaninotto/Faker.git",
-                "reference": "d3ed4cc37051c1ca52d22d76b437d14809fc7e0d"
+                "reference": "f72816b43e74063c8b10357394b6bba8cb1c10de"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/fzaninotto/Faker/zipball/d3ed4cc37051c1ca52d22d76b437d14809fc7e0d",
-                "reference": "d3ed4cc37051c1ca52d22d76b437d14809fc7e0d",
+                "url": "https://api.github.com/repos/fzaninotto/Faker/zipball/f72816b43e74063c8b10357394b6bba8cb1c10de",
+                "reference": "f72816b43e74063c8b10357394b6bba8cb1c10de",
                 "shasum": ""
             },
             "require": {
@@ -80,7 +80,7 @@
             },
             "require-dev": {
                 "ext-intl": "*",
-                "phpunit/phpunit": "^4.0 || ^5.0",
+                "phpunit/phpunit": "^4.8.35 || ^5.7",
                 "squizlabs/php_codesniffer": "^1.5"
             },
             "type": "library",
@@ -109,7 +109,7 @@
                 "faker",
                 "fixtures"
             ],
-            "time": "2017-08-15T16:48:10+00:00"
+            "time": "2018-07-12T10:23:15+00:00"
         },
         {
             "name": "guzzlehttp/guzzle",
@@ -294,25 +294,28 @@
         },
         {
             "name": "myclabs/deep-copy",
-            "version": "1.7.0",
+            "version": "1.8.1",
             "source": {
                 "type": "git",
                 "url": "https://github.com/myclabs/DeepCopy.git",
-                "reference": "3b8a3a99ba1f6a3952ac2747d989303cbd6b7a3e"
+                "reference": "3e01bdad3e18354c3dce54466b7fbe33a9f9f7f8"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/3b8a3a99ba1f6a3952ac2747d989303cbd6b7a3e",
-                "reference": "3b8a3a99ba1f6a3952ac2747d989303cbd6b7a3e",
+                "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/3e01bdad3e18354c3dce54466b7fbe33a9f9f7f8",
+                "reference": "3e01bdad3e18354c3dce54466b7fbe33a9f9f7f8",
                 "shasum": ""
             },
             "require": {
-                "php": "^5.6 || ^7.0"
+                "php": "^7.1"
+            },
+            "replace": {
+                "myclabs/deep-copy": "self.version"
             },
             "require-dev": {
                 "doctrine/collections": "^1.0",
                 "doctrine/common": "^2.6",
-                "phpunit/phpunit": "^4.1"
+                "phpunit/phpunit": "^7.1"
             },
             "type": "library",
             "autoload": {
@@ -335,7 +338,7 @@
                 "object",
                 "object graph"
             ],
-            "time": "2017-10-19T19:58:43+00:00"
+            "time": "2018-06-11T23:09:50+00:00"
         },
         {
             "name": "phar-io/manifest",
@@ -593,16 +596,16 @@
         },
         {
             "name": "phpspec/prophecy",
-            "version": "1.7.6",
+            "version": "1.8.0",
             "source": {
                 "type": "git",
                 "url": "https://github.com/phpspec/prophecy.git",
-                "reference": "33a7e3c4fda54e912ff6338c48823bd5c0f0b712"
+                "reference": "4ba436b55987b4bf311cb7c6ba82aa528aac0a06"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/phpspec/prophecy/zipball/33a7e3c4fda54e912ff6338c48823bd5c0f0b712",
-                "reference": "33a7e3c4fda54e912ff6338c48823bd5c0f0b712",
+                "url": "https://api.github.com/repos/phpspec/prophecy/zipball/4ba436b55987b4bf311cb7c6ba82aa528aac0a06",
+                "reference": "4ba436b55987b4bf311cb7c6ba82aa528aac0a06",
                 "shasum": ""
             },
             "require": {
@@ -614,12 +617,12 @@
             },
             "require-dev": {
                 "phpspec/phpspec": "^2.5|^3.2",
-                "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.5"
+                "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.5 || ^7.1"
             },
             "type": "library",
             "extra": {
                 "branch-alias": {
-                    "dev-master": "1.7.x-dev"
+                    "dev-master": "1.8.x-dev"
                 }
             },
             "autoload": {
@@ -652,20 +655,20 @@
                 "spy",
                 "stub"
             ],
-            "time": "2018-04-18T13:57:24+00:00"
+            "time": "2018-08-05T17:53:17+00:00"
         },
         {
             "name": "phpunit/php-code-coverage",
-            "version": "6.0.4",
+            "version": "6.0.5",
             "source": {
                 "type": "git",
                 "url": "https://github.com/sebastianbergmann/php-code-coverage.git",
-                "reference": "52187754b0eed0b8159f62a6fa30073327e8c2ca"
+                "reference": "4cab20a326d14de7575a8e235c70d879b569a57a"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/52187754b0eed0b8159f62a6fa30073327e8c2ca",
-                "reference": "52187754b0eed0b8159f62a6fa30073327e8c2ca",
+                "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/4cab20a326d14de7575a8e235c70d879b569a57a",
+                "reference": "4cab20a326d14de7575a8e235c70d879b569a57a",
                 "shasum": ""
             },
             "require": {
@@ -715,7 +718,7 @@
                 "testing",
                 "xunit"
             ],
-            "time": "2018-04-29T14:59:09+00:00"
+            "time": "2018-05-28T11:49:20+00:00"
         },
         {
             "name": "phpunit/php-file-iterator",
@@ -985,16 +988,16 @@
         },
         {
             "name": "phpunit/phpunit-mock-objects",
-            "version": "6.1.1",
+            "version": "6.1.2",
             "source": {
                 "type": "git",
                 "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git",
-                "reference": "70c740bde8fd9ea9ea295be1cd875dd7b267e157"
+                "reference": "f9756fd4f43f014cb2dca98deeaaa8ce5500a36e"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/70c740bde8fd9ea9ea295be1cd875dd7b267e157",
-                "reference": "70c740bde8fd9ea9ea295be1cd875dd7b267e157",
+                "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/f9756fd4f43f014cb2dca98deeaaa8ce5500a36e",
+                "reference": "f9756fd4f43f014cb2dca98deeaaa8ce5500a36e",
                 "shasum": ""
             },
             "require": {
@@ -1037,7 +1040,7 @@
                 "mock",
                 "xunit"
             ],
-            "time": "2018-04-11T04:50:36+00:00"
+            "time": "2018-05-29T13:54:20+00:00"
         },
         {
             "name": "psr/http-message",
@@ -1136,16 +1139,16 @@
         },
         {
             "name": "sebastian/comparator",
-            "version": "3.0.0",
+            "version": "3.0.2",
             "source": {
                 "type": "git",
                 "url": "https://github.com/sebastianbergmann/comparator.git",
-                "reference": "ed5fd2281113729f1ebcc64d101ad66028aeb3d5"
+                "reference": "5de4fc177adf9bce8df98d8d141a7559d7ccf6da"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/ed5fd2281113729f1ebcc64d101ad66028aeb3d5",
-                "reference": "ed5fd2281113729f1ebcc64d101ad66028aeb3d5",
+                "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/5de4fc177adf9bce8df98d8d141a7559d7ccf6da",
+                "reference": "5de4fc177adf9bce8df98d8d141a7559d7ccf6da",
                 "shasum": ""
             },
             "require": {
@@ -1196,20 +1199,20 @@
                 "compare",
                 "equality"
             ],
-            "time": "2018-04-18T13:33:00+00:00"
+            "time": "2018-07-12T15:12:46+00:00"
         },
         {
             "name": "sebastian/diff",
-            "version": "3.0.0",
+            "version": "3.0.1",
             "source": {
                 "type": "git",
                 "url": "https://github.com/sebastianbergmann/diff.git",
-                "reference": "e09160918c66281713f1c324c1f4c4c3037ba1e8"
+                "reference": "366541b989927187c4ca70490a35615d3fef2dce"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/e09160918c66281713f1c324c1f4c4c3037ba1e8",
-                "reference": "e09160918c66281713f1c324c1f4c4c3037ba1e8",
+                "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/366541b989927187c4ca70490a35615d3fef2dce",
+                "reference": "366541b989927187c4ca70490a35615d3fef2dce",
                 "shasum": ""
             },
             "require": {
@@ -1252,7 +1255,7 @@
                 "unidiff",
                 "unified diff"
             ],
-            "time": "2018-02-01T13:45:15+00:00"
+            "time": "2018-06-10T07:54:39+00:00"
         },
         {
             "name": "sebastian/environment",
@@ -1654,16 +1657,16 @@
         },
         {
             "name": "statonlab/tripal-test-suite",
-            "version": "1.1.0",
+            "version": "1.4.0",
             "source": {
                 "type": "git",
                 "url": "https://github.com/statonlab/TripalTestSuite.git",
-                "reference": "80b60a14b80f00d164ae5ba8511080d725526d38"
+                "reference": "e469f7fde2cf69303dc22315b142b46b027c9931"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/statonlab/TripalTestSuite/zipball/80b60a14b80f00d164ae5ba8511080d725526d38",
-                "reference": "80b60a14b80f00d164ae5ba8511080d725526d38",
+                "url": "https://api.github.com/repos/statonlab/TripalTestSuite/zipball/e469f7fde2cf69303dc22315b142b46b027c9931",
+                "reference": "e469f7fde2cf69303dc22315b142b46b027c9931",
                 "shasum": ""
             },
             "require": {
@@ -1698,20 +1701,20 @@
                     "email": "bcondon@utk.edu"
                 }
             ],
-            "time": "2018-05-25T13:17:31+00:00"
+            "time": "2018-08-06T19:38:14+00:00"
         },
         {
             "name": "symfony/console",
-            "version": "v4.0.9",
+            "version": "v4.1.3",
             "source": {
                 "type": "git",
                 "url": "https://github.com/symfony/console.git",
-                "reference": "3e820bc2c520a87ca209ad8fa961c97f42e0b4ae"
+                "reference": "ca80b8ced97cf07390078b29773dc384c39eee1f"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/symfony/console/zipball/3e820bc2c520a87ca209ad8fa961c97f42e0b4ae",
-                "reference": "3e820bc2c520a87ca209ad8fa961c97f42e0b4ae",
+                "url": "https://api.github.com/repos/symfony/console/zipball/ca80b8ced97cf07390078b29773dc384c39eee1f",
+                "reference": "ca80b8ced97cf07390078b29773dc384c39eee1f",
                 "shasum": ""
             },
             "require": {
@@ -1739,7 +1742,7 @@
             "type": "library",
             "extra": {
                 "branch-alias": {
-                    "dev-master": "4.0-dev"
+                    "dev-master": "4.1-dev"
                 }
             },
             "autoload": {
@@ -1766,20 +1769,20 @@
             ],
             "description": "Symfony Console Component",
             "homepage": "https://symfony.com",
-            "time": "2018-04-30T01:23:47+00:00"
+            "time": "2018-07-26T11:24:31+00:00"
         },
         {
             "name": "symfony/polyfill-mbstring",
-            "version": "v1.8.0",
+            "version": "v1.9.0",
             "source": {
                 "type": "git",
                 "url": "https://github.com/symfony/polyfill-mbstring.git",
-                "reference": "3296adf6a6454a050679cde90f95350ad604b171"
+                "reference": "d0cd638f4634c16d8df4508e847f14e9e43168b8"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/3296adf6a6454a050679cde90f95350ad604b171",
-                "reference": "3296adf6a6454a050679cde90f95350ad604b171",
+                "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/d0cd638f4634c16d8df4508e847f14e9e43168b8",
+                "reference": "d0cd638f4634c16d8df4508e847f14e9e43168b8",
                 "shasum": ""
             },
             "require": {
@@ -1791,7 +1794,7 @@
             "type": "library",
             "extra": {
                 "branch-alias": {
-                    "dev-master": "1.8-dev"
+                    "dev-master": "1.9-dev"
                 }
             },
             "autoload": {
@@ -1825,7 +1828,7 @@
                 "portable",
                 "shim"
             ],
-            "time": "2018-04-26T10:06:28+00:00"
+            "time": "2018-08-06T14:22:27+00:00"
         },
         {
             "name": "theseer/tokenizer",

+ 24 - 0
tests/DataFactory.php

@@ -71,3 +71,27 @@ Factory::define('chado.feature', function (Faker\Generator $faker) {
         'type_id' => factory('chado.cvterm')->create()->cvterm_id,
     ];
 });
+
+/** @see  StatonLab\TripalTestSuite\Database\Factory::define() */
+Factory::define('tripal_jobs', function (Faker\Generator $faker) {
+  return [
+    'uid' => 1,
+    'job_name' => $faker->sentence,
+    'modulename' => $faker->word,
+    'callback' => $faker->word,
+    'arguments' => serialize(['arg' => $faker->word]),
+    'progress' => 0,
+    'status' => $faker->randomElement([
+      'Waiting',
+      'Cancelled',
+      'Error',
+      'Completed',
+    ]),
+    'submit_date' => time(),
+    'start_time' => NULL,
+    'end_time' => NULL,
+    'error_msg' => NULL,
+    'pid' => $faker->numberBetween(1, 10000),
+    'priority' => $faker->numberBetween(1, 10),
+  ];
+}, 'job_id');

+ 45 - 3
tests/tripal/api/TripalJobsApiTest.php

@@ -1,10 +1,11 @@
 <?php
+
 namespace Tests\tripal\api;
 
 use StatonLab\TripalTestSuite\DBTransaction;
 use StatonLab\TripalTestSuite\TripalTestCase;
 
-class TripalJobsApiTest extends TripalTestCase {
+class TripalJobsApiTest extends TripalTestCase{
 
   use DBTransaction;
 
@@ -13,8 +14,49 @@ class TripalJobsApiTest extends TripalTestCase {
    *
    * @test
    */
-  public function should_create_a_tripal_job() {
-    $job_id = tripal_add_job('Test adding jobs', 'tripal', 'tripal_tripal_cron_notification', [], 1);
+  public function testCreatingAJobWorks() {
+    $job_id = tripal_add_job('Test adding jobs', 'tripal',
+      'tripal_tripal_cron_notification', [], 1);
     $this->assertTrue(is_numeric($job_id));
   }
+
+  /** @test */
+  public function testRetrievingAJob() {
+    $job = factory('tripal_jobs')->create();
+
+    $job2 = tripal_get_job($job->job_id);
+
+    $this->assertNotEmpty($job2);
+    $this->assertObjectHasAttribute('job_id', $job2);
+  }
+
+  /** @test */
+  public function testRetrievingActiveJobs() {
+    factory('tripal_jobs')->create();
+    $jobs = tripal_get_active_jobs();
+
+    $this->assertNotEmpty($jobs);
+  }
+
+  /** @test */
+  public function testRetrievingActiveJobsWithAGivenModule() {
+    factory('tripal_jobs')->create([
+      'modulename' => 'tripal_test_suite',
+      'status' => 'Running',
+    ]);
+    $jobs = tripal_get_active_jobs('tripal_test_suite');
+
+    $this->assertNotEmpty($jobs);
+  }
+
+  /** @test */
+  public function testRetrievingCompletedJobsDoesNotHappen() {
+    factory('tripal_jobs')->create([
+      'modulename' => 'tripal_test_suite',
+      'status' => 'Completed',
+    ]);
+    $jobs = tripal_get_active_jobs('tripal_test_suite');
+
+    $this->assertEmpty($jobs);
+  }
 }

+ 26 - 19
tests/tripal_chado/api/TripalChadoAPITest.php

@@ -1,11 +1,11 @@
 <?php
-namespace Tests\tripal_chado\api;
 
+namespace Tests\tripal_chado\api;
 
 use StatonLab\TripalTestSuite\DBTransaction;
 use StatonLab\TripalTestSuite\TripalTestCase;
 
-class TripalChadoAPITest extends TripalTestCase {
+class TripalChadoAPITest extends TripalTestCase{
 
   use DBTransaction;
 
@@ -17,33 +17,39 @@ class TripalChadoAPITest extends TripalTestCase {
    */
   public function test_tripal_chado_publish_records() {
     $genus_string = 'a_genius_genus';
-    //create an organism, publish it
+
+    // Create an organism, publish it
     $organism = factory('chado.organism')->create([
       'genus' => $genus_string,
       'species' => 'fake_species',
     ]);
-    //get bundle ID for organism
+
+    // Get bundle ID for organism
     $bundle = db_select('public.chado_bundle', 'CB')
       ->fields('CB', ['bundle_id'])
       ->condition('data_table', 'organism')
-      ->execute()->fetchField();
+      ->execute()
+      ->fetchField();
 
-    var_dump($bundle);
     $values = ['bundle_name' => 'bio_data_' . $bundle];
 
- //   ob_start();//dont display the job message
-    $bool = chado_publish_records($values);
-   // ob_end_clean();
+    // Don't display the job message
+    $bool = silent(function () use ($values) {
+      return chado_publish_records($values);
+    });
 
-    $this->assertTrue($bool, 'Publishing a fake organism record failed');
+    $this->assertTrue($bool->getReturnValue(),
+      'Publishing a fake organism record failed');
 
-    //ensure that our entity was created
-    $query = db_select('chado.organism', 'O')
-      ->fields('O', ['organism_id']);
-    $query->join('public.chado_bio_data_' . $bundle, 'CBD', 'O.organism_id = CBD.record_id');
+    // Ensure that our entity was created
+    $query = db_select('chado.organism', 'O')->fields('O', ['organism_id']);
+    $query->join('public.chado_bio_data_' . $bundle, 'CBD',
+      'O.organism_id = CBD.record_id');
     $query->condition('O.genus', $genus_string);
     $organism_id = $query->execute()->fetchField();
-    $this->assertNotNull($organism_id, 'Organism with record ID not found in chado_bio_data table.');
+
+    $this->assertNotNull($organism_id,
+      'Organism with record ID not found in chado_bio_data table.');
   }
 
   /**
@@ -52,10 +58,11 @@ class TripalChadoAPITest extends TripalTestCase {
    * @group api
    */
   public function test_tripal_chado_publish_records_false_with_bad_bundle() {
-    putenv("TRIPAL_SUPPRESS_ERRORS=TRUE");//this will fail, so we suppress the tripal error reporter
-    $bool = chado_publish_records(['bundle_name' => 'never_in_a_million_years']);
-    $this->assertFalse($bool);
-    putenv("TRIPAL_SUPPRESS_ERRORS");//unset
+    $bool = silent(function () {
+      return chado_publish_records(['bundle_name' => 'never_in_a_million_years']);
+    });
+
+    $this->assertFalse($bool->getReturnValue());
   }
 
   /**