Skip to content
This repository has been archived by the owner on Jul 8, 2023. It is now read-only.

Commit

Permalink
Merge branch 'release/3.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
ezzatron committed Feb 22, 2016
2 parents c9a4c52 + 2aebbe8 commit 8bcaa15
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 108 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Composer NPM bridge changelog

## 3.0.1 (2016-02-22)

- **[FIXED]** Fixed bug where Isolator was unable to be autoloaded ([#11]).

[#11]: https://github.com/eloquent/composer-npm-bridge/issues/11

## 3.0.0 (2016-02-12)

- **[BC BREAK]** Stripped down implementation, many public methods removed.
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@
[current version]: https://packagist.org/packages/eloquent/composer-npm-bridge
[version-image]: https://img.shields.io/packagist/v/eloquent/composer-npm-bridge.svg?style=flat-square "This project uses semantic versioning"

## Installation and documentation
## Installation

* Available as [Composer] package [eloquent/composer-npm-bridge].

[composer]: http://getcomposer.org/
[eloquent/composer-npm-bridge]: https://packagist.org/packages/eloquent/composer-npm-bridge

## Requirements

* The `npm` executable must be available in PATH.
Expand All @@ -26,7 +29,7 @@
To utilize the *Composer NPM bridge*, simply add `eloquent/composer-npm-bridge`
to the `require` section of the project's Composer configuration:

composer require eloquent/composer-npm-bridge:~2
composer require eloquent/composer-npm-bridge:^3

NPM dependencies are specified via a [package.json] configuration file in the
root directory of the Composer package. Source control should be configured to
Expand Down
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
"type": "composer-plugin",
"require": {
"php": ">=5.3",
"composer-plugin-api": "^1",
"icecave/isolator": "^2|^3"
"composer-plugin-api": "^1"
},
"require-dev": {
"composer/composer": "dev-master",
Expand Down
89 changes: 16 additions & 73 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 12 additions & 13 deletions src/NpmClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Composer\Util\ProcessExecutor;
use Eloquent\Composer\NpmBridge\Exception\NpmCommandFailedException;
use Eloquent\Composer\NpmBridge\Exception\NpmNotFoundException;
use Icecave\Isolator\Isolator;
use Symfony\Component\Process\ExecutableFinder;

/**
Expand All @@ -29,11 +28,7 @@ class NpmClient
*/
public static function create()
{
return new self(
new ProcessExecutor(),
new ExecutableFinder(),
Isolator::get()
);
return new self(new ProcessExecutor(), new ExecutableFinder());
}

/**
Expand All @@ -43,16 +38,19 @@ public static function create()
*
* @param ProcessExecutor $processExecutor The process executor to use.
* @param ExecutableFinder $executableFinder The executable finder to use.
* @param Isolator $isolator The isolator to use.
* @param callable $getcwd The getcwd() implementation to use.
* @param callable $chdir The chdir() implementation to use.
*/
public function __construct(
ProcessExecutor $processExecutor,
ExecutableFinder $executableFinder,
Isolator $isolator
$getcwd = 'getcwd',
$chdir = 'chdir'
) {
$this->processExecutor = $processExecutor;
$this->executableFinder = $executableFinder;
$this->isolator = $isolator;
$this->getcwd = $getcwd;
$this->chdir = $chdir;
}

/**
Expand Down Expand Up @@ -111,14 +109,14 @@ private function executeNpm($arguments, $workingDirectoryPath)
$command = implode(' ', array_map('escapeshellarg', $arguments));

if (null !== $workingDirectoryPath) {
$previousWorkingDirectoryPath = $this->isolator->getcwd();
$this->isolator->chdir($workingDirectoryPath);
$previousWorkingDirectoryPath = call_user_func($this->getcwd);
call_user_func($this->chdir, $workingDirectoryPath);
}

$exitCode = $this->processExecutor->execute($command);

if (null !== $workingDirectoryPath) {
$this->isolator->chdir($previousWorkingDirectoryPath);
call_user_func($this->chdir, $previousWorkingDirectoryPath);
}

if (0 !== $exitCode) {
Expand All @@ -141,6 +139,7 @@ private function npmPath()

private $processExecutor;
private $executableFinder;
private $isolator;
private $getcwd;
private $chdir;
private $npmPath;
}
37 changes: 19 additions & 18 deletions test/suite/NpmClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ protected function setUp()
{
$this->processExecutor = Phony::mock('Composer\Util\ProcessExecutor');
$this->executableFinder = Phony::mock('Symfony\Component\Process\ExecutableFinder');
$this->isolator = Phony::mock('Icecave\Isolator\Isolator');
$this->getcwd = Phony::stub();
$this->chdir = Phony::stub();
$this->client =
new NpmClient($this->processExecutor->mock(), $this->executableFinder->mock(), $this->isolator->mock());
new NpmClient($this->processExecutor->mock(), $this->executableFinder->mock(), $this->getcwd, $this->chdir);

$this->executableFinder->find('npm')->returns('/path/to/npm');
$this->isolator->getcwd()->returns('/path/to/cwd');
$this->processExecutor->execute('*')->returns(0);
$this->executableFinder->find('npm')->returns('/path/to/npm');
$this->getcwd->returns('/path/to/cwd');
}

public function testInstall()
Expand All @@ -37,12 +38,12 @@ public function testInstall()
$this->assertNull($this->client->install('/path/to/project'));
Phony::inOrder(
$this->executableFinder->find->calledWith('npm'),
$this->isolator->chdir->calledWith('/path/to/project'),
$this->chdir->calledWith('/path/to/project'),
$this->processExecutor->execute->calledWith("'/path/to/npm' 'install'"),
$this->isolator->chdir->calledWith('/path/to/cwd'),
$this->isolator->chdir->calledWith('/path/to/project'),
$this->chdir->calledWith('/path/to/cwd'),
$this->chdir->calledWith('/path/to/project'),
$this->processExecutor->execute->calledWith("'/path/to/npm' 'install'"),
$this->isolator->chdir->calledWith('/path/to/cwd')
$this->chdir->calledWith('/path/to/cwd')
);
}

Expand All @@ -51,9 +52,9 @@ public function testInstallProductionMode()
$this->assertNull($this->client->install('/path/to/project', false));
Phony::inOrder(
$this->executableFinder->find->calledWith('npm'),
$this->isolator->chdir->calledWith('/path/to/project'),
$this->chdir->calledWith('/path/to/project'),
$this->processExecutor->execute->calledWith("'/path/to/npm' 'install' '--production'"),
$this->isolator->chdir->calledWith('/path/to/cwd')
$this->chdir->calledWith('/path/to/cwd')
);
}

Expand All @@ -79,12 +80,12 @@ public function testUpdate()
$this->assertNull($this->client->update('/path/to/project'));
Phony::inOrder(
$this->executableFinder->find->calledWith('npm'),
$this->isolator->chdir->calledWith('/path/to/project'),
$this->chdir->calledWith('/path/to/project'),
$this->processExecutor->execute->calledWith("'/path/to/npm' 'update'"),
$this->isolator->chdir->calledWith('/path/to/cwd'),
$this->isolator->chdir->calledWith('/path/to/project'),
$this->chdir->calledWith('/path/to/cwd'),
$this->chdir->calledWith('/path/to/project'),
$this->processExecutor->execute->calledWith("'/path/to/npm' 'update'"),
$this->isolator->chdir->calledWith('/path/to/cwd')
$this->chdir->calledWith('/path/to/cwd')
);
}

Expand All @@ -110,12 +111,12 @@ public function testShrinkwrap()
$this->assertNull($this->client->shrinkwrap('/path/to/project'));
Phony::inOrder(
$this->executableFinder->find->calledWith('npm'),
$this->isolator->chdir->calledWith('/path/to/project'),
$this->chdir->calledWith('/path/to/project'),
$this->processExecutor->execute->calledWith("'/path/to/npm' 'shrinkwrap'"),
$this->isolator->chdir->calledWith('/path/to/cwd'),
$this->isolator->chdir->calledWith('/path/to/project'),
$this->chdir->calledWith('/path/to/cwd'),
$this->chdir->calledWith('/path/to/project'),
$this->processExecutor->execute->calledWith("'/path/to/npm' 'shrinkwrap'"),
$this->isolator->chdir->calledWith('/path/to/cwd')
$this->chdir->calledWith('/path/to/cwd')
);
}

Expand Down

0 comments on commit 8bcaa15

Please sign in to comment.