Merge pull request #6 from runcommand/use-circle

Use Circle to run test suite
This commit is contained in:
Daniel Bachhuber 2016-08-24 12:08:21 -07:00 committed by GitHub
commit 8d93154ef8
8 changed files with 47 additions and 32 deletions

View file

@ -1,29 +0,0 @@
sudo: false
language: php
notifications:
email:
on_success: never
on_failure: change
branches:
only:
- master
php:
- 5.3
- 5.6
cache:
- composer
- $HOME/.composer/cache
env:
global:
- WP_CLI_BIN_DIR=/tmp/wp-cli-phar
before_script:
- bash bin/install-package-tests.sh
script: ./vendor/bin/behat

View file

@ -3,7 +3,7 @@ runcommand/profile
Profile the performance of a WordPress request.
[![Build Status](https://travis-ci.org/runcommand/profile.svg?branch=master)](https://travis-ci.org/runcommand/profile)
[![CircleCI](https://circleci.com/gh/runcommand/profile/tree/master.svg?style=svg&circle-token=d916e588bf7c8ac469a3bd01930cf9eed886debe)](https://circleci.com/gh/runcommand/profile/tree/master)
Quick links: [Using](#using) | [Installing](#installing) | [Contributing](#contributing)

15
circle.yml Normal file
View file

@ -0,0 +1,15 @@
machine:
php:
version: 5.6.14
environment:
WP_CLI_BIN_DIR: /tmp/wp-cli-phar
dependencies:
cache_directories:
- ~/.composer/cache
test:
pre:
- bash bin/install-package-tests.sh
override:
- ./vendor/bin/behat --strict

View file

@ -119,6 +119,11 @@ class FeatureContext extends BehatContext implements ClosuredContextInterface {
}
}
// Remove WP-CLI package directory
if ( isset( $this->variables['PACKAGE_PATH'] ) ) {
$this->proc( Utils\esc_cmd( 'rm -rf %s', $this->variables['PACKAGE_PATH'] ) )->run();
}
foreach ( $this->running_procs as $proc ) {
self::terminate_proc( $proc );
}

View file

@ -8,6 +8,12 @@ function assertEquals( $expected, $actual ) {
}
}
function assertNotEquals( $expected, $actual ) {
if ( $expected == $actual ) {
throw new Exception( "Actual value: " . var_export( $actual, true ) );
}
}
function assertNumeric( $actual ) {
if ( !is_numeric( $actual ) ) {
throw new Exception( "Actual value: " . var_export( $actual, true ) );

View file

@ -1,6 +1,7 @@
<?php
function wp_mail() {
// do nothing
function wp_mail( $to ) {
// Log for testing purposes
WP_CLI::log( "WP-CLI test suite: Sent email to {$to}." );
}

View file

@ -190,3 +190,12 @@ $steps->Then( '/^the (.+) (file|directory) should (exist|not exist|be:|contain:|
}
);
$steps->Then( '/^an email should (be sent|not be sent)$/', function( $world, $expected ) {
if ( 'be sent' === $expected ) {
assertNotEquals( 0, $world->email_sends );
} else if ( 'not be sent' === $expected ) {
assertEquals( 0, $world->email_sends );
} else {
throw new Exception( 'Invalid expectation' );
}
});

View file

@ -14,6 +14,11 @@ function invoke_proc( $proc, $mode ) {
return $proc->$method();
}
function capture_email_sends( $stdout ) {
$stdout = preg_replace( '#WP-CLI test suite: Sent email to.+\n?#', '', $stdout, -1, $email_sends );
return array( $stdout, $email_sends );
}
$steps->When( '/^I launch in the background `([^`]+)`$/',
function ( $world, $cmd ) {
$world->background_proc( $cmd );
@ -24,6 +29,7 @@ $steps->When( '/^I (run|try) `([^`]+)`$/',
function ( $world, $mode, $cmd ) {
$cmd = $world->replace_variables( $cmd );
$world->result = invoke_proc( $world->proc( $cmd ), $mode );
list( $world->result->stdout, $world->email_sends ) = capture_email_sends( $world->result->stdout );
}
);
@ -31,6 +37,7 @@ $steps->When( "/^I (run|try) `([^`]+)` from '([^\s]+)'$/",
function ( $world, $mode, $cmd, $subdir ) {
$cmd = $world->replace_variables( $cmd );
$world->result = invoke_proc( $world->proc( $cmd, array(), $subdir ), $mode );
list( $world->result->stdout, $world->email_sends ) = capture_email_sends( $world->result->stdout );
}
);
@ -41,6 +48,7 @@ $steps->When( '/^I (run|try) the previous command again$/',
$proc = Process::create( $world->result->command, $world->result->cwd, $world->result->env );
$world->result = invoke_proc( $proc, $mode );
list( $world->result->stdout, $world->email_sends ) = capture_email_sends( $world->result->stdout );
}
);