Skip to content

Commit e328454

Browse files
Use PSR-4 autoloading of existing classes; add remaining test files
1 parent 80e3da4 commit e328454

14 files changed

+1224
-3
lines changed

.distignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.DS_Store
2+
.git
3+
.gitignore
4+
.gitlab-ci.yml
5+
.editorconfig
6+
.travis.yml
7+
behat.yml
8+
circle.yml
9+
bin/
10+
features/
11+
utils/
12+
*.zip
13+
*.tar.gz

.editorconfig

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# This file is for unifying the coding style for different editors and IDEs
2+
# editorconfig.org
3+
4+
# WordPress Coding Standards
5+
# https://make.wordpress.org/core/handbook/coding-standards/
6+
7+
root = true
8+
9+
[*]
10+
charset = utf-8
11+
end_of_line = lf
12+
insert_final_newline = true
13+
trim_trailing_whitespace = true
14+
indent_style = tab
15+
16+
[{.jshintrc,*.json,*.yml,*.feature}]
17+
indent_style = space
18+
indent_size = 2
19+
20+
[{*.txt,wp-config-sample.php}]
21+
end_of_line = crlf
22+
23+
[composer.json]
24+
indent_style = space
25+
indent_size = 4

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.DS_Store
2+
wp-cli.local.yml
3+
composer.lock
4+
node_modules/
5+
vendor/
6+
*.zip
7+
*.tar.gz

.travis.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
sudo: false
2+
3+
language: php
4+
5+
notifications:
6+
email:
7+
on_success: never
8+
on_failure: change
9+
10+
branches:
11+
only:
12+
- master
13+
14+
cache:
15+
- composer
16+
- $HOME/.composer/cache
17+
18+
env:
19+
global:
20+
- WP_CLI_BIN_DIR=/tmp/wp-cli-phar
21+
22+
matrix:
23+
include:
24+
- php: 7.1
25+
env: WP_VERSION=latest
26+
- php: 7.0
27+
env: WP_VERSION=latest
28+
- php: 5.6
29+
env: WP_VERSION=latest
30+
- php: 5.6
31+
env: WP_VERSION=trunk
32+
- php: 5.3
33+
env: WP_VERSION=latest
34+
35+
before_script:
36+
- phpenv config-rm xdebug.ini
37+
- composer validate
38+
- bash bin/install-package-tests.sh
39+
40+
script: ./vendor/bin/behat --format progress --strict

