Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Setup Travis CI for automated testing

  • Loading branch information...
commit bef80ef2db8b7ce17324dec978bde98b01c77d0d 1 parent 0323566
Andrew Coulton authored December 29, 2011
19  .travis.yml
... ...
@@ -0,0 +1,19 @@
  1
+# Configuration file for Travis CI test environment
  2
+language: php
  3
+php:
  4
+  - 5.3
  5
+
  6
+env:
  7
+  - KO_SANDBOX=/home/vagrant/kohana
  8
+
  9
+after_install:
  10
+  # Install vfsStream for unit tests
  11
+  - pyrus channel-discover pear.php-tools.net
  12
+  - pyrus install pat/vfsStream-beta
  13
+  - phpenv rehash
  14
+
  15
+  # Create a kohana environment
  16
+  - php ./dev/ko-sandbox.php
  17
+
  18
+# Run the Mimic tests
  19
+script: phpunit --bootstrap=$KO_SANDBOX/modules/unittest/bootstrap.php --group=mimic $KO_SANDBOX/modules/unittest/tests.php
6  README.md
Source Rendered
... ...
@@ -1,4 +1,4 @@
1  
-# Mimic
  1
+# Mimic [![Build Status](https://secure.travis-ci.org/acoulton/mimic.png)](http://travis-ci.org/acoulton/mimic)
2 2
 
