PHPUnit can be initialised with Oracle
authorFrederic Massart <fred@moodle.com>
Wed, 22 Oct 2014 05:37:35 +0000 (13:37 +0800)
committerFrederic Massart <fred@moodle.com>
Wed, 22 Oct 2014 05:37:43 +0000 (13:37 +0800)
mdk/commands/phpunit.py
mdk/moodle.py

index 5e7fdb3..3356890 100644 (file)
@@ -27,7 +27,7 @@ import os
 import gzip
 import urllib
 from ..command import Command
-from ..tools import process
+from ..tools import process, question
 
 
 class PhpunitCommand(Command):
@@ -121,7 +121,16 @@ class PhpunitCommand(Command):
 
         # Run cli
         try:
-            M.initPHPUnit(force=args.force)
+
+            # If Oracle, ask the user for a Behat prefix, if not set.
+            prefix = M.get('phpunit_prefix')
+            if M.get('dbtype') == 'oci' and (args.force or not prefix or len(prefix) > 2):
+                while not prefix or len(prefix) > 2:
+                    prefix = question('What prefix would you like to use? (Oracle, max 2 chars)')
+            else:
+                prefix = None
+
+            M.initPHPUnit(force=args.force, prefix=prefix)
             logging.info('PHPUnit ready!')
 
             if args.unittest or args.testcase or args.filter:
index 6970b7d..64cf6c3 100644 (file)
@@ -281,7 +281,7 @@ class Moodle(object):
 
         return headcommit
 
-    def initPHPUnit(self, force=False):
+    def initPHPUnit(self, force=False, prefix=None):
         """Initialise the PHPUnit environment"""
 
         if self.branch_compare(23, '<'):
@@ -294,8 +294,15 @@ class Moodle(object):
             mkdir(phpunit_dataroot, 0777)
 
         # Set PHPUnit prefix
-        phpunit_prefix = 'phpu_'
-        self.updateConfig('phpunit_prefix', phpunit_prefix)
+        currentPrefix = self.get('phpunit_prefix')
+        phpunit_prefix = prefix or 'phpu_'
+
+        if not currentPrefix or force:
+            self.updateConfig('phpunit_prefix', phpunit_prefix)
+        elif currentPrefix != phpunit_prefix and self.get('dbtype') != 'oci':
+            # Warn that a prefix is already set and we did not change it.
+            # No warning for Oracle as we need to set it to something else.
+            logging.warning('PHPUnit prefix not changed, already set to \'%s\', expected \'%s\'.' % (currentPrefix, phpunit_prefix))
 
         result = (None, None, None)
         exception = None