Skip to content

Commit bf561e5

Browse files
Merge pull request #18 from wp-cli/update-tests-readme
Update package tests and README for the move
2 parents 28fe752 + 80c2d94 commit bf561e5

File tree

17 files changed

+459
-127
lines changed

17 files changed

+459
-127
lines changed

README.md

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
runcommand/dist-archive
2-
=======================
1+
wp-cli/dist-archive-command
2+
===========================
33

44
Create a distribution .zip or .tar.gz based on a plugin or theme's .distignore file.
55

6-
[![runcommand open source](https://runcommand.io/wp-content/themes/runcommand-theme/bin/shields/runcommand-open-source.svg)](https://runcommand.io/pricing/) [![CircleCI](https://circleci.com/gh/runcommand/dist-archive/tree/master.svg?style=svg)](https://circleci.com/gh/runcommand/dist-archive/tree/master)
6+
[![Build Status](https://travis-ci.org/wp-cli/dist-archive-command.svg?branch=master)](https://travis-ci.org/wp-cli/dist-archive-command)
77

8-
Quick links: [Using](#using) | [Installing](#installing) | [Support](#support)
8+
Quick links: [Using](#using) | [Installing](#installing) | [Contributing](#contributing)
99

1010
## Using
1111

@@ -52,16 +52,38 @@ script in each project.
5252

5353
Installing this package requires WP-CLI v0.23.0 or greater. Update to the latest stable release with `wp cli update`.
5454

55-
Once you've done so, you can install this package with `wp package install runcommand/dist-archive`.
55+
Once you've done so, you can install this package with `wp package install wp-cli/dist-archive-command`.
5656

57-
## Support
57+
## Contributing
5858

59-
This WP-CLI package is free for anyone to use. Support, including usage questions and feature requests, is available to [paying runcommand customers](https://runcommand.io/pricing/).
59+
We appreciate you taking the initiative to contribute to this project.
6060

61-
Think you’ve found a bug? Before you create a new issue, you should [search existing issues](https://github.com/runcommand/sparks/issues?q=label%3Abug%20) to see if there’s an existing resolution to it, or if it’s already been fixed in a newer version. Once you’ve done a bit of searching and discovered there isn’t an open or fixed issue for your bug, please [create a new issue](https://github.com/runcommand/sparks/issues/new) with description of what you were doing, what you saw, and what you expected to see.
61+
Contributing isn’t limited to just code. We encourage you to contribute in the way that best fits your abilities, by writing tutorials, giving a demo at your local meetup, helping other users with their support questions, or revising our documentation.
6262

63-
Want to contribute a new feature? Please first [open a new issue](https://github.com/runcommand/sparks/issues/new) to discuss whether the feature is a good fit for the project. Once you've decided to work on a pull request, please include [functional tests](https://wp-cli.org/docs/pull-requests/#functional-tests) and follow the [WordPress Coding Standards](http://make.wordpress.org/core/handbook/coding-standards/).
63+
### Reporting a bug
6464

65-
runcommand customers can also email [[email protected]](mailto:[email protected]) for private support.
65+
Think you’ve found a bug? We’d love for you to help us get it fixed.
6666

67+
Before you create a new issue, you should [search existing issues](https://github.com/wp-cli/dist-archive-command/issues?q=label%3Abug%20) to see if there’s an existing resolution to it, or if it’s already been fixed in a newer version.
6768

69+
Once you’ve done a bit of searching and discovered there isn’t an open or fixed issue for your bug, please [create a new issue](https://github.com/wp-cli/dist-archive-command/issues/new) with the following:
70+
71+
1. What you were doing (e.g. "When I run `wp post list`").
72+
2. What you saw (e.g. "I see a fatal about a class being undefined.").
73+
3. What you expected to see (e.g. "I expected to see the list of posts.")
74+
75+
Include as much detail as you can, and clear steps to reproduce if possible.
76+
77+
### Creating a pull request
78+
79+
Want to contribute a new feature? Please first [open a new issue](https://github.com/wp-cli/dist-archive-command/issues/new) to discuss whether the feature is a good fit for the project.
80+
81+
Once you've decided to commit the time to seeing your pull request through, please follow our guidelines for creating a pull request to make sure it's a pleasant experience:
82+
83+
1. Create a feature branch for each contribution.
84+
2. Submit your pull request early for feedback.
85+
3. Include functional tests with your changes. [Read the WP-CLI documentation](https://wp-cli.org/docs/pull-requests/#functional-tests) for an introduction.
86+
4. Follow the [WordPress Coding Standards](http://make.wordpress.org/core/handbook/coding-standards/).
87+
88+
89+
*This README.md is generated dynamically from the project's codebase using `wp scaffold package-readme` ([doc](https://github.com/wp-cli/scaffold-package-command#wp-scaffold-package-readme)). To suggest changes, please submit a pull request against the corresponding part of the codebase.*

bin/install-package-tests.sh

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,9 @@
22

33
set -ex
44

5-
PACKAGE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/../ && pwd )"
6-
7-
download() {
8-
if [ `which curl` ]; then
9-
curl -s "$1" > "$2";
10-
elif [ `which wget` ]; then
11-
wget -nv -O "$2" "$1"
12-
fi
13-
}
14-
15-
install_wp_cli() {
16-
17-
# the Behat test suite will pick up the executable found in $WP_CLI_BIN_DIR
18-
mkdir -p $WP_CLI_BIN_DIR
19-
download https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli-nightly.phar $WP_CLI_BIN_DIR/wp
20-
chmod +x $WP_CLI_BIN_DIR/wp
21-
22-
}
23-
24-
download_behat() {
25-
26-
cd $PACKAGE_DIR
27-
download https://getcomposer.org/installer installer
28-
php installer
29-
php composer.phar require --dev behat/behat='~2.5'
30-
31-
}
32-
335
install_db() {
346
mysql -e 'CREATE DATABASE IF NOT EXISTS wp_cli_test;' -uroot
357
mysql -e 'GRANT ALL PRIVILEGES ON wp_cli_test.* TO "wp_cli_test"@"localhost" IDENTIFIED BY "password1"' -uroot
368
}
379

38-
install_wp_cli
39-
download_behat
4010
install_db

bin/test.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
set -ex
4+
5+
# Run the functional tests
6+
BEHAT_TAGS=$(php utils/behat-tags.php)
7+
behat --format progress $BEHAT_TAGS --strict

circle.yml

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,28 @@ machine:
22
php:
33
version: 5.6.22
44
environment:
5-
WP_CLI_BIN_DIR: /tmp/wp-cli-phar
5+
PATH: "$HOME/$CIRCLE_PROJECT_REPONAME/vendor/bin:$PATH"
6+
WP_CLI_BIN_DIR: "$HOME/$CIRCLE_PROJECT_REPONAME/vendor/bin"
67

78
dependencies:
89
cache_directories:
910
- ~/.composer/cache
11+
pre:
12+
# Set the PHP timezone so that Behat does not fail.
13+
- echo "date.timezone = 'US/Central'" > /opt/circleci/php/$(phpenv global)/etc/conf.d/wp-cli-timezone.ini
14+
# Disable xdebug, which makes Composer slower.
15+
- echo "" > /opt/circleci/php/$(phpenv global)/etc/conf.d/xdebug.ini
16+
# Increase memory limit
17+
- echo "memory_limit = 512M" > /opt/circleci/php/$(phpenv global)/etc/conf.d/memory.ini
18+
override:
19+
- composer require wp-cli/wp-cli:dev-master
20+
- composer install
21+
- bash bin/install-package-tests.sh
1022

1123
test:
1224
pre:
13-
- bash bin/install-package-tests.sh
25+
- composer validate
1426
override:
15-
- ./vendor/bin/behat --strict
27+
- WP_VERSION=latest bash bin/test.sh
28+
- rm -rf '/tmp/wp-cli-test core-download-cache'
29+
- WP_VERSION=trunk bash bin/test.sh

composer.json

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
],
1414
"minimum-stability": "dev",
1515
"autoload": {
16-
"files": [ "command.php" ]
16+
"files": [ "dist-archive-command.php" ]
1717
},
1818
"require": {},
1919
"require-dev": {
@@ -22,21 +22,6 @@
2222
"extra": {
2323
"commands": [
2424
"dist-archive"
25-
],
26-
"readme": {
27-
"shields": [
28-
"[![runcommand open source](https://runcommand.io/wp-content/themes/runcommand-theme/bin/shields/runcommand-open-source.svg)](https://runcommand.io/pricing/)",
29-
"[![CircleCI](https://circleci.com/gh/runcommand/dist-archive/tree/master.svg?style=svg)](https://circleci.com/gh/runcommand/dist-archive/tree/master)"
30-
],
31-
"sections": [
32-
"Using",
33-
"Installing",
34-
"Support"
35-
],
36-
"support": {
37-
"body": "https://raw.githubusercontent.com/runcommand/runcommand-theme/master/bin/readme-partials/support-open-source.md"
38-
},
39-
"show_powered_by": false
40-
}
25+
]
4126
}
4227
}
File renamed without changes.

features/bootstrap/FeatureContext.php

Lines changed: 62 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@
1212
if ( file_exists( __DIR__ . '/utils.php' ) ) {
1313
require_once __DIR__ . '/utils.php';
1414
require_once __DIR__ . '/Process.php';
15+
require_once __DIR__ . '/ProcessRun.php';
1516
$project_composer = dirname( dirname( dirname( __FILE__ ) ) ) . '/composer.json';
1617
if ( file_exists( $project_composer ) ) {
1718
$composer = json_decode( file_get_contents( $project_composer ) );
1819
if ( ! empty( $composer->autoload->files ) ) {
1920
$contents = 'require:' . PHP_EOL;
2021
foreach( $composer->autoload->files as $file ) {
21-
$contents .= ' - ' . dirname( dirname( dirname( __FILE__ ) ) ) . '/' . $file;
22+
$contents .= ' - ' . dirname( dirname( dirname( __FILE__ ) ) ) . '/' . $file . PHP_EOL;
2223
}
2324
@mkdir( sys_get_temp_dir() . '/wp-cli-package-test/' );
2425
$project_config = sys_get_temp_dir() . '/wp-cli-package-test/config.yml';
@@ -30,6 +31,7 @@
3031
} else {
3132
require_once __DIR__ . '/../../php/utils.php';
3233
require_once __DIR__ . '/../../php/WP_CLI/Process.php';
34+
require_once __DIR__ . '/../../php/WP_CLI/ProcessRun.php';
3335
require_once __DIR__ . '/../../vendor/autoload.php';
3436
}
3537

@@ -57,9 +59,10 @@ class FeatureContext extends BehatContext implements ClosuredContextInterface {
5759
*/
5860
private static function get_process_env_variables() {
5961
// Ensure we're using the expected `wp` binary
60-
$bin_dir = getenv( 'WP_CLI_BIN_DIR' ) ?: realpath( __DIR__ . "/../../bin" );
62+
$bin_dir = getenv( 'WP_CLI_BIN_DIR' ) ?: realpath( __DIR__ . '/../../bin' );
63+
$vendor_dir = realpath( __DIR__ . '/../../vendor/bin' );
6164
$env = array(
62-
'PATH' => $bin_dir . ':' . getenv( 'PATH' ),
65+
'PATH' => $bin_dir . ':' . $vendor_dir . ':' . getenv( 'PATH' ),
6366
'BEHAT_RUN' => 1,
6467
'HOME' => '/tmp/wp-cli-home',
6568
);
@@ -78,6 +81,9 @@ private static function cache_wp_files() {
7881
return;
7982

8083
$cmd = Utils\esc_cmd( 'wp core download --force --path=%s', self::$cache_dir );
84+
if ( getenv( 'WP_VERSION' ) ) {
85+
$cmd .= Utils\esc_cmd( ' --version=%s', getenv( 'WP_VERSION' ) );
86+
}
8187
Process::create( $cmd, null, self::get_process_env_variables() )->run_check();
8288
}
8389

@@ -90,6 +96,9 @@ public static function prepare( SuiteEvent $event ) {
9096
echo $result->stdout;
9197
echo PHP_EOL;
9298
self::cache_wp_files();
99+
$result = Process::create( Utils\esc_cmd( 'wp core version --path=%s', self::$cache_dir ) , null, self::get_process_env_variables() )->run_check();
100+
echo 'WordPress ' . $result->stdout;
101+
echo PHP_EOL;
93102
}
94103

95104
/**
@@ -119,6 +128,11 @@ public function afterScenario( $event ) {
119128
}
120129
}
121130

131+
// Remove WP-CLI package directory
132+
if ( isset( $this->variables['PACKAGE_PATH'] ) ) {
133+
$this->proc( Utils\esc_cmd( 'rm -rf %s', $this->variables['PACKAGE_PATH'] ) )->run();
134+
}
135+
122136
foreach ( $this->running_procs as $proc ) {
123137
self::terminate_proc( $proc );
124138
}
@@ -165,6 +179,9 @@ public static function create_cache_dir() {
165179
* @param array $parameters context parameters (set them up through behat.yml)
166180
*/
167181
public function __construct( array $parameters ) {
182+
if ( getenv( 'WP_CLI_TEST_DBHOST' ) ) {
183+
self::$db_settings['dbhost'] = getenv( 'WP_CLI_TEST_DBHOST' );
184+
}
168185
$this->drop_db();
169186
$this->set_cache_dir();
170187
$this->variables['CORE_CONFIG_SETTINGS'] = Utils\assoc_args_to_str( self::$db_settings );
@@ -202,22 +219,60 @@ public function create_run_dir() {
202219
public function build_phar( $version = 'same' ) {
203220
$this->variables['PHAR_PATH'] = $this->variables['RUN_DIR'] . '/' . uniqid( "wp-cli-build-", TRUE ) . '.phar';
204221

222+
// Test running against WP-CLI proper
223+
$make_phar_path = __DIR__ . '/../../utils/make-phar.php';
224+
if ( ! file_exists( $make_phar_path ) ) {
225+
// Test running against a package installed as a WP-CLI dependency
226+
// WP-CLI installed as a project dependency
227+
$make_phar_path = __DIR__ . '/../../../../../utils/make-phar.php';
228+
if ( ! file_exists( $make_phar_path ) ) {
229+
// WP-CLI as a dependency of this project
230+
$make_phar_path = __DIR__ . '/../../vendor/wp-cli/wp-cli/utils/make-phar.php';
231+
}
232+
}
233+
205234
$this->proc( Utils\esc_cmd(
206235
'php -dphar.readonly=0 %1$s %2$s --version=%3$s && chmod +x %2$s',
207-
__DIR__ . '/../../utils/make-phar.php',
236+
$make_phar_path,
208237
$this->variables['PHAR_PATH'],
209238
$version
210239
) )->run_check();
211240
}
212241

242+
public function download_phar( $version = 'same' ) {
243+
if ( 'same' === $version ) {
244+
$version = WP_CLI_VERSION;
245+
}
246+
247+
$download_url = sprintf(
248+
'https://github.com/wp-cli/wp-cli/releases/download/v%1$s/wp-cli-%1$s.phar',
249+
$version
250+
);
251+
252+
$this->variables['PHAR_PATH'] = $this->variables['RUN_DIR'] . '/'
253+
. uniqid( 'wp-cli-download-', true )
254+
. '.phar';
255+
256+
Process::create( \WP_CLI\Utils\esc_cmd(
257+
'curl -sSL %s > %s',
258+
$download_url,
259+
$this->variables['PHAR_PATH']
260+
) )->run_check();
261+
262+
Process::create( \WP_CLI\Utils\esc_cmd(
263+
'chmod +x %s',
264+
$this->variables['PHAR_PATH']
265+
) )->run_check();
266+
}
267+
213268
private function set_cache_dir() {
214269
$path = sys_get_temp_dir() . '/wp-cli-test-cache';
215270
$this->proc( Utils\esc_cmd( 'mkdir -p %s', $path ) )->run_check();
216271
$this->variables['CACHE_DIR'] = $path;
217272
}
218273

219274
private static function run_sql( $sql ) {
220-
Utils\run_mysql_command( 'mysql --no-defaults', array(
275+
Utils\run_mysql_command( '/usr/bin/env mysql --no-defaults', array(
221276
'execute' => $sql,
222277
'host' => self::$db_settings['dbhost'],
223278
'user' => self::$db_settings['dbuser'],
@@ -302,7 +357,8 @@ public function download_wp( $subdir = '' ) {
302357

303358
public function create_config( $subdir = '' ) {
304359
$params = self::$db_settings;
305-
$params['dbprefix'] = $subdir ?: 'wp_';
360+
// Replaces all characters that are not alphanumeric or an underscore into an underscore.
361+
$params['dbprefix'] = $subdir ? preg_replace( '#[^a-zA-Z\_0-9]#', '_', $subdir ) : 'wp_';
306362

307363
$params['skip-salts'] = true;
308364
$this->proc( 'wp core config', $params, $subdir )->run_check();

features/bootstrap/Process.php

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -73,33 +73,3 @@ public function run_check() {
7373
return $r;
7474
}
7575
}
76-
77-
/**
78-
* Results of an executed command.
79-
*/
80-
class ProcessRun {
81-
82-
/**
83-
* @var array $props Properties of executed command.
84-
*/
85-
public function __construct( $props ) {
86-
foreach ( $props as $key => $value ) {
87-
$this->$key = $value;
88-
}
89-
}
90-
91-
/**
92-
* Return properties of executed command as a string.
93-
*
94-
* @return string
95-
*/
96-
public function __toString() {
97-
$out = "$ $this->command\n";
98-
$out .= "$this->stdout\n$this->stderr";
99-
$out .= "cwd: $this->cwd\n";
100-
$out .= "exit status: $this->return_code";
101-
102-
return $out;
103-
}
104-
105-
}

features/bootstrap/ProcessRun.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace WP_CLI;
4+
5+
/**
6+
* Results of an executed command.
7+
*/
8+
class ProcessRun {
9+
10+
/**
11+
* @var array $props Properties of executed command.
12+
*/
13+
public function __construct( $props ) {
14+
foreach ( $props as $key => $value ) {
15+
$this->$key = $value;
16+
}
17+
}
18+
19+
/**
20+
* Return properties of executed command as a string.
21+
*
22+
* @return string
23+
*/
24+
public function __toString() {
25+
$out = "$ $this->command\n";
26+
$out .= "$this->stdout\n$this->stderr";
27+
$out .= "cwd: $this->cwd\n";
28+
$out .= "exit status: $this->return_code";
29+
30+
return $out;
31+
}
32+
33+
}

0 commit comments

Comments
 (0)