Skip to content

Commit

Permalink
Merge pull request #10061 from Seldaek/deprecations
Browse files Browse the repository at this point in the history
Fix the remainder of PHP8.1 deprecation warnings
  • Loading branch information
Seldaek committed Aug 19, 2021
2 parents c5a02a2 + a586a75 commit e5a50d1
Show file tree
Hide file tree
Showing 30 changed files with 790 additions and 955 deletions.
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Expand Up @@ -15,7 +15,7 @@
bootstrap="tests/bootstrap.php"
>
<php>
<env name="SYMFONY_DEPRECATIONS_HELPER" value="weak"/>
<env name="SYMFONY_DEPRECATIONS_HELPER" value="max[direct]=0"/>
<env name="COMPOSER_TEST_SUITE" value="1"/>
</php>
<testsuites>
Expand Down
4 changes: 2 additions & 2 deletions src/Composer/IO/ConsoleIO.php
Expand Up @@ -36,9 +36,9 @@ class ConsoleIO extends BaseIO
/** @var HelperSet */
protected $helperSet;
/** @var string */
protected $lastMessage;
protected $lastMessage = '';
/** @var string */
protected $lastMessageErr;
protected $lastMessageErr = '';

/** @var float */
private $startTime;
Expand Down
2 changes: 1 addition & 1 deletion src/Composer/Json/JsonValidationException.php
Expand Up @@ -24,7 +24,7 @@ class JsonValidationException extends Exception
public function __construct($message, $errors = array(), Exception $previous = null)
{
$this->errors = $errors;
parent::__construct($message, 0, $previous);
parent::__construct((string) $message, 0, $previous);
}

public function getErrors()
Expand Down
2 changes: 1 addition & 1 deletion src/Composer/Package/Archiver/ArchiveManager.php
Expand Up @@ -88,7 +88,7 @@ public function getPackageFilename(CompletePackageInterface $package)
}
$nameParts = array($baseName);

