-
-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5afbd4f
commit ea4a6e6
Showing
5 changed files
with
302 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
||
/** | ||
|
@@ -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)) | ||
|
@@ -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)) | ||
|
@@ -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)) | ||
|
@@ -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)) | ||
|
@@ -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)) | ||
|
@@ -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)) | ||
|
@@ -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)) | ||
|
@@ -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)) | ||
|
@@ -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)) | ||
|
@@ -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)) | ||
|
@@ -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()); | ||
|
Oops, something went wrong.