Skip to content

Commit

Permalink
Experimental refactor of the bootstrap process (WIP)
Browse files Browse the repository at this point in the history
The order of execution of the bootstrapping process has been heavily refactored
to contain everything in separate, isolated steps as far as currently possible.

There's a major issue remaining, that will need further discussion: the
autoloader for the framework itself (needed for any commands to register without
errors) and the autoloader for the bundled commands (that are required through
Composer) would need to be split and moved independently, but reside within the
same Composer autoloader setup.

See wp-cli#3850
  • Loading branch information
schlessera committed Mar 2, 2017
1 parent f666104 commit 0addae7
Show file tree
Hide file tree
Showing 32 changed files with 1,690 additions and 722 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
},
"autoload": {
"psr-0": { "WP_CLI": "php" },
"psr-4": { "": "php/commands/src" },
"classmap": [ "php/export" ]
}
}
152 changes: 105 additions & 47 deletions features/command.feature
Original file line number Diff line number Diff line change
Expand Up @@ -688,21 +688,52 @@ Feature: WP-CLI Commands
Scenario: Override command bundled with current source

Given an empty directory
And a cli-override.php file:
And a cli-command-override/cli.php file:
"""
<?php
WP_CLI::add_command( 'cli', function(){
WP_CLI::success( "WP-Override-CLI" );
}, array( 'when' => 'before_wp_load' ) );
if ( ! class_exists( 'WP_CLI' ) ) {
return;
}
$autoload = dirname( __FILE__ ) . '/vendor/autoload.php';
if ( file_exists( $autoload ) ) {
require_once $autoload;
}
WP_CLI::add_command( 'cli', 'CLI_Command', array( 'when' => 'before_wp_load' ) );
"""
And a cli-command-override/src/CLI_Command.php file:
"""
<?php
class CLI_Command extends WP_CLI_Command {
public function version() {
WP_CLI::success( "WP-Override-CLI" );
}
}
"""
And a cli-command-override/composer.json file:
"""
{
"name": "wp-cli/cli-override",
"description": "A command that overrides the bundled 'cli' command.",
"autoload": {
"psr-4": { "": "src/" },
"files": [ "cli.php" ]
},
"extra": {
"commands": [
"cli"
]
}
}
"""
And I run `composer install --working-dir={RUN_DIR}/cli-command-override --no-interaction`

When I run `wp cli version`
Then STDOUT should contain:
"""
WP-CLI
"""

When I run `wp --require=cli-override.php cli version`
When I run `wp --require=cli-command-override/cli.php cli version`
Then STDOUT should contain:
"""
WP-Override-CLI
Expand All @@ -713,21 +744,52 @@ Feature: WP-CLI Commands

Given an empty directory
And a new Phar
And a cli-override.php file:
And a cli-command-override/cli.php file:
"""
<?php
if ( ! class_exists( 'WP_CLI' ) ) {
return;
}
$autoload = dirname( __FILE__ ) . '/vendor/autoload.php';
if ( file_exists( $autoload ) ) {
require_once $autoload;
}
WP_CLI::add_command( 'cli', 'CLI_Command', array( 'when' => 'before_wp_load' ) );
"""
And a cli-command-override/src/CLI_Command.php file:
"""
<?php
WP_CLI::add_command( 'cli', function(){
WP_CLI::success( "WP-Override-CLI" );
}, array( 'when' => 'before_wp_load' ) );
class CLI_Command extends WP_CLI_Command {
public function version() {
WP_CLI::success( "WP-Override-CLI" );
}
}
"""
And a cli-command-override/composer.json file:
"""
{
"name": "wp-cli/cli-override",
"description": "A command that overrides the bundled 'cli' command.",
"autoload": {
"psr-4": { "": "src/" },
"files": [ "cli.php" ]
},
"extra": {
"commands": [
"cli"
]
}
}
"""
And I run `composer install --working-dir={RUN_DIR}/cli-command-override --no-interaction`

When I run `{PHAR_PATH} cli version`
Then STDOUT should contain:
"""
WP-CLI
"""

When I run `{PHAR_PATH} --require=cli-override.php cli version`
When I run `{PHAR_PATH} --require=cli-command-override/cli.php cli version`
Then STDOUT should contain:
"""
WP-Override-CLI
Expand All @@ -738,56 +800,52 @@ Feature: WP-CLI Commands

Given an empty directory
And a downloaded Phar with version "1.0.0"
And a cli-override.php file:
And a cli-command-override/cli.php file:
"""
<?php
WP_CLI::add_command( 'cli', function(){
WP_CLI::success( "WP-Override-CLI" );
}, array( 'when' => 'before_wp_load' ) );
if ( ! class_exists( 'WP_CLI' ) ) {
return;
}
$autoload = dirname( __FILE__ ) . '/vendor/autoload.php';
if ( file_exists( $autoload ) ) {
require_once $autoload;
}
WP_CLI::add_command( 'cli', 'CLI_Command', array( 'when' => 'before_wp_load' ) );
"""