if (preg_match('{^[a-f0-9]{40}$}', $package->getDistReference())) {
if (null !== $package->getDistReference() && preg_match('{^[a-f0-9]{40}$}', $package->getDistReference())) {
array_push($nameParts, $package->getDistReference(), $package->getDistType());
} else {
array_push($nameParts, $package->getPrettyVersion(), $package->getDistReference());
Expand Down
4 changes: 4 additions & 0 deletions src/Composer/Package/BasePackage.php
Expand Up @@ -217,6 +217,10 @@ public function getFullPrettyVersion($truncate = true, $displayMode = PackageInt
throw new \UnexpectedValueException('Display mode '.$displayMode.' is not supported');
}

if (null === $reference) {
return $this->getPrettyVersion();
}

// if source reference is a sha1 hash -- truncate
if ($truncate && \strlen($reference) === 40 && $this->getSourceType() !== 'svn') {
return $this->getPrettyVersion() . ' ' . substr($reference, 0, 7);
Expand Down
3 changes: 3 additions & 0 deletions src/Composer/Package/Package.php
Expand Up @@ -27,11 +27,14 @@ class Package extends BasePackage
protected $installationSource;
protected $sourceType;
protected $sourceUrl;
/** @var ?string */
protected $sourceReference;
protected $sourceMirrors;
protected $distType;
protected $distUrl;
/** @var ?string */
protected $distReference;
/** @var ?string */
protected $distSha1Checksum;
protected $distMirrors;
protected $version;
Expand Down
6 changes: 3 additions & 3 deletions src/Composer/Package/PackageInterface.php
Expand Up @@ -131,7 +131,7 @@ public function getSourceUrls();
/**
* Returns the repository reference of this package, e.g. master, 1.0.0 or a commit hash for git
*
* @return string The repository reference
* @return ?string The repository reference
*/
public function getSourceReference();

Expand Down Expand Up @@ -172,14 +172,14 @@ public function getDistUrls();
/**
* Returns the reference of the distribution archive of this version, e.g. master, 1.0.0 or a commit hash for git
*
* @return string
* @return ?string
*/
public function getDistReference();

/**
* Returns the sha1 checksum for the distribution archive of this version
*
* @return string
* @return ?string
*/
public function getDistSha1Checksum();

Expand Down
4 changes: 2 additions & 2 deletions src/Composer/Util/Bitbucket.php
Expand Up @@ -151,7 +151,7 @@ public function authorizeOAuthInteractively($originUrl, $message = null)
$this->io->writeError(sprintf('to create a consumer. It will be stored in "%s" for future use by Composer.', $this->config->getAuthConfigSource()->getName()));
$this->io->writeError('Ensure you enter a "Callback URL" (http://example.com is fine) or it will not be possible to create an Access Token (this callback url will not be used by composer)');

$consumerKey = trim($this->io->askAndHideAnswer('Consumer Key (hidden): '));
$consumerKey = trim((string) $this->io->askAndHideAnswer('Consumer Key (hidden): '));

if (!$consumerKey) {
$this->io->writeError('<warning>No consumer key given, aborting.</warning>');
Expand All @@ -160,7 +160,7 @@ public function authorizeOAuthInteractively($originUrl, $message = null)
return false;
}

$consumerSecret = trim($this->io->askAndHideAnswer('Consumer Secret (hidden): '));
$consumerSecret = trim((string) $this->io->askAndHideAnswer('Consumer Secret (hidden): '));

if (!$consumerSecret) {
$this->io->writeError('<warning>No consumer secret given, aborting.</warning>');
Expand Down
8 changes: 4 additions & 4 deletions src/Composer/Util/Perforce.php
Expand Up @@ -160,7 +160,7 @@ public function setStream($stream)

public function isStream()
{
return (strcmp($this->p4DepotType, 'stream') === 0);
return is_string($this->p4DepotType) && (strcmp($this->p4DepotType, 'stream') === 0);
}

public function getStream()
Expand Down Expand Up @@ -204,11 +204,11 @@ public function setUser($user)
public function queryP4User()
{
$this->getUser();
if (strlen($this->p4User) > 0) {
if (strlen((string) $this->p4User) > 0) {
return;
}
$this->p4User = $this->getP4variable('P4USER');
if (strlen($this->p4User) > 0) {
if (strlen((string) $this->p4User) > 0) {
return;
}
$this->p4User = $this->io->ask('Enter P4 User:');
Expand Down Expand Up @@ -262,7 +262,7 @@ public function queryP4Password()
return $this->p4Password;
}
$password = $this->getP4variable('P4PASSWD');
if (strlen($password) <= 0) {
if (strlen((string) $password) <= 0) {
$password = $this->io->askAndHideAnswer('Enter password for Perforce user ' . $this->getUser() . ': ');
}
$this->p4Password = $password;
Expand Down
7 changes: 5 additions & 2 deletions src/Composer/Util/ProcessExecutor.php
Expand Up @@ -356,9 +356,9 @@ public function markJobDone()
*/
public function splitLines($output)
{
$output = trim($output);
$output = trim((string) $output);

return ((string) $output === '') ? array() : preg_split('{\r?\n}', $output);
return $output === '' ? array() : preg_split('{\r?\n}', $output);
}

/**
Expand All @@ -371,6 +371,9 @@ public function getErrorOutput()
return $this->errorOutput;
}

/**
* @private
*/
public function outputHandler($type, $buffer)
{
if ($this->captureOutput) {
Expand Down
5 changes: 3 additions & 2 deletions tests/Composer/Test/Downloader/FileDownloaderTest.php
Expand Up @@ -18,6 +18,7 @@
use Composer\Plugin\PluginEvents;
use Composer\Plugin\PreFileDownloadEvent;
use Composer\Test\TestCase;
use Composer\Test\Mock\ProcessExecutorMock;
use Composer\Util\Filesystem;
use Composer\Util\Http\Response;
use Composer\Util\Loop;
Expand Down Expand Up @@ -194,7 +195,7 @@ public function testDownloadWithCustomProcessedUrl()
$dispatcher = new EventDispatcher(
$composerMock,
$this->getMockBuilder('Composer\IO\IOInterface')->getMock(),
$this->getMockBuilder('Composer\Util\ProcessExecutor')->getMock()
new ProcessExecutorMock
);
$dispatcher->addListener(PluginEvents::PRE_FILE_DOWNLOAD, function (PreFileDownloadEvent $event) use ($expectedUrl) {
$event->setProcessedUrl($expectedUrl);
Expand Down Expand Up @@ -288,7 +289,7 @@ public function testDownloadWithCustomCacheKey()
$dispatcher = new EventDispatcher(
$composerMock,
$this->getMockBuilder('Composer\IO\IOInterface')->getMock(),
$this->getMockBuilder('Composer\Util\ProcessExecutor')->getMock()
new ProcessExecutorMock
);
$dispatcher->addListener(PluginEvents::PRE_FILE_DOWNLOAD, function (PreFileDownloadEvent $event) use ($customCacheKey) {
$event->setCustomCacheKey($customCacheKey);
Expand Down
83 changes: 39 additions & 44 deletions tests/Composer/Test/Downloader/FossilDownloaderTest.php
Expand Up @@ -16,6 +16,7 @@
use Composer\Test\TestCase;
use Composer\Util\Filesystem;
use Composer\Util\Platform;
use Composer\Test\Mock\ProcessExecutorMock;

class FossilDownloaderTest extends TestCase
{
Expand All @@ -39,7 +40,7 @@ protected function getDownloaderMock($io = null, $config = null, $executor = nul
{
$io = $io ?: $this->getMockBuilder('Composer\IO\IOInterface')->getMock();
$config = $config ?: $this->getMockBuilder('Composer\Config')->getMock();
$executor = $executor ?: $this->getMockBuilder('Composer\Util\ProcessExecutor')->getMock();
$executor = $executor ?: new ProcessExecutorMock;
$filesystem = $filesystem ?: $this->getMockBuilder('Composer\Util\Filesystem')->getMock();

return new FossilDownloader($io, $config, $executor, $filesystem);
Expand Down Expand Up @@ -67,28 +68,18 @@ public function testInstall()
$packageMock->expects($this->once())
->method('getSourceUrls')
->will($this->returnValue(array('http://fossil.kd2.org/kd2fw/')));
$processExecutor = $this->getMockBuilder('Composer\Util\ProcessExecutor')->getMock();

$expectedFossilCommand = $this->getCmd('fossil clone -- \'http://fossil.kd2.org/kd2fw/\' \'repo.fossil\'');
$processExecutor->expects($this->at(0))
->method('execute')
->with($this->equalTo($expectedFossilCommand))
->will($this->returnValue(0));

$expectedFossilCommand = $this->getCmd('fossil open --nested -- \'repo.fossil\'');
$processExecutor->expects($this->at(1))
->method('execute')
->with($this->equalTo($expectedFossilCommand))
->will($this->returnValue(0));

$expectedFossilCommand = $this->getCmd('fossil update -- \'trunk\'');
$processExecutor->expects($this->at(2))
->method('execute')
->with($this->equalTo($expectedFossilCommand))
->will($this->returnValue(0));

$downloader = $this->getDownloaderMock(null, null, $processExecutor);

$process = new ProcessExecutorMock;
$process->expects(array(
$this->getCmd('fossil clone -- \'http://fossil.kd2.org/kd2fw/\' \'repo.fossil\''),
$this->getCmd('fossil open --nested -- \'repo.fossil\''),
$this->getCmd('fossil update -- \'trunk\''),
), true);

$downloader = $this->getDownloaderMock(null, null, $process);
$downloader->install($packageMock, 'repo');

$process->assertComplete($this);
}

public function testUpdateforPackageWithoutSourceReference()
Expand Down Expand Up @@ -126,42 +117,46 @@ public function testUpdate()
$packageMock->expects($this->any())
->method('getVersion')
->will($this->returnValue('1.0.0.0'));
$processExecutor = $this->getMockBuilder('Composer\Util\ProcessExecutor')->getMock();

$expectedFossilCommand = $this->getCmd("fossil changes");
$processExecutor->expects($this->at(0))
->method('execute')
->with($this->equalTo($expectedFossilCommand))
->will($this->returnValue(0));
$expectedFossilCommand = $this->getCmd("fossil pull && fossil up 'trunk'");
$processExecutor->expects($this->at(1))
->method('execute')
->with($this->equalTo($expectedFossilCommand))
->will($this->returnValue(0));

$downloader = $this->getDownloaderMock(null, null, $processExecutor);

$process = new ProcessExecutorMock;
$process->expects(array(
$this->getCmd("fossil changes"),
$this->getCmd("fossil pull && fossil up 'trunk'"),
), true);

$downloader = $this->getDownloaderMock(null, null, $process);
$downloader->prepare('update', $packageMock, $this->workingDir, $packageMock);
$downloader->update($packageMock, $packageMock, $this->workingDir);
$downloader->cleanup('update', $packageMock, $this->workingDir, $packageMock);

$process->assertComplete($this);
}

public function testRemove()
{
$expectedResetCommand = $this->getCmd('cd \'composerPath\' && fossil status');
// Ensure file exists
$file = $this->workingDir . '/.fslckout';
touch($file);

$packageMock = $this->getMockBuilder('Composer\Package\PackageInterface')->getMock();
$processExecutor = $this->getMockBuilder('Composer\Util\ProcessExecutor')->getMock();
$processExecutor->expects($this->any())
->method('execute')
->with($this->equalTo($expectedResetCommand));

$process = new ProcessExecutorMock;
$process->expects(array(
$this->getCmd('fossil changes'),
), true);

$filesystem = $this->getMockBuilder('Composer\Util\Filesystem')->getMock();
$filesystem->expects($this->once())
->method('removeDirectoryAsync')
->with($this->equalTo('composerPath'))
->with($this->equalTo($this->workingDir))
->will($this->returnValue(\React\Promise\resolve(true)));

$downloader = $this->getDownloaderMock(null, null, $processExecutor, $filesystem);
$downloader->remove($packageMock, 'composerPath');
$downloader = $this->getDownloaderMock(null, null, $process, $filesystem);
$downloader->prepare('uninstall', $packageMock, $this->workingDir);
$downloader->remove($packageMock, $this->workingDir);
$downloader->cleanup('uninstall', $packageMock, $this->workingDir);

$process->assertComplete($this);
}

public function testGetInstallationSource()
Expand Down

0 comments on commit e5a50d1

Please sign in to comment.