Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions features/package-install.feature
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,54 @@ Feature: Install WP-CLI packages
"""
"url": "http://wp-cli.org/package-index/"
"""
And the composer.json file should contain:
"""
"canonical": false
"""

When I run `WP_CLI_PACKAGES_DIR=. wp package is-installed wp-cli/restful`
Then the return code should be 0
And STDERR should be empty
And STDOUT should be empty

Scenario: Install a package updates the package index repository to be non-canonical
Given an empty directory
And a composer.json file:
"""
{
"repositories": {
"test" : {
"type": "path",
"url": "./dummy-package/"
},
"wp-cli": {
"type": "composer",
"url": "https://wp-cli.org/package-index/"
}
}
}
"""
And a dummy-package/composer.json file:
"""
{
"name": "wp-cli/restful",
"description": "This is a dummy package we will install instead of actually installing the real package. This prevents the test from hanging indefinitely for some reason, even though it passes. The 'name' must match a real package as it is checked against the package index."
}
"""
When I run `WP_CLI_PACKAGES_DIR=. wp package install wp-cli/restful`
Then STDOUT should contain:
"""
Updating package index repository url...
"""
And STDOUT should contain:
"""
Comment thread
swissspidy marked this conversation as resolved.
Outdated
Success: Package installed
"""
And the composer.json file should contain:
"""
"canonical": false
"""

@require-php-5.6
Scenario: Install a package with 'wp-cli/wp-cli' as a dependency
Given a WP install
Expand Down
10 changes: 7 additions & 3 deletions src/Package_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,9 @@ class Package_Command extends WP_CLI_Command {
* @var array
*/
private $composer_type_package = [
'type' => 'composer',
'url' => self::PACKAGE_INDEX_URL,
'type' => 'composer',
'url' => self::PACKAGE_INDEX_URL,
'canonical' => false,
];

/**
Expand Down Expand Up @@ -365,7 +366,10 @@ public function install( $args, $assoc_args ) {
);
}
// If the composer file does not contain the current package index repository, refresh the repository definition.
if ( empty( $composer_backup_decoded['repositories']['wp-cli']['url'] ) || self::PACKAGE_INDEX_URL !== $composer_backup_decoded['repositories']['wp-cli']['url'] ) {
if ( empty( $composer_backup_decoded['repositories']['wp-cli']['url'] )
|| self::PACKAGE_INDEX_URL !== $composer_backup_decoded['repositories']['wp-cli']['url']
|| ! isset( $composer_backup_decoded['repositories']['wp-cli']['canonical'] )
|| false !== $composer_backup_decoded['repositories']['wp-cli']['canonical'] ) {
Comment thread
swissspidy marked this conversation as resolved.
Outdated
WP_CLI::log( 'Updating package index repository url...' );
$package_args = $this->composer_type_package;
Comment thread
swissspidy marked this conversation as resolved.
Outdated
$json_manipulator->addRepository(
Expand Down
Loading