Skip to content

Commit

Permalink
Update to composer 1.8
Browse files Browse the repository at this point in the history
  • Loading branch information
francoispluchino committed May 1, 2019
1 parent 5afbd4f commit ea4a6e6
Show file tree
Hide file tree
Showing 5 changed files with 302 additions and 137 deletions.
44 changes: 44 additions & 0 deletions Tests/ComposerUtil.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

/*
* This file is part of the Fxp Composer Asset Plugin package.
*
* (c) François Pluchino <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Fxp\Composer\AssetPlugin\Tests;

use Composer\Composer;
use Composer\Package\Version\VersionParser;

/**
* Helper for Composer.
*
* @author François Pluchino <[email protected]>
*/
abstract class ComposerUtil
{
/**
* @param string[] $value The map of composer versions and the values
*
* @return string
*/
public static function getValueByVersion(array $value)
{
$versionParser = new VersionParser();
$composerVersionConstraint = $versionParser->parseConstraints(Composer::VERSION);

foreach ($value as $versionRange => $content) {
$rangeConstraint = $versionParser->parseConstraints($versionRange);

if ($composerVersionConstraint->matches($rangeConstraint)) {
return $content;
}
}

throw new \InvalidArgumentException('The composer version is not found');
}
}
12 changes: 10 additions & 2 deletions Tests/Repository/Vcs/GitBitbucketDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Composer\Util\Filesystem;
use Composer\Util\RemoteFilesystem;
use Fxp\Composer\AssetPlugin\Repository\Vcs\GitBitbucketDriver;
use Fxp\Composer\AssetPlugin\Tests\ComposerUtil;