README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
wp-cli/db-command
2+
=================
3+
4+
Perform basic database operations using credentials stored in wp-config.php
5+
6+
[![Build Status](https://travis-ci.org/wp-cli/db-command.svg?branch=master)](https://travis-ci.org/wp-cli/db-command)
7+
8+
Quick links: [Using](#using) | [Installing](#installing) | [Contributing](#contributing)
9+
10+
## Using
11+
12+
13+
14+
## Installing
15+
16+
Installing this package requires WP-CLI v1.1.0 or greater. Update to the latest stable release with `wp cli update`.
17+
18+
Once you've done so, you can install this package with `wp package install wp-cli/db-command`.
19+
20+
## Contributing
21+
22+
We appreciate you taking the initiative to contribute to this project.
23+
24+
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.
25+
26+
### Reporting a bug
27+
28+
Think you’ve found a bug? We’d love for you to help us get it fixed.
29+
30+
Before you create a new issue, you should [search existing issues](https://github.com/wp-cli/db-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.
31+
32+
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/db-command/issues/new) with the following:
33+
34+
1. What you were doing (e.g. "When I run `wp post list`").
35+
2. What you saw (e.g. "I see a fatal about a class being undefined.").
36+
3. What you expected to see (e.g. "I expected to see the list of posts.")
37+
38+
Include as much detail as you can, and clear steps to reproduce if possible.
39+
40+
### Creating a pull request
41+
42+
Want to contribute a new feature? Please first [open a new issue](https://github.com/wp-cli/db-command/issues/new) to discuss whether the feature is a good fit for the project.
43+
44+
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:
45+
46+
1. Create a feature branch for each contribution.
47+
2. Submit your pull request early for feedback.
48+
3. Include functional tests with your changes. [Read the WP-CLI documentation](https://wp-cli.org/docs/pull-requests/#functional-tests) for an introduction.
49+
4. Follow the [WordPress Coding Standards](http://make.wordpress.org/core/handbook/coding-standards/).
50+
51+
52+
*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: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env bash
2+
3+
set -ex
4+
5+
WP_CLI_BIN_DIR=${WP_CLI_BIN_DIR-/tmp/wp-cli-phar}
6+
7+
PACKAGE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/../ && pwd )"
8+
9+
download() {
10+
if [ `which curl` ]; then
11+
curl -s "$1" > "$2";
12+
elif [ `which wget` ]; then
13+
wget -nv -O "$2" "$1"
14+
fi
15+
}
16+
17+
install_wp_cli() {
18+
19+
# the Behat test suite will pick up the executable found in $WP_CLI_BIN_DIR
20+
mkdir -p $WP_CLI_BIN_DIR
21+
download https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli-nightly.phar $WP_CLI_BIN_DIR/wp
22+
chmod +x $WP_CLI_BIN_DIR/wp
23+
24+
}
25+
26+
download_behat() {
27+
28+
cd $PACKAGE_DIR
29+
composer require --dev behat/behat='~2.5'
30+
31+
}
32+
33+
install_db() {
34+
mysql -e 'CREATE DATABASE IF NOT EXISTS wp_cli_test;' -uroot
35+
mysql -e 'GRANT ALL PRIVILEGES ON wp_cli_test.* TO "wp_cli_test"@"localhost" IDENTIFIED BY "password1"' -uroot
36+
}
37+
38+
install_wp_cli
39+
download_behat
40+
install_db

composer.json

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"name": "wp-cli/db-command",
3+
"description": "Perform basic database operations using credentials stored in wp-config.php.",
4+
"type": "wp-cli-package",
5+
"homepage": "https://github.com/wp-cli/db-command",
6+
"support": {
7+
"issues": "https://github.com/wp-cli/db-command/issues"
8+
},
9+
"license": "MIT",
10+
"authors": [
11+
{
12+
"name": "Daniel Bachhuber",
13+
"email": "[email protected]",
14+
"homepage": "https://runcommand.io"
15+
}
16+
],
17+
"minimum-stability": "dev",
18+
"autoload": {
19+
"psr-4": {"": "src/"},
20+
"files": [ "db-command.php" ]
21+
},
22+
"require": {},
23+
"require-dev": {
24+
"behat/behat": "~2.5"
25+
},
26+
"extra": {
27+
"commands": [
28+
"db create",
29+
"db drop",
30+
"db reset",
31+
"db check",
32+
"db optimize",
33+
"db repair",
34+
"db cli",
35+
"db query",
36+
"db export",
37+
"db import",
38+
"db tables"
39+
]
40+
}
41+
}

db-command.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
if ( ! class_exists( 'WP_CLI' ) ) {
4+
return;
5+
}
6+
7+
$autoload = dirname( __FILE__ ) . '/vendor/autoload.php';
8+
if ( file_exists( $autoload ) ) {
9+
require_once $autoload;
10+
}
11+
12+
WP_CLI::add_command( 'db', 'DB_Command' );

features/bootstrap/Process.php

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
3+
namespace WP_CLI;
4+
5+
/**
6+
* Run a system process, and learn what happened.
7+
*/
8+
class Process {
9+
10+
/**
11+
* @param string $command Command to execute.
12+
* @param string $cwd Directory to execute the command in.
13+
* @param array $env Environment variables to set when running the command.
14+
*/
15+
public static function create( $command, $cwd = null, $env = array() ) {
16+
$proc = new self;
17+
18+
$proc->command = $command;
19+
$proc->cwd = $cwd;
20+
$proc->env = $env;
21+
22+
return $proc;
23+
}
24+
25+
private $command, $cwd, $env;
26+
27+
private function __construct() {}
28+
29+
/**
30+
* Run the command.
31+
*
32+
* @return ProcessRun
33+
*/
34+
public function run() {
35+
$cwd = $this->cwd;
36+
37+
$descriptors = array(
38+
0 => STDIN,
39+
1 => array( 'pipe', 'w' ),
40+
2 => array( 'pipe', 'w' ),
41+
);
42+
43+
$proc = proc_open( $this->command, $descriptors, $pipes, $cwd, $this->env );
44+
45+
$stdout = stream_get_contents( $pipes[1] );
46+
fclose( $pipes[1] );
47+
48+
$stderr = stream_get_contents( $pipes[2] );
49+
fclose( $pipes[2] );
50+
51+
return new ProcessRun( array(
52+
'stdout' => $stdout,
53+
'stderr' => $stderr,
54+
'return_code' => proc_close( $proc ),
55+
'command' => $this->command,
56+
'cwd' => $cwd,
57+
'env' => $this->env
58+
) );
59+
}
60+
61+
/**
62+
* Run the command, but throw an Exception on error.
63+
*
64+
* @return ProcessRun
65+
*/
66+
public function run_check() {
67+
$r = $this->run();
68+
69+
if ( $r->return_code || !empty( $r->STDERR ) ) {
70+
throw new \RuntimeException( $r );
71+
}
72+
73+
return $r;
74+
}
75+
}

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)