Browse Source

build bootstrap etc

Vlad Dracula 7 years ago
parent
commit
9c99f38694
4 changed files with 59 additions and 1 deletions
  1. 1 1
      .travis.yml
  2. 12 0
      phpunit.xml
  3. 30 0
      test/bootstrap.php
  4. 16 0
      test/tripal_test.test

+ 1 - 1
.travis.yml

@@ -10,7 +10,7 @@ script:
   - git clone https://github.com/tripal/docker-tripal-centos  && cd docker-tripal-centos
   - cd tripal-v2 && docker build -t tripal-v2 .
   - docker run -it -d -p 8080:80 tripal-v2 /bin/bash
-  - docker exec -it tripal-v2 bash -c drush pm-disable tripal_core -y && cd /var/www/html/sites/all/modules/tripal/ && git checkout 7.x-3.x && drush pm-enable tripal -y && drush pm-enable tripal_chado -y && drush cc all --yes && drush status'
+  - docker exec -it tripal-v2 bash -c 'drush pm-disable tripal_core -y && cd /var/www/html/sites/all/modules/tripal/ && git checkout 7.x-3.x && drush pm-enable tripal -y && drush pm-enable tripal_chado -y && drush cc all --yes && drush status'
   - cd ../tripal-v3 && docker -t tripal-v3 build .
   - docker run -it -d -p 8080:80 tripal-v3 /bin/bash
   - docker exec -it tripal-v3 bash -c 'cd /var/www/html/sites/all/modules/tripal/ &&composer install && ./vendor/bin/phpunit'

+ 12 - 0
phpunit.xml

@@ -0,0 +1,12 @@
+<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:noNamespaceSchemaLocation="phpunit.xsd"
+         bootstrap="tests/bootstrap.php"
+         verbose="true"
+         colors="true">
+    <testsuites>
+        <testsuite name="default">
+            <directory suffix=".test">./test/</directory>
+            <exclude>tests/bootstrap.php</exclude>
+        </testsuite>
+    </testsuites>
+</phpunit>

+ 30 - 0
test/bootstrap.php

@@ -0,0 +1,30 @@
+<?php
+test_suite_read_and_set_environment_variables();
+$drupal_root = getenv('DRUPAL_ROOT');
+define('DRUPAL_ROOT', $drupal_root ?: __DIR__.'/../../../../..');
+require_once DRUPAL_ROOT.'/includes/bootstrap.inc';
+$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
+$current_dir = getcwd();
+chdir(DRUPAL_ROOT);
+// Bootstrap Drupal.
+drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
+chdir($current_dir);
+/**
+ * @throws \Exception
+ */
+function test_suite_read_and_set_environment_variables() {
+  $filename = __DIR__.'/.env';
+  if(file_exists($filename)) {
+    $file = fopen($filename, 'r');
+    while ($line = str_replace("\n", '', fgets($file))) {
+      // break line into key value
+      $env = explode('=', $line);
+      if(count($env) === 2) {
+        putenv($line);
+      } else {
+        throw new Exception('Invalid environment line: ' . $line);
+      }
+    }
+    fclose($file);
+  }
+}

+ 16 - 0
test/tripal_test.test

@@ -0,0 +1,16 @@
+<?php
+
+use PHPUnit\Framework\TestCase;
+
+//some reading for organizing and annotating tests
+//https://stackoverflow.com/questions/8313283/phpunit-best-practices-to-organize-tests
+//https://jtreminio.com/2013/03/unit-testing-tutorial-introduction-to-phpunit/
+
+final class tripal_test extends TestCase {
+
+  public function testTrueIsTrue() {
+    $foo = TRUE;
+    $this->assertTrue($foo);
+
+  }
+}