Make use of Phar::running() to get the current phar path
parent
fb397acaa0
commit
e81df52e53
|
@ -23,6 +23,7 @@ use Composer\SelfUpdate\Versions;
|
||||||
use Composer\IO\IOInterface;
|
use Composer\IO\IOInterface;
|
||||||
use Composer\Downloader\FilesystemException;
|
use Composer\Downloader\FilesystemException;
|
||||||
use Composer\Downloader\TransportException;
|
use Composer\Downloader\TransportException;
|
||||||
|
use Phar;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Composer\Console\Input\InputOption;
|
use Composer\Console\Input\InputOption;
|
||||||
use Composer\Console\Input\InputArgument;
|
use Composer\Console\Input\InputArgument;
|
||||||
|
@ -116,9 +117,9 @@ EOT
|
||||||
$cacheDir = $config->get('cache-dir');
|
$cacheDir = $config->get('cache-dir');
|
||||||
$rollbackDir = $config->get('data-dir');
|
$rollbackDir = $config->get('data-dir');
|
||||||
$home = $config->get('home');
|
$home = $config->get('home');
|
||||||
$localFilename = realpath($_SERVER['argv'][0]);
|
$localFilename = Phar::running(false);
|
||||||
if (false === $localFilename) {
|
if ('' === $localFilename) {
|
||||||
$localFilename = $_SERVER['argv'][0];
|
throw new \RuntimeException('Could not determine the location of the composer.phar file as it appears you are not running this code from a phar archive.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($input->getOption('update-keys')) {
|
if ($input->getOption('update-keys')) {
|
||||||
|
|
|
@ -96,6 +96,7 @@ class AllFunctionalTest extends TestCase
|
||||||
|
|
||||||
self::assertFileExists(self::$pharPath);
|
self::assertFileExists(self::$pharPath);
|
||||||
copy(self::$pharPath, __DIR__.'/../../composer-test.phar');
|
copy(self::$pharPath, __DIR__.'/../../composer-test.phar');
|
||||||
|
chmod(__DIR__.'/../../composer-test.phar', 0777);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -14,6 +14,7 @@ namespace Composer\Test\Command;
|
||||||
|
|
||||||
use Composer\Composer;
|
use Composer\Composer;
|
||||||
use Composer\Test\TestCase;
|
use Composer\Test\TestCase;
|
||||||
|
use Symfony\Component\Process\Process;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @group slow
|
* @group slow
|
||||||
|
@ -24,23 +25,15 @@ class SelfUpdateCommandTest extends TestCase
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
private $prevArgv;
|
private $phar;
|
||||||
|
|
||||||
public function setUp(): void
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
$this->prevArgv = $_SERVER['argv'][0];
|
|
||||||
$dir = $this->initTempComposer();
|
$dir = $this->initTempComposer();
|
||||||
copy(__DIR__.'/../../../composer-test.phar', $dir.'/composer.phar');
|
copy(__DIR__.'/../../../composer-test.phar', $dir.'/composer.phar');
|
||||||
$_SERVER['argv'][0] = $dir.'/composer.phar';
|
$this->phar = $dir.'/composer.phar';
|
||||||
}
|
|
||||||
|
|
||||||
public function tearDown(): void
|
|
||||||
{
|
|
||||||
parent::tearDown();
|
|
||||||
|
|
||||||
$_SERVER['argv'][0] = $this->prevArgv;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSuccessfulUpdate(): void
|
public function testSuccessfulUpdate(): void
|
||||||
|
@ -49,20 +42,20 @@ class SelfUpdateCommandTest extends TestCase
|
||||||
$this->markTestSkipped('On releases this test can fail to upgrade as we are already on latest version');
|
$this->markTestSkipped('On releases this test can fail to upgrade as we are already on latest version');
|
||||||
}
|
}
|
||||||
|
|
||||||
$appTester = $this->getApplicationTester();
|
$appTester = new Process([PHP_BINARY, $this->phar, 'self-update']);
|
||||||
$appTester->run(['command' => 'self-update']);
|
$status = $appTester->run();
|
||||||
|
self::assertSame(0, $status, $appTester->getErrorOutput());
|
||||||
|
|
||||||
$appTester->assertCommandIsSuccessful();
|
self::assertStringContainsString('Upgrading to version', $appTester->getOutput());
|
||||||
self::assertStringContainsString('Upgrading to version', $appTester->getDisplay());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUpdateToSpecificVersion(): void
|
public function testUpdateToSpecificVersion(): void
|
||||||
{
|
{
|
||||||
$appTester = $this->getApplicationTester();
|
$appTester = new Process([PHP_BINARY, $this->phar, 'self-update', '2.4.0']);
|
||||||
$appTester->run(['command' => 'self-update', 'version' => '2.4.0']);
|
$status = $appTester->run();
|
||||||
|
self::assertSame(0, $status, $appTester->getErrorOutput());
|
||||||
|
|
||||||
$appTester->assertCommandIsSuccessful();
|
self::assertStringContainsString('Upgrading to version 2.4.0', $appTester->getOutput());
|
||||||
self::assertStringContainsString('Upgrading to version 2.4.0', $appTester->getDisplay());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUpdateWithInvalidOptionThrowsException(): void
|
public function testUpdateWithInvalidOptionThrowsException(): void
|
||||||
|
@ -83,12 +76,12 @@ class SelfUpdateCommandTest extends TestCase
|
||||||
$this->markTestSkipped('On releases this test can fail to upgrade as we are already on latest version');
|
$this->markTestSkipped('On releases this test can fail to upgrade as we are already on latest version');
|
||||||
}
|
}
|
||||||
|
|
||||||
$appTester = $this->getApplicationTester();
|
$appTester = new Process([PHP_BINARY, $this->phar, 'self-update', $option]);
|
||||||
$appTester->run(['command' => 'self-update', $option => true]);
|
$status = $appTester->run();
|
||||||
$appTester->assertCommandIsSuccessful();
|
self::assertSame(0, $status, $appTester->getErrorOutput());
|
||||||
|
|
||||||
self::assertStringContainsString('Upgrading to version', $appTester->getDisplay());
|
self::assertStringContainsString('Upgrading to version', $appTester->getOutput());
|
||||||
self::assertStringContainsString($expectedOutput, $appTester->getDisplay());
|
self::assertStringContainsString($expectedOutput, $appTester->getOutput());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue