Skip to content
This repository has been archived by the owner on Mar 15, 2020. It is now read-only.

Commit

Permalink
Add a random string to skip packagist json cache (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
luckyraul authored and theofidry committed Mar 30, 2018
1 parent fb9d3b1 commit d01d3b8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
7 changes: 3 additions & 4 deletions src/Strategy/GithubStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@

class GithubStrategy implements StrategyInterface
{

const API_URL = 'https://packagist.org/packages/%s.json';
const API_URL = 'https://packagist.org/p/%s.json';

const STABLE = 'stable';

Expand Down Expand Up @@ -101,7 +100,7 @@ public function getCurrentRemoteVersion(Updater $updater)
);
}

$versions = array_keys($package['package']['versions']);
$versions = array_keys($package['packages'][$this->getPackageName()]);
$versionParser = new VersionParser($versions);
if ($this->getStability() === self::STABLE) {
$this->remoteVersion = $versionParser->getMostRecentStable();
Expand Down Expand Up @@ -217,7 +216,7 @@ protected function getDownloadUrl(array $package)
$baseUrl = preg_replace(
'{\.git$}',
'',
$package['package']['versions'][$this->remoteVersion]['source']['url']
$package['packages'][$this->getPackageName()][$this->remoteVersion]['source']['url']
);
$downloadUrl = sprintf(
'%s/releases/download/%s/%s',
Expand Down
12 changes: 6 additions & 6 deletions tests/Humbug/Test/SelfUpdate/UpdaterGithubStrategyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function testUpdatePhar()
$updater = new Updater($this->tmp . '/old.phar');
$updater->setStrategyObject(new GithubTestStrategy);
$updater->getStrategy()->setPharName('new.phar');
$updater->getStrategy()->setPackageName(''); // not used in this test
$updater->getStrategy()->setPackageName('humbug/test-phar');
$updater->getStrategy()->setCurrentLocalVersion('1.0.0');

$this->assertTrue($updater->update());
Expand All @@ -132,7 +132,7 @@ private function deleteTempPhars()
@unlink($this->tmp . '/releases/download/1.0.1/new.phar');
@unlink($this->tmp . '/releases/download/1.0.1/new.phar.pubkey');
@unlink($this->tmp . '/old.1c7049180abee67826d35ce308c38272242b64b8.phar');
@unlink($this->tmp . '/package.json');
@unlink($this->tmp . '/packages.json');
}

private function createTestPharAndKey()
Expand All @@ -145,9 +145,9 @@ private function createTestPharAndKey()
);
@mkdir($this->tmp.'/releases/download/1.0.1', 0755, true);
copy($this->files.'/build/new.phar', $this->tmp.'/releases/download/1.0.1/new.phar');
file_put_contents($this->tmp . '/package.json', json_encode(array(
'package' => array(
'versions' => array(
file_put_contents($this->tmp . '/packages.json', json_encode(array(
'packages' => array(
'humbug/test-phar' => array(
'1.0.1' => array(
'source' => array(
'url' => 'file://' . $this->tmp . '.git'
Expand All @@ -165,6 +165,6 @@ class GithubTestStrategy extends GithubStrategy
{
protected function getApiUrl()
{
return 'file://' . sys_get_temp_dir() . '/package.json';
return 'file://' . sys_get_temp_dir() . '/packages.json';
}
}

0 comments on commit d01d3b8

Please sign in to comment.