When I run `{PHAR_PATH} cli version`
Then STDOUT should contain:
"""
WP-CLI 1.0.0
"""

When I run `{PHAR_PATH} --require=cli-override.php cli version`
Then STDOUT should contain:
"""
WP-Override-CLI
"""

@bootstrap
Scenario: Override command bundled with Composer stack

Given an empty directory
And a composer.json file:
And a cli-command-override/src/CLI_Command.php file:
"""
{
"name": "wp-cli/composer-test",
"type": "project",
"require": {
"wp-cli/wp-cli": "1.1.0"
}
<?php
class CLI_Command extends WP_CLI_Command {
public function version() {
WP_CLI::success( "WP-Override-CLI" );
}
}
"""
And a cli-override.php file:
And a cli-command-override/composer.json file:
"""
<?php
WP_CLI::add_command( 'cli', function(){
WP_CLI::success( "WP-Override-CLI" );
}, array( 'when' => 'before_wp_load' ) );
{
"name": "wp-cli/cli-override",
"description": "A command that overrides the bundled 'cli' command.",
"autoload": {
"psr-4": { "": "src/" },
"files": [ "cli.php" ]
},
"extra": {
"commands": [
"cli"
]
}
}
"""
And I run `composer install --no-interaction`
And I run `composer install --working-dir={RUN_DIR}/cli-command-override --no-interaction`

When I run `vendor/bin/wp cli version`
When I run `{PHAR_PATH} cli version`
Then STDOUT should contain:
"""
WP-CLI 1.1.0
WP-CLI 1.0.0
"""

When I run `vendor/bin/wp --require=cli-override.php cli version`
When I run `{PHAR_PATH} --require=cli-command-override/cli.php cli version`
Then STDOUT should contain:
"""
WP-Override-CLI
Expand Down
56 changes: 48 additions & 8 deletions features/framework.feature
Original file line number Diff line number Diff line change
Expand Up @@ -299,19 +299,39 @@ Feature: Load WP-CLI
And a cli-command-override/cli.php file:
"""
<?php
WP_CLI::add_command( 'cli', function(){
WP_CLI::success( "WP-Override-CLI" );
}, array( 'when' => 'before_wp_load' ) );
if ( ! class_exists( 'WP_CLI' ) ) {
return;
}
$autoload = dirname( __FILE__ ) . '/vendor/autoload.php';
if ( file_exists( $autoload ) ) {
require_once $autoload;
}
WP_CLI::add_command( 'cli', 'CLI_Command', array( 'when' => 'before_wp_load' ) );
"""
And a cli-command-override/src/CLI_Command.php file:
"""
<?php
class CLI_Command extends WP_CLI_Command {
public function version() {
WP_CLI::success( "WP-Override-CLI" );
}
}
"""
And a cli-command-override/composer.json file:
"""
{
"name": "wp-cli/cli-override",
"description": "A command that overrides the bundled 'cli' command.",
"autoload": {
"psr-4": { "": "src/" },
"files": [ "cli.php" ]
},
"extra": {
"commands": [
"cli"
]
}
}
}
"""
And I run `composer install --no-interaction`
Expand Down Expand Up @@ -346,19 +366,39 @@ Feature: Load WP-CLI
And a cli-command-override/cli.php file:
"""
<?php
WP_CLI::add_command( 'cli', function(){
WP_CLI::success( "WP-Override-CLI" );
}, array( 'when' => 'before_wp_load' ) );
if ( ! class_exists( 'WP_CLI' ) ) {
return;
}
$autoload = dirname( __FILE__ ) . '/vendor/autoload.php';
if ( file_exists( $autoload ) ) {
require_once $autoload;
}
WP_CLI::add_command( 'cli', 'CLI_Command', array( 'when' => 'before_wp_load' ) );
"""
And a cli-command-override/src/CLI_Command.php file:
"""
<?php
class CLI_Command extends WP_CLI_Command {
public function version() {
WP_CLI::success( "WP-Override-CLI" );
}
}
"""
And a cli-command-override/composer.json file:
"""
{
"name": "wp-cli/cli-override",
"description": "A command that overrides the bundled 'cli' command.",
"autoload": {
"psr-4": { "": "src/" },
"files": [ "cli.php" ]
},
"extra": {
"commands": [
"cli"
]
}
}
}
"""
And I run `composer install --no-interaction`
Expand Down
Loading

0 comments on commit 0addae7

Please sign in to comment.