/**
* Tests of vcs git bitbucket repository.
Expand Down Expand Up @@ -88,7 +89,10 @@ public function testPublicRepositoryWithComposer($type, $filename)
),
array(
'bitbucket.org',
'https://api.bitbucket.org/1.0/repositories/composer-test/repo-name/main-branch',
ComposerUtil::getValueByVersion(array(
'^1.7.0' => 'https://api.bitbucket.org/2.0/repositories/composer-test/repo-name?fields=mainbranch',
'1.6.*' => 'https://api.bitbucket.org/1.0/repositories/composer-test/repo-name/main-branch',
)),
false,
),
array(
Expand All @@ -115,7 +119,11 @@ public function testPublicRepositoryWithComposer($type, $filename)
$driver = new GitBitbucketDriver($repoConfig, $io, $this->config, null, $remoteFilesystem);
$driver->initialize();

$this->assertEquals('test_master', $driver->getRootIdentifier());
$expectedRootIdentifier = ComposerUtil::getValueByVersion(array(
'^1.7.0' => 'master',
'1.6.*' => 'test_master',
));
$this->assertEquals($expectedRootIdentifier, $driver->getRootIdentifier());

$dist = $driver->getDist($sha);
$this->assertEquals('zip', $dist['type']);
Expand Down
12 changes: 10 additions & 2 deletions Tests/Repository/Vcs/HgBitbucketDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Composer\Util\Filesystem;
use Composer\Util\RemoteFilesystem;
use Fxp\Composer\AssetPlugin\Repository\Vcs\HgBitbucketDriver;
use Fxp\Composer\AssetPlugin\Tests\ComposerUtil;

/**
* Tests of vcs mercurial bitbucket repository.
Expand Down Expand Up @@ -87,7 +88,10 @@ public function testPublicRepositoryWithComposer($type, $filename)
),
array(
'bitbucket.org',
'https://api.bitbucket.org/1.0/repositories/composer-test/repo-name/main-branch',
ComposerUtil::getValueByVersion(array(
'^1.7.0' => 'https://api.bitbucket.org/2.0/repositories/composer-test/repo-name?fields=mainbranch',
'1.6.*' => 'https://api.bitbucket.org/1.0/repositories/composer-test/repo-name/main-branch',
)),
false,
),
array(
Expand Down Expand Up @@ -115,7 +119,11 @@ public function testPublicRepositoryWithComposer($type, $filename)
$driver->initialize();
$this->setAttribute($driver, 'tags', array($identifier => $sha));

$this->assertEquals('test_master', $driver->getRootIdentifier());
$expectedRootIdentifier = ComposerUtil::getValueByVersion(array(
'^1.7.0' => 'default',
'1.6.*' => 'test_master',
));
$this->assertEquals($expectedRootIdentifier, $driver->getRootIdentifier());

$dist = $driver->getDist($sha);
$this->assertEquals('zip', $dist['type']);
Expand Down
56 changes: 45 additions & 11 deletions Tests/Util/PerforceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Composer\IO\IOInterface;
use Composer\Util\Filesystem;
use Composer\Util\ProcessExecutor;
use Fxp\Composer\AssetPlugin\Tests\ComposerUtil;
use Fxp\Composer\AssetPlugin\Util\Perforce;

/**
Expand Down Expand Up @@ -121,7 +122,10 @@ public function getTestRepoConfig()

public function testGetComposerInformationWithoutLabelWithoutStream()
{
$expectedCommand = 'p4 -u user -c composer_perforce_TEST_depot -p port print //depot/ASSET.json';
$expectedCommand = ComposerUtil::getValueByVersion(array(
'^1.7.0' => 'p4 -u user -c composer_perforce_TEST_depot -p port print '.escapeshellarg('//depot/ASSET.json'),
'1.6.*' => 'p4 -u user -c composer_perforce_TEST_depot -p port print //depot/ASSET.json',
));
$this->processExecutor->expects($this->at(0))
->method('execute')
->with($this->equalTo($expectedCommand))
Expand All @@ -147,7 +151,10 @@ function ($command, &$output) {

public function testGetComposerInformationWithLabelWithoutStream()
{
$expectedCommand = 'p4 -u user -p port files //depot/[email protected]';
$expectedCommand = ComposerUtil::getValueByVersion(array(
'^1.7.0' => 'p4 -u user -p port files '.escapeshellarg('//depot/[email protected]'),
'1.6.*' => 'p4 -u user -p port files //depot/[email protected]',
));
$this->processExecutor->expects($this->at(0))
->method('execute')
->with($this->equalTo($expectedCommand))
Expand All @@ -161,7 +168,10 @@ function ($command, &$output) {
)
);

$expectedCommand = 'p4 -u user -c composer_perforce_TEST_depot -p port print //depot/ASSET.json@10001';
$expectedCommand = ComposerUtil::getValueByVersion(array(
'^1.7.0' => 'p4 -u user -c composer_perforce_TEST_depot -p port print '.escapeshellarg('//depot/ASSET.json@10001'),
'1.6.*' => 'p4 -u user -c composer_perforce_TEST_depot -p port print //depot/ASSET.json@10001',
));
$this->processExecutor->expects($this->at(1))
->method('execute')
->with($this->equalTo($expectedCommand))
Expand Down Expand Up @@ -190,7 +200,10 @@ public function testGetComposerInformationWithoutLabelWithStream()
{
$this->setAssetPerforceToStream();

$expectedCommand = 'p4 -u user -c composer_perforce_TEST_depot_branch -p port print //depot/branch/ASSET.json';
$expectedCommand = ComposerUtil::getValueByVersion(array(
'^1.7.0' => 'p4 -u user -c composer_perforce_TEST_depot_branch -p port print '.escapeshellarg('//depot/branch/ASSET.json'),
'1.6.*' => 'p4 -u user -c composer_perforce_TEST_depot_branch -p port print //depot/branch/ASSET.json',
));
$this->processExecutor->expects($this->at(0))
->method('execute')
->with($this->equalTo($expectedCommand))
Expand Down Expand Up @@ -218,7 +231,10 @@ function ($command, &$output) {
public function testGetComposerInformationWithLabelWithStream()
{
$this->setAssetPerforceToStream();
$expectedCommand = 'p4 -u user -p port files //depot/branch/[email protected]';
$expectedCommand = ComposerUtil::getValueByVersion(array(
'^1.7.0' => 'p4 -u user -p port files '.escapeshellarg('//depot/branch/[email protected]'),
'1.6.*' => 'p4 -u user -p port files //depot/branch/[email protected]',
));
$this->processExecutor->expects($this->at(0))
->method('execute')
->with($this->equalTo($expectedCommand))
Expand All @@ -232,7 +248,10 @@ function ($command, &$output) {
)
);

$expectedCommand = 'p4 -u user -c composer_perforce_TEST_depot_branch -p port print //depot/branch/ASSET.json@10001';
$expectedCommand = ComposerUtil::getValueByVersion(array(
'^1.7.0' => 'p4 -u user -c composer_perforce_TEST_depot_branch -p port print '.escapeshellarg('//depot/branch/ASSET.json@10001'),
'1.6.*' => 'p4 -u user -c composer_perforce_TEST_depot_branch -p port print //depot/branch/ASSET.json@10001',
));
$this->processExecutor->expects($this->at(1))
->method('execute')
->with($this->equalTo($expectedCommand))
Expand Down Expand Up @@ -260,7 +279,10 @@ function ($command, &$output) {
public function testGetComposerInformationWithLabelButNoSuchFile()
{
$this->setAssetPerforceToStream();
$expectedCommand = 'p4 -u user -p port files //depot/branch/[email protected]';
$expectedCommand = ComposerUtil::getValueByVersion(array(
'^1.7.0' => 'p4 -u user -p port files '.escapeshellarg('//depot/branch/[email protected]'),
'1.6.*' => 'p4 -u user -p port files //depot/branch/[email protected]',
));
$this->processExecutor->expects($this->at(0))
->method('execute')
->with($this->equalTo($expectedCommand))
Expand All @@ -282,7 +304,10 @@ function ($command, &$output) {
public function testGetComposerInformationWithLabelWithStreamWithNoChange()
{
$this->setAssetPerforceToStream();
$expectedCommand = 'p4 -u user -p port files //depot/branch/[email protected]';
$expectedCommand = ComposerUtil::getValueByVersion(array(
'^1.7.0' => 'p4 -u user -p port files '.escapeshellarg('//depot/branch/[email protected]'),
'1.6.*' => 'p4 -u user -p port files //depot/branch/[email protected]',
));
$this->processExecutor->expects($this->at(0))
->method('execute')
->with($this->equalTo($expectedCommand))
Expand All @@ -306,7 +331,10 @@ public function testCheckServerExists()
/* @var ProcessExecutor|\PHPUnit_Framework_MockObject_MockObject $processExecutor */
$processExecutor = $this->getMockBuilder('Composer\Util\ProcessExecutor')->getMock();