3 3
 Mimic is a module for [Kohana Framework v3.2 and up](http://kohanaframework.org)
4 4
 that allows easy mocking and testing of an application's interaction with external
@@ -67,6 +67,8 @@ just run the following from the base folder:
67 67
 
68 68
     phpunit --bootstrap=modules/unittest/bootstrap.php --group=mimic modules/unittest/tests.php
69 69
 
  70
+The Mimic test suite also runs continuously on [Travis CI](http://travis-ci.org/acoulton/mimic) against the current codebase. Helper scripts are provided in the dev/ folder to create a sandbox with up to date Kohana core and required modules.
  71
+
70 72
 ## Further Documentation
71 73
 Is included with the module, integrated into the Kohana online userguide.
72 74
 
@@ -100,4 +102,4 @@ Pull requests should:
100 102
   further commits are required to complete your solution)
101 103
 * generally speaking, include a unit test or new dataset for an existing test that
102 104
   fails before your new code is merged and passes afterwards
103  
-* adopt the Kohana coding standards
  105
+* adopt the Kohana coding standards
110  dev/bootstrap.php
... ...
@@ -0,0 +1,110 @@
  1
+<?php defined('SYSPATH') or die('No direct script access.');
  2
+
  3
+// -- Environment setup --------------------------------------------------------
  4
+
  5
+// Load the core Kohana class
  6
+require SYSPATH.'classes/kohana/core'.EXT;
  7
+
  8
+if (is_file(APPPATH.'classes/kohana'.EXT))
  9
+{
  10
+	// Application extends the core
  11
+	require APPPATH.'classes/kohana'.EXT;
  12
+}
  13
+else
  14
+{
  15
+	// Load empty core extension
  16
+	require SYSPATH.'classes/kohana'.EXT;
  17
+}
  18
+
  19
+/**
  20
+ * Set the default time zone.
  21
+ *
  22
+ * @see  http://kohanaframework.org/guide/using.configuration
  23
+ * @see  http://php.net/timezones
  24
+ */
  25
+date_default_timezone_set('America/Chicago');
  26
+
  27
+/**
  28
+ * Set the default locale.
  29
+ *
  30
+ * @see  http://kohanaframework.org/guide/using.configuration
  31
+ * @see  http://php.net/setlocale
  32
+ */
  33
+setlocale(LC_ALL, 'en_US.utf-8');
  34
+
  35
+/**
  36
+ * Enable the Kohana auto-loader.
  37
+ *
  38
+ * @see  http://kohanaframework.org/guide/using.autoloading
  39
+ * @see  http://php.net/spl_autoload_register
  40
+ */
  41
+spl_autoload_register(array('Kohana', 'auto_load'));
  42
+
  43
+/**
  44
+ * Enable the Kohana auto-loader for unserialization.
  45
+ *
  46
+ * @see  http://php.net/spl_autoload_call
  47
+ * @see  http://php.net/manual/var.configuration.php#unserialize-callback-func
  48
+ */
  49
+ini_set('unserialize_callback_func', 'spl_autoload_call');
  50
+
  51
+// -- Configuration and initialization -----------------------------------------
  52
+
  53
+/**
  54
+ * Set the default language
  55
+ */
  56
+I18n::lang('en-us');
  57
+
  58
+/**
  59
+ * Set Kohana::$environment if a 'KOHANA_ENV' environment variable has been supplied.
  60
+ *
  61
+ * Note: If you supply an invalid environment name, a PHP warning will be thrown
  62
+ * saying "Couldn't find constant Kohana::<INVALID_ENV_NAME>"
  63
+ */
  64
+if (isset($_SERVER['KOHANA_ENV']))
  65
+{
  66
+	Kohana::$environment = constant('Kohana::'.strtoupper($_SERVER['KOHANA_ENV']));
  67
+}
  68
+
  69
+/**
  70
+ * Initialize Kohana, setting the default options.
  71
+ *
  72
+ * The following options are available:
  73
+ *
  74
+ * - string   base_url    path, and optionally domain, of your application   NULL
  75
+ * - string   index_file  name of your index file, usually "index.php"       index.php
  76
+ * - string   charset     internal character set used for input and output   utf-8
  77
+ * - string   cache_dir   set the internal cache directory                   APPPATH/cache
  78
+ * - boolean  errors      enable or disable error handling                   TRUE
  79
+ * - boolean  profile     enable or disable internal profiling               TRUE
  80
+ * - boolean  caching     enable or disable internal caching                 FALSE
  81
+ */
  82
+Kohana::init(array(
  83
+	'base_url'   => '/',
  84
+));
  85
+
  86
+/**
  87
+ * Attach the file write to logging. Multiple writers are supported.
  88
+ */
  89
+Kohana::$log->attach(new Log_File(APPPATH.'logs'));
  90
+
  91
+/**
  92
+ * Attach a file reader to config. Multiple readers are supported.
  93
+ */
  94
+Kohana::$config->attach(new Config_File);
  95
+
  96
+/**
  97
+ * Enable modules. Modules are referenced by a relative or absolute path.
  98
+ */
  99
+$modules = require(APPPATH.'sandbox_modules.php');
  100
+Kohana::modules($modules);
  101
+
  102
+/**
  103
+ * Set the routes. Each route must have a minimum of a name, a URI and a set of
  104
+ * defaults for the URI.
  105
+ */
  106
+Route::set('default', '(<controller>(/<action>(/<id>)))')
  107
+	->defaults(array(
  108
+		'controller' => 'welcome',
  109
+		'action'     => 'index',
  110
+	));
90  dev/ko_sandbox.php
... ...
@@ -0,0 +1,90 @@
  1
+<?php
  2
+
  3
+/**
  4
+ * Creates a sandboxed Kohana install for this module
  5
+ */
  6
+
  7
+// Configure the Kohana core version and modules to use
  8
+$repos = array(
  9
+	'system' => array(
  10
+		'url' => 'git://github.com/kohana/core.git',
  11
+		'branch' => '3.2/master'
  12
+	),
  13
+	'unittest' => array(
  14
+		'url' => 'git://github.com/acoulton/unittest.git',
  15
+		'branch' => '3.2/master'
  16
+	),
  17
+	'mimic' => TRUE,
  18
+);
  19
+
  20
+/**
  21
+ * NO USER CHANGES BEYOND HERE!
  22
+ */
  23
+echo "Installing Kohana Sandbox for module\r\n";
  24
+
  25
+// Create a location for the sandbox
  26
+if ( ! isset($_SERVER['KO_SANDBOX']))
  27
+{
  28
+	$_SERVER['KO_SANDBOX'] = $_SERVER['HOME'].'/ko_sandbox';
  29
+}
  30
+
  31
+$root = $_SERVER['KO_SANDBOX'];
  32
+
  33
+if (file_exists($root))
  34
+{
  35
+	print_r("*** PATH $root EXISTS! CANNOT CONTINUE");
  36
+	exit(1);
  37
+}
  38
+
  39
+mkdir($root, 0777, TRUE);
  40
+
  41
+// Checkout the core and modules
  42
+echo "Fetching required modules\n";
  43
+$modules=array();
  44
+foreach ($repos as $module => $repo)
  45
+{
  46
+	// Checkout from git unless this is the current module
  47
+	if ($repo !== TRUE)
  48
+	{
  49
+		// Module path should be modules/
  50
+		if ($module !== 'system')
  51
+		{
  52
+			$modpath = $root.'/modules/'.$module;
  53
+		}	
  54
+		else
  55
+		{
  56
+			$modpath = $root.'/system';
  57
+		}
  58
+		
  59
+		// Do the git checkout
  60
+                $cmd = 'git clone -b '.$repo['branch'].' '.$repo['url'].' '.$modpath;
  61
+                echo "Checking out $module to $modpath\n\t-$cmd\n";
  62
+		system($cmd, $return);
  63
+		if ($return)
  64
+		{
  65
+			echo "CHECKOUT FAILED!! Value $return";
  66
+			exit(1);
  67
+		}
  68
+	}
  69
+	else
  70
+	{
  71
+		// Local path is the path above this
  72
+		$modpath = realpath(__DIR__.'/../');
  73
+	}
  74
+
  75
+	// Add to module array if required
  76
+	if ($module !== 'system')
  77
+	{
  78
+		$modules[$module] = $modpath;
  79
+	}
  80
+}
  81
+
  82
+// Create an application folder and bootstrap
  83
+echo "Building application folder\n";
  84
+mkdir($root.'/application');
  85
+mkdir($root.'/application/cache');
  86
+mkdir($root.'/application/logs');
  87
+file_put_contents($root.'/application/sandbox_modules.php',"<?php \n return ".var_export($modules, TRUE).';');
  88
+
  89
+copy('dev/bootstrap.php', $root.'/application/bootstrap.php');
  90
+echo "Sandbox install complete in $root\n";

0 notes on commit bef80ef

Please sign in to comment.
Something went wrong with that request. Please try again.