Skip to content

Commit

Permalink
Allow composer require --no-update (#1150)
Browse files Browse the repository at this point in the history
* Allow --no-update

* Docs

* Unused param

* Pass the package to 'composer remove'
  • Loading branch information
claudiu-cristea authored Dec 1, 2023
1 parent e06abe4 commit fec6afc
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/tasks/Composer.md
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,7 @@ $this->taskComposerRequire()->dependency('foo/bar', '^.2.4.8')->run();
* `noSuggest($noSuggest = null)`

* `param bool` $noSuggest
* `noUpdate()`
* `preferDist($preferDist = null)`

* `param bool` $preferDist
Expand Down
14 changes: 14 additions & 0 deletions src/Task/Composer/Remove.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,20 @@ class Remove extends Base
*/
protected $action = 'remove';

/**
* 'remove' is a keyword, so it cannot be a method name.
*
* @param array|string $project
*
* @return $this
*/
public function dependency(array|string $project): self
{
$project = (array)$project;
$this->args($project);
return $this;
}

/**
* @param bool $dev
*
Expand Down
11 changes: 11 additions & 0 deletions src/Task/Composer/RequireDependency.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ public function noSuggest($noSuggest = true)
return $this;
}

/**
* adds `no-update` option to composer
*
* @return $this
*/
public function noUpdate(): self
{
$this->option('--no-update');
return $this;
}

/**
* {@inheritdoc}
*/
Expand Down
20 changes: 17 additions & 3 deletions tests/unit/Task/ComposerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,17 @@ public function testComposerDumpAutoloadCommand()
public function testComposerRemove()
{
$this->assertEquals(
'composer remove --no-interaction',
(new \Robo\Task\Composer\Remove('composer'))->setConfig(new \Robo\Config())->getCommand()
$this->adjustQuotes("composer remove 'foo/bar' 'baz/qux' --no-interaction"),
(new \Robo\Task\Composer\Remove('composer'))
->setConfig(new \Robo\Config())
->dependency(['foo/bar', 'baz/qux'])
->getCommand()
);
$this->assertEquals(
'composer remove --dev --no-progress --no-update --no-interaction',
$this->adjustQuotes("composer remove 'foo/bar' --dev --no-progress --no-update --no-interaction"),
(new \Robo\Task\Composer\Remove('composer'))
->setConfig(new \Robo\Config())
->dependency('foo/bar')
->dev()
->noProgress()
->noUpdate()
Expand Down Expand Up @@ -355,6 +359,16 @@ public function testComposerRequireCommand()
->dependency(['a/b', 'x/y:^1'])
->getCommand()
);

$this->assertEquals(
$this->adjustQuotes("composer require a/b 'x/y:^1' --no-interaction --no-suggest --no-update"),
(new \Robo\Task\Composer\RequireDependency('composer'))
->setConfig(new \Robo\Config())
->dependency(['a/b', 'x/y:^1'])
->noSuggest()
->noUpdate()
->getCommand()
);
}

public function testComposerCreateProjectCommand()
Expand Down

0 comments on commit fec6afc

Please sign in to comment.