$expectedCommand = 'p4 -p perforce.does.exist:port info -s';
$expectedCommand = ComposerUtil::getValueByVersion(array(
'^1.7.0' => 'p4 -p '.escapeshellarg('perforce.does.exist:port').' info -s',
'1.6.*' => 'p4 -p perforce.does.exist:port info -s',
));
$processExecutor->expects($this->at(0))
->method('execute')
->with($this->equalTo($expectedCommand), $this->equalTo(null))
Expand All @@ -326,7 +354,10 @@ public function testCheckServerClientError()
/* @var ProcessExecutor|\PHPUnit_Framework_MockObject_MockObject $processExecutor */
$processExecutor = $this->getMockBuilder('Composer\Util\ProcessExecutor')->getMock();

$expectedCommand = 'p4 -p perforce.does.exist:port info -s';
$expectedCommand = ComposerUtil::getValueByVersion(array(
'^1.7.0' => 'p4 -p '.escapeshellarg('perforce.does.exist:port').' info -s',
'1.6.*' => 'p4 -p perforce.does.exist:port info -s',
));
$processExecutor->expects($this->at(0))
->method('execute')
->with($this->equalTo($expectedCommand), $this->equalTo(null))
Expand All @@ -343,7 +374,10 @@ public function testCleanupClientSpecShouldDeleteClient()
$this->perforce->setFilesystem($fs);

$testClient = $this->perforce->getClient();
$expectedCommand = 'p4 -u '.self::TEST_P4USER.' -p '.self::TEST_PORT.' client -d '.$testClient;
$expectedCommand = ComposerUtil::getValueByVersion(array(
'^1.7.0' => 'p4 -u '.self::TEST_P4USER.' -p '.self::TEST_PORT.' client -d '.escapeshellarg($testClient),
'1.6.*' => 'p4 -u '.self::TEST_P4USER.' -p '.self::TEST_PORT.' client -d '.$testClient,
));
$this->processExecutor->expects($this->once())->method('execute')->with($this->equalTo($expectedCommand));

$fs->expects($this->once())->method('remove')->with($this->perforce->getP4ClientSpec());
Expand Down
Loading

0 comments on commit ea4a6e6

Please sign in to comment.