Skip to content

Commit

Permalink
Testing Out Travis
Browse files Browse the repository at this point in the history
  • Loading branch information
bfintal committed Mar 1, 2014
1 parent 0ecde45 commit 8c9c61f
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 0 deletions.
52 changes: 52 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Travis CI Configuration File

# Tell Travis CI we're using PHP
language: php

# PHP version used in first build configuration.
php:
- "5.5"

# WordPress version used in first build configuration.
env:
- WP_VERSION=master

# Next we define our matrix of additional build configurations to test against.
# The versions listed above will automatically create our first configuration,
# so it doesn't need to be re-defined below.

# WP_VERSION specifies the tag to use. The way these tests are configured to run
# requires at least WordPress 3.8. Specify "master" to test against SVN trunk.

# Note that Travis CI supports listing these above to automatically build a
# matrix of configurations, but we're being nice here by manually building a
# total of four configurations even though we're testing 4 versions of PHP
# along with 2 versions of WordPress (which would build 8 configs otherwise).
# This takes half as long to run while still providing adequate coverage.

matrix:
include:
- php: "5.3"
env: WP_VERSION=master
- php: "5.4"
env: WP_VERSION=3.8
- php: "5.2"
env: WP_VERSION=3.8

# Clones WordPress and configures our testing environment.
before_script:
- export PLUGIN_SLUG=$(basename $(pwd))
- git clone https://github.com/tierra/wordpress.git /tmp/wordpress
# - git clone . "/tmp/wordpress/src/wp-content/plugins/$PLUGIN_SLUG"
- cd ..
- mv $PLUGIN_SLUG "/tmp/wordpress/src/wp-content/plugins/$PLUGIN_SLUG"
- cd /tmp/wordpress
- git checkout $WP_VERSION
- mysql -e "CREATE DATABASE wordpress_tests;" -uroot
- cp wp-tests-config-sample.php wp-tests-config.php
- sed -i "s/youremptytestdbnamehere/wordpress_tests/" wp-tests-config.php
- sed -i "s/yourusernamehere/travis/" wp-tests-config.php
- sed -i "s/yourpasswordhere//" wp-tests-config.php
- cd "/tmp/wordpress/src/wp-content/plugins/$PLUGIN_SLUG"

script: phpunit
8 changes: 8 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<phpunit bootstrap="tests/bootstrap.php" backupGlobals="false" colors="true">
<testsuites>
<!-- Default test suite to run all tests -->
<testsuite>
<directory prefix="test_" suffix=".php">tests</directory>
</testsuite>
</testsuites>
</phpunit>
23 changes: 23 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
/**
* Bootstrap the plugin unit testing environment.
*
* Edit 'active_plugins' setting below to point to your main plugin file.
*
* @package wordpress-plugin-tests
*/

// Activates this plugin in WordPress so it can be tested.
$GLOBALS['wp_tests_options'] = array(
'active_plugins' => array( 'titan-framework/titan-framework.php' ),
);

// If the develop repo location is defined (as WP_DEVELOP_DIR), use that
// location. Otherwise, we'll just assume that this plugin is installed in a
// WordPress develop SVN checkout.

if( false !== getenv( 'WP_DEVELOP_DIR' ) ) {
require getenv( 'WP_DEVELOP_DIR' ) . '/tests/phpunit/includes/bootstrap.php';
} else {
require '../../../../tests/phpunit/includes/bootstrap.php';
}
52 changes: 52 additions & 0 deletions tests/test_wordpress_plugin_tests.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

/**
* Tests to test that that testing framework is testing tests. Meta, huh?
*
* @package wordpress-plugins-tests
*/
class WP_Test_WordPress_Plugin_Tests extends WP_UnitTestCase {

/**
* Run a simple test to ensure that the tests are running
*/
function test_tests() {

$this->assertTrue( true );

}

/**
* If these tests are being run on Travis CI, verify that the version of
* WordPress installed is the version that we requested.
*
* @requires PHP 5.3
*/
function test_wp_version() {

if ( !getenv( 'TRAVIS' ) )
$this->markTestSkipped( 'Test skipped since Travis CI was not detected.' );

$requested_version = getenv( 'WP_VERSION' ) . '-src';

// The "master" version requires special handling.
if ( $requested_version == 'master-src' ) {
$file = file_get_contents( 'https://raw.github.com/tierra/wordpress/master/src/wp-includes/version.php' );
preg_match( '#\$wp_version = \'([^\']+)\';#', $file, $matches );
$requested_version = $matches[1];
}
$this->assertEquals( get_bloginfo( 'version' ), $requested_version );

}

/**
* Ensure that the plugin has been installed and activated.
*/
function test_plugin_activated() {

$this->assertTrue( is_plugin_active( 'titan-framework/titan-framework.php' ) );

}

}

0 comments on commit 8c9c61f

Please sign in to comment.