-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Add check to ensure the right version of Composer is used (#164)
- Loading branch information
Showing
3 changed files
with
80 additions
and
2 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,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Bamarni\Composer\Bin\Tests; | ||
|
||
use Symfony\Component\Process\Process; | ||
use function preg_match; | ||
|
||
final class ComposerVersionProvider | ||
{ | ||
public static function getComposerVersion(): string | ||
{ | ||
$composerVersionProcess = Process::fromShellCommandline( | ||
'composer --version --no-ansi --no-interaction', | ||
null, | ||
null, | ||
null, | ||
1 | ||
); | ||
|
||
$composerVersionProcess->mustRun(); | ||
|
||
$output = $composerVersionProcess->getOutput(); | ||
|
||
return self::extractComposerVersion($output); | ||
} | ||
|
||
private static function extractComposerVersion(string $versionOutput): string | ||
{ | ||
preg_match('/Composer version (?<version>\d+\.\d+\.\d+) /', $versionOutput, $matches); | ||
|
||
return $matches['version']; | ||
} | ||
} |
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,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Bamarni\Composer\Bin\Tests; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use function preg_match; | ||
use function sprintf; | ||
|
||
/** | ||
* @group e2e | ||
* @covers \Bamarni\Composer\Bin\Tests\ComposerVersionProvider | ||
*/ | ||
final class ComposerVersionProviderTest extends TestCase | ||
{ | ||
public function test_it_can_get_the_composer_version(): void | ||
{ | ||
$expectedPattern = '/^\d+\.\d+\.\d+$/'; | ||
|
||
$actual = ComposerVersionProvider::getComposerVersion(); | ||
|
||
self::assertSame( | ||
1, | ||
preg_match($expectedPattern, $actual), | ||
sprintf( | ||
'The version "%s" does not match the pattern "%s".', | ||
$actual, | ||
$expectedPattern | ||
) | ||
); | ||
} | ||
} |
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