Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Barys Biankouski committed May 25, 2023
1 parent 31ae1b7 commit 98eadbd
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 22 deletions.
8 changes: 6 additions & 2 deletions composer
Expand Up @@ -180,7 +180,12 @@ if (!class_exists('ComposerWrapper')) {

public function __construct(ComposerWrapperParams $params = null)
{
$this->params = null === $params ? new ComposerWrapperParams() : $params;
if (null === $params ) {
$this->params = new ComposerWrapperParams();
$this->params->loadReal();
} else {
$this->params = $params;
}
}

protected function file_get_contents()
Expand Down Expand Up @@ -519,7 +524,6 @@ if (!class_exists('ComposerWrapper')) {
*/
public function run($cliArguments)
{
$this->params->loadReal();
$composerPathName = "{$this->params->getComposerDir()}/composer.phar";

$this->ensureInstalled($composerPathName);
Expand Down
2 changes: 1 addition & 1 deletion tests/ComposerWrapperParamsTest.php
Expand Up @@ -19,7 +19,7 @@ function () use ($params) {
},
array(
"COMPOSER_UPDATE_FREQ" => "101 days",
"COMPOSER_FORCE_MAJOR_VERSION" => 2,
"COMPOSER_CHANNEL" => 2,
"COMPOSER_DIR" => 'dir_from_env',
),
__DIR__ . '/composer.json_read_config_examples/envVariablesHasBiggerPriority'
Expand Down
29 changes: 13 additions & 16 deletions tests/ComposerWrapperTest.php
Expand Up @@ -8,7 +8,6 @@ class ComposerWrapperTest extends TestCase
{

const WRAPPER_CLASS = 'ComposerWrapper';
const WRAPPER_PARAMS_CLASS = 'ComposerWrapperParams';
const INSTALLER = '<?php die("This is a stub and should never be executed");';


Expand Down Expand Up @@ -58,19 +57,17 @@ public function installsIfNotInstalled()

/**
* @test
* @dataProvider installsRequestedMajorVersionExamples
* @dataProvider installsRequestedChannelExamples
*/
public function installsRequestedMajorVersion($dir, $supportsMajorVersionFlag, $requestedVersion)
public function installsRequestedChannel($dir, $supportsChannelFlag, $requestedChannel)
{
$params = $this->getMockBuilder(self::WRAPPER_PARAMS_CLASS)
->setMethods(array('getForceMajorVersion'))
->getMock();
$params->expects(self::any())->method('getForceMajorVersion')->willReturn($requestedVersion);
$params = new ComposerWrapperParams();
$params->setChannel($requestedChannel);
$wrapper = $this->getMockBuilder(self::WRAPPER_CLASS)
->setMethods(array('showError', 'copy', 'verifyChecksum', 'unlink', 'supportsForceVersionFlag'))
->setMethods(array('showError', 'copy', 'verifyChecksum', 'unlink', 'supportsChannelFlag'))
->setConstructorArgs(array($params))
->getMock();
if ($supportsMajorVersionFlag) {
if ($supportsChannelFlag) {
$showErrorExpectation = self::never();
} else {
$showErrorExpectation = self::once();
Expand All @@ -79,25 +76,25 @@ public function installsRequestedMajorVersion($dir, $supportsMajorVersionFlag, $
$wrapper->expects(self::once())->method('copy')->willReturn(true);
$wrapper->expects(self::once())->method('verifyChecksum')->willReturn(null);
$wrapper->expects(self::once())->method('unlink')->willReturn(null);
$wrapper->expects(self::once())->method('supportsForceVersionFlag')->willReturn($supportsMajorVersionFlag);
$wrapper->expects(self::once())->method('supportsChannelFlag')->willReturn($supportsChannelFlag);
self::callNonPublic(
$wrapper,
'installComposer',
array($dir)
);
}

public static function installsRequestedMajorVersionExamples()
public static function installsRequestedChannelExamples()
{
return array(
'version 1 is requested; installed supports flag' => array(
'dir' => __DIR__ . '/installer_stub_with_major_version_flags',
'supportsMajorVersionFlags' => true,
'supportsChannelFlags' => true,
'requestedVersion' => 1,
),
'version 1 is requested; installed doesn\'t support flag' => array(
'dir' => __DIR__ . '/installer_stub_without_major_version_flags',
'supportsMajorVersionFlags' => false,
'supportsChannelFlags' => false,
'requestedVersion' => 1,
),
);
Expand Down Expand Up @@ -452,10 +449,10 @@ public function doesNotTryToSelfUpdateWhenUpToDate()
public function addsForceVersionFlag($version, $supportsFlags, $flag, $expectError = false)
{
$wrapper = $this->getMockBuilder(self::WRAPPER_CLASS)
->setMethods(array('supportsForceVersionFlag', 'touch', 'passthru', 'showError'))
->setMethods(array('supportsChannelFlag', 'touch', 'passthru', 'showError'))
->getMock();

$wrapper->expects($this->once())->method('supportsForceVersionFlag')->willReturn($supportsFlags);
$wrapper->expects($this->once())->method('supportsChannelFlag')->willReturn($supportsFlags);
$wrapper->expects($this->once())->method('touch')->willReturn(null);
$wrapper->expects($expectError ? $this->once() : $this->never())->method('showError');
$self = $this;
Expand Down Expand Up @@ -631,7 +628,7 @@ public function detectsSupportForForceVersionFlags($helpOutput, $versions, $expe

$this->assertSame(
$expectedResult,
self::callNonPublic($mock, 'supportsForceVersionFlag', array(array('composer'), $version))
self::callNonPublic($mock, 'supportsChannelFlag', array(array('composer'), $version))
);
}
}
Expand Down
Expand Up @@ -2,7 +2,7 @@
"extra": {
"wrapper": {
"update-freq": "101 days",
"major-version": 2,
"channel": 2,
"composer-dir": "dir_from_composer-from-env.json"
}
}
Expand Down
Expand Up @@ -2,7 +2,7 @@
"extra": {
"wrapper": {
"update-freq": "100 days",
"major-version": 1,
"channel": 1,
"composer-dir": "dir_from_composer.json"
}
}
Expand Down
Expand Up @@ -2,7 +2,7 @@
"extra": {
"wrapper": {
"update-freq": "100 days",
"major-version": 1,
"channel": 1,
"composer-dir": "dir_from_composer.json"
}
}
Expand Down

0 comments on commit 98eadbd

Please sign in to comment.