Permalink
Browse files

Setup Travis CI for automated testing

  • Loading branch information...
1 parent 0323566 commit bef80ef2db8b7ce17324dec978bde98b01c77d0d @acoulton committed Dec 29, 2011
Showing with 223 additions and 2 deletions.
  1. +19 −0 .travis.yml
  2. +4 −2 README.md
  3. +110 −0 dev/bootstrap.php
  4. +90 −0 dev/ko_sandbox.php
View
19 .travis.yml
@@ -0,0 +1,19 @@
+# Configuration file for Travis CI test environment
+language: php
+php:
+ - 5.3
+
+env:
+ - KO_SANDBOX=/home/vagrant/kohana
+
+after_install:
+ # Install vfsStream for unit tests
+ - pyrus channel-discover pear.php-tools.net
+ - pyrus install pat/vfsStream-beta
+ - phpenv rehash
+
+ # Create a kohana environment
+ - php ./dev/ko-sandbox.php
+
+# Run the Mimic tests
+script: phpunit --bootstrap=$KO_SANDBOX/modules/unittest/bootstrap.php --group=mimic $KO_SANDBOX/modules/unittest/tests.php
View
6 README.md
@@ -1,4 +1,4 @@
-# Mimic
+# Mimic [![Build Status](https://secure.travis-ci.org/acoulton/mimic.png)](http://travis-ci.org/acoulton/mimic)
Mimic is a module for [Kohana Framework v3.2 and up](http://kohanaframework.org)
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:
phpunit --bootstrap=modules/unittest/bootstrap.php --group=mimic modules/unittest/tests.php
+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.
+
## Further Documentation
Is included with the module, integrated into the Kohana online userguide.
@@ -100,4 +102,4 @@ Pull requests should:
further commits are required to complete your solution)
* generally speaking, include a unit test or new dataset for an existing test that
fails before your new code is merged and passes afterwards
-* adopt the Kohana coding standards
+* adopt the Kohana coding standards
View
110 dev/bootstrap.php
@@ -0,0 +1,110 @@
+<?php defined('SYSPATH') or die('No direct script access.');
+
+// -- Environment setup --------------------------------------------------------
+
+// Load the core Kohana class
+require SYSPATH.'classes/kohana/core'.EXT;
+
+if (is_file(APPPATH.'classes/kohana'.EXT))
+{
+ // Application extends the core
+ require APPPATH.'classes/kohana'.EXT;
+}
+else
+{
+ // Load empty core extension
+ require SYSPATH.'classes/kohana'.EXT;
+}
+
+/**
+ * Set the default time zone.
+ *
+ * @see http://kohanaframework.org/guide/using.configuration
+ * @see http://php.net/timezones
+ */
+date_default_timezone_set('America/Chicago');
+
+/**
+ * Set the default locale.
+ *
+ * @see http://kohanaframework.org/guide/using.configuration
+ * @see http://php.net/setlocale
+ */
+setlocale(LC_ALL, 'en_US.utf-8');
+
+/**
+ * Enable the Kohana auto-loader.
+ *
+ * @see http://kohanaframework.org/guide/using.autoloading
+ * @see http://php.net/spl_autoload_register
+ */
+spl_autoload_register(array('Kohana', 'auto_load'));
+
+/**
+ * Enable the Kohana auto-loader for unserialization.
+ *
+ * @see http://php.net/spl_autoload_call
+ * @see http://php.net/manual/var.configuration.php#unserialize-callback-func
+ */
+ini_set('unserialize_callback_func', 'spl_autoload_call');
+
+// -- Configuration and initialization -----------------------------------------
+
+/**
+ * Set the default language
+ */
+I18n::lang('en-us');
+
+/**
+ * Set Kohana::$environment if a 'KOHANA_ENV' environment variable has been supplied.
+ *
+ * Note: If you supply an invalid environment name, a PHP warning will be thrown
+ * saying "Couldn't find constant Kohana::<INVALID_ENV_NAME>"
+ */
+if (isset($_SERVER['KOHANA_ENV']))
+{
+ Kohana::$environment = constant('Kohana::'.strtoupper($_SERVER['KOHANA_ENV']));
+}
+
+/**
+ * Initialize Kohana, setting the default options.
+ *
+ * The following options are available:
+ *
+ * - string base_url path, and optionally domain, of your application NULL
+ * - string index_file name of your index file, usually "index.php" index.php
+ * - string charset internal character set used for input and output utf-8
+ * - string cache_dir set the internal cache directory APPPATH/cache
+ * - boolean errors enable or disable error handling TRUE
+ * - boolean profile enable or disable internal profiling TRUE
+ * - boolean caching enable or disable internal caching FALSE
+ */
+Kohana::init(array(
+ 'base_url' => '/',
+));
+
+/**
+ * Attach the file write to logging. Multiple writers are supported.
+ */
+Kohana::$log->attach(new Log_File(APPPATH.'logs'));
+
+/**
+ * Attach a file reader to config. Multiple readers are supported.
+ */
+Kohana::$config->attach(new Config_File);
+
+/**
+ * Enable modules. Modules are referenced by a relative or absolute path.
+ */
+$modules = require(APPPATH.'sandbox_modules.php');
+Kohana::modules($modules);
+
+/**
+ * Set the routes. Each route must have a minimum of a name, a URI and a set of
+ * defaults for the URI.
+ */
+Route::set('default', '(<controller>(/<action>(/<id>)))')
+ ->defaults(array(
+ 'controller' => 'welcome',
+ 'action' => 'index',
+ ));
View
90 dev/ko_sandbox.php
@@ -0,0 +1,90 @@
+<?php
+
+/**
+ * Creates a sandboxed Kohana install for this module
+ */
+
+// Configure the Kohana core version and modules to use
+$repos = array(
+ 'system' => array(
+ 'url' => 'git://github.com/kohana/core.git',
+ 'branch' => '3.2/master'
+ ),
+ 'unittest' => array(
+ 'url' => 'git://github.com/acoulton/unittest.git',
+ 'branch' => '3.2/master'
+ ),
+ 'mimic' => TRUE,
+);
+
+/**
+ * NO USER CHANGES BEYOND HERE!
+ */
+echo "Installing Kohana Sandbox for module\r\n";
+
+// Create a location for the sandbox
+if ( ! isset($_SERVER['KO_SANDBOX']))
+{
+ $_SERVER['KO_SANDBOX'] = $_SERVER['HOME'].'/ko_sandbox';
+}
+
+$root = $_SERVER['KO_SANDBOX'];
+
+if (file_exists($root))
+{
+ print_r("*** PATH $root EXISTS! CANNOT CONTINUE");
+ exit(1);
+}
+
+mkdir($root, 0777, TRUE);
+
+// Checkout the core and modules
+echo "Fetching required modules\n";
+$modules=array();
+foreach ($repos as $module => $repo)
+{
+ // Checkout from git unless this is the current module
+ if ($repo !== TRUE)
+ {
+ // Module path should be modules/
+ if ($module !== 'system')
+ {
+ $modpath = $root.'/modules/'.$module;
+ }
+ else
+ {
+ $modpath = $root.'/system';
+ }
+
+ // Do the git checkout
+ $cmd = 'git clone -b '.$repo['branch'].' '.$repo['url'].' '.$modpath;
+ echo "Checking out $module to $modpath\n\t-$cmd\n";
+ system($cmd, $return);
+ if ($return)
+ {
+ echo "CHECKOUT FAILED!! Value $return";
+ exit(1);
+ }
+ }
+ else
+ {
+ // Local path is the path above this
+ $modpath = realpath(__DIR__.'/../');
+ }
+
+ // Add to module array if required
+ if ($module !== 'system')
+ {
+ $modules[$module] = $modpath;
+ }
+}
+
+// Create an application folder and bootstrap
+echo "Building application folder\n";
+mkdir($root.'/application');
+mkdir($root.'/application/cache');
+mkdir($root.'/application/logs');
+file_put_contents($root.'/application/sandbox_modules.php',"<?php \n return ".var_export($modules, TRUE).';');
+
+copy('dev/bootstrap.php', $root.'/application/bootstrap.php');
+echo "Sandbox install complete in $root\n";

0 comments on commit bef80ef

Please sign in to comment.